CE203303 - PSoC® 3 and PSoC 5LP Breathing LED Objective ® This example demonstrates the flexibility of a PSoC 3 or PSoC 5LP, by implementing a breathing LED effect exclusively in hardware, with no CPU usage beyond initialization. Overview This example uses two PWMs and an XOR gate to make an LED gradually cycle through increasing and decreasing brightness. There is no CPU usage beyond PWM initialization. Requirements Tool: PSoC Creator 3.2 or higher Programming Language: C (GCC 4.8.4) Associated Parts: All PSoC 3 and PSoC 5LP parts Related Hardware: CY8CKIT-059, CY8CKIT-030, CY8CKIT-050, CY8CKIT-001 Design The hardware design features two PWM Components, as Figure 1 shows. They have slightly different periods, with 50% duty cycles. Routing them through an exclusive-OR (XOR) gate yields an output signal with a gradually changing duty cycle. Driving an LED with this signal results in a “breathing” effect, where the LED gradually gets brighter and dimmer. The rate of change is proportional to the difference between the PWM output frequencies. Figure 1. Breathing LED Schematic (Pin and LED are selected for CY8CKIT-059) www.cypress.com Document No. 002-03303 Rev. ** 1 PSoC® 3 and PSoC 5LP Breathing LED Design Considerations This design can be extended in a number of ways: Change the PWMs from 8-bit to 16-bit to get more precise control of the breathing rate. Add an analog-to-digital converter (ADC), with a kit potentiometer as an analog input. Then use CPU firmware to change the period of one of the PWMs based on the potentiometer position. This allows potentiometer-based control of the breathing rate. Use fixed-block PWMs (FF-TCPWM) instead of UDB-based PWMs to save UDB resources for other functions. Connect a kit button through an input pin to the PWMs’ enable terminals. This allows hardware control of whether or not the LED breathes, with no CPU usage. This code example is designed for the PSoC 5LP device family and associated CY8CKIT-059 kit. The design is easily portable to other PSoC 3, PSoC 4 and PSoC 5LP devices and kits, typically by just changing the LED, button, or potentiometer pin assignments. PSoC Creator Components Table 1 lists the PSoC Creator Components used in this example, as well as the hardware resources used by each. Table 1. List of PSoC Creator Components Component Hardware Resources PWM_1 1 TCPWM, or ~1 UDB PWM_2 1 TCPWM, or ~1 UDB XOR gate 1 UDB macrocell Clock_1 1 clock divider Pin_LED 1 pin Parameter Settings Figure 2 shows the changed settings for the PWM Components. Figure 2. PWMs Configuration Operation Plug the CY8CKIT-059 board into your computer’s USB port. Program the project into the kit, and observe the breathing effect on the kit’s blue LED. www.cypress.com Document No. 002-03303 Rev. ** 2 PSoC® 3 and PSoC 5LP Breathing LED Related Documents Table 2 lists all relevant application notes, code examples, knowledge base articles, device datasheets, and PSoC Creator Component datasheets. Table 2. Related Documents Application Notes AN54181, AN77759 Getting Started with PSoC 3 Getting Started with PSoC 5LP Describes the PSoC 3 and PSoC 5LP, and how to build this code example. PSoC Creator Component Datasheets PWM Supports fixed block and UDB-based PWMs Digital Logic Gates Supports creation of UDB-based logic gates to perform Boolean operations Pins Supports connection of hardware resources to physical pins Device Documentation PSoC 3 Datasheets PSoC 3 Technical Reference Manuals PSoC 5LP Datasheets PSoC 5LP Technical Reference Manuals Development Kit (DVK) Documentation PSoC 3 and PSoC 5LP Kits PSoC Resources If you are new to PSoC, Cypress provides a wealth of data at www.cypress.com to help you to select the right PSoC device for your design, and quickly and effectively integrate the device into your design. For a comprehensive list of resources, see knowledge base article KBA86521, How to Design with PSoC 3, PSoC 4, and PSoC 5LP. The following is an abbreviated list for PSoC 3 and PSoC 5LP: Overview: PSoC Portfolio, PSoC Roadmap Product Selectors: PSoC 1, PSoC 3, PSoC 4, or PSoC 5LP. In addition, PSoC Creator includes a device selection tool. Datasheets: Describe and provide electrical specifications for the PSoC 3 and PSoC 5LP device families Technical Reference Manuals (TRM): Provide detailed descriptions of the architecture and registers in the PSoC 3 and PSoC 5LP device families. Application Notes and Code Examples: Cover a broad range of topics, from basic to advanced level. Many of the application notes include code examples. PSoC Creator provides additional code examples. Recommended application notes for getting started with PSoC 3 and PSoC 5LP are: AN54181, Getting Started with PSoC 3 AN77759, Getting Started with PSoC 5LP AN61290, Hardware Design Considerations AN57821, Mixed Signal Circuit Board Layout AN81623, Digital Design Best Practices AN73854, Introduction To Bootloaders www.cypress.com PSoC Training Videos: These videos provide step-bystep instructions on how to get started building complex designs with PSoC. Development Kits: • CY8CKIT-059 is a low-cost platform for prototyping products with PSoC 5LP. It has a unique snap-away programmer and debugger on the USB connector: • CY8CKIT-030 and CY8CKIT-050 are designed for analog performance. They enable you to evaluate, develop and prototype high precision analog, lowpower and low-voltage applications powered by PSoC 3 or PSoC 5LP. • CY8CKIT-001 provides a common development platform for any one of the PSoC 1, PSoC 3, PSoC 4, or PSoC 5LP families of devices. The MiniProg3 device provides an interface for flash programming and debug. Document No. 002-03303 Rev. ** 3 PSoC® 3 and PSoC 5LP Breathing LED PSoC Creator PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 3 – with PSoC Creator, you can: 1. 2. Drag and drop Components to build your hardware system design in the main design workspace 3. Configure Components using configuration tools 4. Explore the library of 100+ Components Codesign your application firmware with the PSoC hardware 5. Review Component datasheets Figure 3. PSoC Creator Features www.cypress.com Document No. 002-03303 Rev. ** 4 PSoC® 3 and PSoC 5LP Breathing LED Document History ® Document Title: PSoC 3 and PSoC 5LP Breathing LED - CE203303 Document Number: 002-03303 Revision ECN ** 4940060 www.cypress.com Orig. of Change MKEA Submission Date 10/08/2015 Description of Change New code example Document No. 002-03303 Rev. ** 5 PSoC® 3 and PSoC 5LP Breathing LED Worldwide Sales and Design Support Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find the office closest to you, visit us at Cypress Locations. PSoC® Solutions Products Automotive cypress.com/go/automotive psoc.cypress.com/solutions Clocks & Buffers cypress.com/go/clocks PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP Interface cypress.com/go/interface Lighting & Power Control cypress.com/go/powerpsoc Memory cypress.com/go/memory PSoC cypress.com/go/psoc Touch Sensing cypress.com/go/touch USB Controllers cypress.com/go/usb Wireless/RF cypress.com/go/wireless Cypress Developer Community Community | Forums | Blogs | Video | Training Technical Support cypress.com/go/support PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone Fax Website : 408-943-2600 : 408-943-4730 : www.cypress.com © Cypress Semiconductor Corporation, 2015. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement. www.cypress.com Document No. 002-03303 Rev. ** 6