CE203972 - PSoC® CY8C4Axx Comparator with Programmable Voltage Reference Objective This code example uses a programmable voltage reference and a single comparator to determine if an input voltage is between two specified voltages. Overview This code example checks for a high and low limit then turns on one of three kit LEDs to indicate if the voltage is too high, too low, or within the high and low limits. Requirements Tool: PSoC Creator 3.3 SP2 or higher Programming Language: C (GCC 4.9.0) or higher Associated Parts: PSoC Analog Coprocessor Related Hardware: CY8CKIT-048 Design This design uses a single comparator ( Comp_1 ) in conjunction with a programmable voltage reference ( PVref_1 ), to create a window comparator. A window comparator indicates when a voltage is between two set points. Normally two comparators would be required, but since the programmable voltage reference is adjustable, only one comparator is required. The firmware adjusts the voltage reference, checks the comparator output, and then turns on the correct LED to signal if the voltage is between the set points, above the high set point, or below the low set point. Figure 1 Project Schematic www.cypress.com Document No. 002-03972 Rev.** 1 PSoC® CY8C4Axx Comparator with Programmable Voltage Reference Design Considerations The reference source for the programmable voltage reference is either based on the 1.2 volt system voltage reference (by default), or the supply voltage Vdd. The programmable voltage reference (PVref_1) allows the user to select an output that is between the reference source and Vss in 16 equal steps. When the 1.2 volt reference source is used, the user may select a value between 75 mV (1.2V/16) to 1.2 volts in steps of 75 mV. Vdd can also be selected as the reference source and the output will be in increments of Vdd/16. For example, if Vdd = 3.3 volts, the output may be from 206 mV to 3.3 volts in 206 mV steps. Hardware Setup The resistors and LEDs shown in the schematic are mounted on the CY8CKIT-048 kit. The three Off-Chip LEDs are part of a single RGB (Red, Green, Blue) LED on the development board. A potentiometer connected between Vss and Vdd will need to be added by the user. Instead of a potentiometer, any voltage source between Vss and Vdd may be used. 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 or User Module Comp_1 Version Hardware Resources 1.20 ½ of a CTB/CTBm 1.0 ¼ of the programmable reference block Vin (Analog Pin) 2.20 GPIO ( P0[7] ) RedLED 2.20 GPIO ( P1[4] ) GreenLED 2.20 GPIO ( P0[2] ) BlueLED 2.20 GPIO ( P1[6] ) PVref_1 Parameter Settings Both the programmable voltage reference (PVrev_1) and the comparator (Comp_1) components use their default configuration for this code example. Operation To evaluate this code example perform the following steps: 1) Attach a potentiometer as shown on the schematic in Figure1 or apply an external voltage source to port P0[7]. Be careful that the external voltage source stays within the range of the PSoC’s supply of Vss to Vdd. 2) Slowly adjust the input voltage from 0 volts to above 1.5 volts. 3) Monitor the LED status with respect to the voltage input. a. Blue LED should be on when input voltage is below 0.5 volts. b. Green LED should be on when voltage is between 0.5 and 1.0 volts. c. Red LED should be on when voltage exceeds 1.0 volt. The levels at which the different LEDs are on may be adjusted in the source code found in main.c. The “HIGH_LIMIT” and “LOW_LIMIT” #define statements may be modified to adjust the high and low limits of the window comparator. www.cypress.com Document No. 002-03972 Rev.** 2 PSoC® CY8C4Axx Comparator with Programmable Voltage Reference Related Documents Table 2 lists all relevant application notes, code examples, knowledge base articles, device datasheets, and Component datasheets. Table 2. Related Documents Application Notes AN211293 Getting Started with PSoC® Analog Coprocessor PSoC Creator Component Datasheets Comp PSoC 4 Voltage Comparator (Comp) PVref PSoC 4 Programmable Voltage Reference Pins General Purpose IO Pins Device Documentation Cy8C4Axx Datasheet PSoC® Analog Coprocessor: CY8C4Axx Family Datasheet Development Kit (DVK) Documentation CY8CKIT-048 PSoC® Analog Coprocessor Pioneer Kit PSoC® Family Web Page PSoC® Analog Coprocessor www.cypress.com Document No. 002-03972 Rev.** 3 PSoC® CY8C4Axx Comparator with Programmable Voltage Reference Document History Document Title: CE203972 - PSoC® CY8C4Axx Comparator with Programmable Voltage Reference Document Number: 002-03972 Revision ECN ** 5101225 www.cypress.com Orig. of Change MEH Submission Date 1/22/2016 Description of Change New Code Example Document No. 002-03972 Rev.** 4 PSoC® CY8C4Axx Comparator with Programmable Voltage Reference 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 ARM® Cortex® Microcontrollers cypress.com/arm PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP Automotive cypress.com/automotive Cypress Developer Community Clocks & Buffers cypress.com/clocks Interface cypress.com/interface Lighting & Power Control cypress.com/powerpsoc Memory cypress.com/memory PSoC cypress.com/psoc Touch Sensing cypress.com/touch USB Controllers cypress.com/usb Wireless/RF cypress.com/wireless Forums | Projects | Videos | Blogs | Training | Components Technical Support cypress.com/support PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corporation. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 951341709 Phone Fax Website : 408-943-2600 : 408-943-4730 : www.cypress.com © Cypress Semiconductor Corporation, 2016. This document is the property of Cypress Semiconductor Corporation and its subsidiaries, including Spansion LLC (“Cypress”). This document, including any software or firmware included or referenced in this document (“Software”), is owned by Cypress under the intellectual property laws and treaties of the United States and other countries worldwide. Cypress reserves all rights under such laws and treaties and does not, except as specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other intellectual property rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with Cypress governing the use of the Software, then Cypress hereby grants you a personal, non-exclusive, nontransferable license (without the right to sublicense) (1) under its copyright rights in the Software (a) for Software provided in source code form, to modify and reproduce the Software solely for use with Cypress hardware products, only internally within your organization, and (b) to distribute the Software in binary code form externally to end users (either directly or indirectly through resellers and distributors), solely for use on Cypress hardware product units, and (2) under those claims of Cypress’s patents that are infringed by the Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software solely for use with Cypress hardware products. Any other use, reproduction, modification, translation, or compilation of the Software is prohibited. TO THE EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE OR ACCOMPANYING HARDWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. To the extent permitted by applicable law, Cypress reserves the right to make changes to this document without further notice. Cypress does not assume any liability arising out of the application or use of any product or circuit described in this document. Any information provided in this document, including any sample design information or programming code, is provided only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test the functionality and safety of any application made of this information and any resulting product. Cypress products are not designed, intended, or authorized for use as critical components in systems designed or intended for the operation of weapons, weapons systems, nuclear installations, life-support devices or systems, other medical devices or systems (including resuscitation equipment and surgical implants), pollution control or hazardous substances management, or other uses where the failure of the device or system could cause personal injury, death, or property damage (“Unintended Uses”). A critical component is any component of a device or system whose failure to perform can be reasonably expected to cause the failure of the device or system, or to affect its safety or effectiveness. Cypress is not liable, in whole or in part, and you shall and hereby do release Cypress from any claim, damage, or other liability arising from or related to all Unintended Uses of Cypress products. You shall indemnify and hold Cypress harmless from and against all claims, costs, damages, and other liabilities, including claims for personal injury or death, arising from or related to any Unintended Uses of Cypress products. Cypress, the Cypress logo, Spansion, the Spansion logo, and combinations thereof, PSoC, CapSense, EZ-USB, F-RAM, and Traveo are trademarks or registered trademarks of Cypress in the United States and other countries. For a more complete list of Cypress trademarks, visit cypress.com. Other names and brands may be claimed as property of their respective owners. www.cypress.com Document No. 002-03972 Rev.** 5