CE210197 Adjustable Reference Comparator.pdf

CE210197 – Adjustable Reference Comparator
Objective
This code example demonstrates the adjustable voltage reference capability of the CapSense® Sigma Delta (CSD)
Comparator. This Component provides the flexibility to compare the input voltage with different levels of reference voltages. It
can be used as a fan speed controller, battery monitor, and so on.
Overview
This code example demonstrates how to set the Component options for adjustable voltage reference and how to set different
reference voltages in the firmware.
The code example uses a pushbutton to set the reference voltages in the firmware. Once the reference voltage is set, the
comparator compares the input voltage with the reference voltage. If the input voltage is greater than the reference voltage,
the code sets the RGB LED to green. Otherwise, the code sets the RGB LED to red. An external voltage supply of 1.8 V is
required to connect with the input voltage.
Requirements
Tool: PSoC Creator™ 3.3 SP2 or higher
Programming Language: C (ARM GCC 4.9)
Associated Parts: PSoC® 4000S, PSoC 4100S, and PSoC Analog Coprocessor
Related Hardware: CY8CKIT-041-40xx, CY8CKIT-041-41xx, and CY8CKIT-048
Design
The example project consists of analog input pins, a digital input pin, output pins, and Comp/Vref Components. Figure 1 shows
the Component schematics for this project. The Comparator compares the input voltage applied to the noninverting terminal
(Vplus) with a variable reference voltage, which is generated by the reference generator. The reference generator is part of the
Comparator Component, which gets a constant reference voltage as an input.
The example uses a GPIO pin to apply the constant reference voltage to the inverting terminal (Vminus) of the Comp/Vref
Component. The firmware uses the redLed and greenLed pins to control the respective LEDs. The red and green LEDs are
part of the RGB LED on the kits.
This code example uses a pushbutton to change the reference voltage in the firmware at run time. It uses the LEDs to show
the output of the Comparator. The Comparator can take the reference voltage input from 0.6 V to analog supply voltage
(VDDA) – 0.6 V.
www.cypress.com
Document No. 002-10197 Rev. **
1
Adjustable Reference Comparator
Figure 1. Component Schematics
At the beginning of the program, the code initializes the Comparator Component, and the LEDs are set to the default state.
The code defines four reference voltage tap values as macros to demonstrate the adjustable reference capabilities of the
Comparator Component. The values are calculated using the following formula:
Tap value = Required reference voltage in mV / Comp_VREF_STEP_MVOLTS
Each time the pushbutton is pressed, upon the rising edge, the code changes the reference voltage to the next reference
voltage value. Then the Comparator compares the input voltage with the reference voltage generated by the reference block.
A software counter counts the number of rising edges of the button presses to indicate the reference voltage to be set. The
counter is reset after four presses.
When the input voltage is greater than the reference voltage, the green LED is turned on. Otherwise the red LED is turned on.
Change the reference voltage tap values by simply pushing the button. Figure 2 shows the firmware flow chart of this project.
www.cypress.com
Document No. 002-10197 Rev. **
2
Adjustable Reference Comparator
Figure 2. Firmware Flow Chart
Start
Initialize the Comparator
component
NO
YES
Is rising edge of push
button detected?
YES
Is buttonCount=1?
NO
YES
Set the Reference
Voltage tap value to
VREFTAP1
Is buttonCount=2?
NO
YES
Set the Reference
Voltage tap value to
VREFTAP2
Is buttonCount==3?
NO
Set the Reference
Voltage tap value to
VREFTAP4
Set the Reference
Voltage tap value to
VREFTAP3
buttonCount=0
Increment the
buttonCount
NO
YES
Input voltage is greater than
Reference voltage?
Turn on Red LED
Turn on Green LED
Design Considerations
The code example is designed for the PSoC 4000S family and the associated CY8CKIT-041-40xx kit. The design is easily
portable to other PSoC devices and kits, typically by just changing the device and pin assignments.
To switch from the CY8CKIT-041-40xx to other PSoC pioneer kits, follow these steps:
1.
Select the appropriate device with a device selector called from the project’s context menu (Figure 3). Table 1 lists the
device number for each pioneer kit.
2.
When you select the device, PSoC Creator assigns pins automatically in the Design-Wide Resource file according to the
device selected.
Note: If the assigned Components pins are not as shown in Table 1 or you want to overwrite the existing pin assignment,
double-click the project’s Design-Wide Resource file in the Workspace Explorer window and assign the pins. Refer to the
device datasheet for information on pin assignments.
www.cypress.com
Document No. 002-10197 Rev. **
3
Adjustable Reference Comparator
Figure 3. Select Device Selector from Project’s Context Menu
3.
Build the project and ensure that there are no errors or warnings.
Table 1. Pin Assignments for the Adjustable Reference Comparator Project
Development Kits
Pin Name
www.cypress.com
CY8CKIT-041-41XX
CY8CKIT-048
( CY8C4045AZI-423)
(CY8C4146AZI-S433)
(CY8C4A5LQI-483)
Vplus
P2[2]
P2[2]
P2[2]
Vminus
P4[0]
P4[0]
P5[1]
CmpOut
P2[0]
P2[0]
P3[5]
redLed
P3[4]
P3[4]
P1[4]
greenLed
P2[6]
P2[6]
P2[6]
pushButton
P0[7]
P0[7]
P0[3]
CY8CKIT-041-40XX
Document No. 002-10197 Rev. **
4
Adjustable Reference Comparator
PSoC Creator Components
Table 2 lists the PSoC Creator Components used in this example, as well as the hardware resources used by each.
Table 2. PSoC Creator Components
Component
Hardware Resources
Comp
AMUXBUS-A, AMUXBUS-B, CSD Comparator, 3 pins
pushButton
1 pin
redLed
1 pin
greenLed
1 pin
Parameter Settings
CapSense Component
Figure 4 shows the settings for the CSD_Comp_P4 Component.
Figure 4. CSD_Comp_P4 Configuration
Operation
After you build and install the example in the CY8CKIT-041-40xx kit, test the example by doing the following:
1.
Connect a 1.8-V external voltage supply to the Vplus pin.
2.
Connect the Vminus pin to VDD (4 V) or an external supply of 4 V.
3.
Push the button to set the different reference voltage tap values.
4.
Observe the RGB LED change colors depending on the input voltage value with respect to the reference voltage.
www.cypress.com
Document No. 002-10197 Rev. **
5
Adjustable Reference Comparator
Related Documents
Table 3 lists the relevant application notes, code examples, PSoC Creator Component datasheets, device documentation, and
development kit (DVK) documentation.
Table 3. Related Documents
Application Notes
AN79953
Getting Started with PSoC 4
Describes PSoC 4 and how to build your first PSoC Creator project
Code Examples
CE210197
Adjustable Reference Comparator
PSoC Creator Component Datasheets
CSD_Comp_P4
Supports CSD-based adjustable voltage reference comparator
Pins
Supports the connection of hardware resources to physical pins
Device Documentation
PSoC 4 Datasheets
PSoC 4 Technical Reference Manuals
DVK Documentation
CY8CKIT-041-40xx PSoC 4 S-Series Pioneer Kit
CY8CKIT-041-41xx PSoC 4 S-Series Pioneer Kit
CY8CKIT-048 PSoC Analog Coprocessor Pioneer Kit
PSoC Resources
Cypress provides a wealth of data at www.cypress.com to help you select the right PSoC device and quickly and effectively
integrate the device into your design. For a comprehensive list of resources, see KBA86521, How to Design with PSoC 3,
PSoC 4, and PSoC 5LP. The following is an abbreviated list for PSoC 4:


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.
Technical Reference Manuals (TRM): Provide
detailed descriptions of the architecture and registers
in each PSoC 4 device family.

Development Kits:

Datasheets: Describe and provide electrical
specifications for the PSoC 4000, PSoC 4000S,
PSoC 4100S,
PSoC 4100
and
PSoC 4200,
PSoC 4xx7 BLE, PSoC 4200-M, and PSoC Analog
Coprocessor device families

CapSense Design Guide: Learn how to design
capacitive touch-sensing applications with the PSoC 4
family of devices.

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.
www.cypress.com

CY8CKIT-040, CY8CKIT-041-40xx, CY8CKIT041-41xx, CY8CKIT-042, CY8CKIT-042-BLE,
CY8CKIT-044, and CY8CKIT-048 PSoC Pioneer
Kits are easy-to-use and inexpensive development
platforms. These kits include connectors for
Arduino™ compatible shields and Digilent®
Pmod™ daughter cards.

CY8CKIT-049 is a very low-cost prototyping
platform for sampling PSoC 4 devices.

CY8CKIT-001 is a common development platform
for all PSoC family devices.

CY8CKIT-002 – The MiniProg3 device provides an
interface for flash programming and debugging.
Document No. 002-10197 Rev. **
6
Adjustable Reference Comparator
PSoC Creator
PSoC Creator is a free, Windows-based Integrated Design Environment (IDE) that enables the concurrent hardware and
firmware design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 5. With PSoC Creator, you can:
1.
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
2.
Codesign your application firmware with the PSoC
hardware
5.
Review Component datasheets
Figure 5. PSoC Creator Features
www.cypress.com
Document No. 002-10197 Rev. **
7
Adjustable Reference Comparator
Document History
Document Title: CE210197 - Adjustable Reference Comparator
Document Number: 002-10197
Revision
ECN
**
5142921
www.cypress.com
Orig. of
Change
AKSM
Submission
Date
02/19/2016
Description of Change
New code example.
Document No. 002-10197 Rev. **
8
Adjustable Reference Comparator
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
CapSense and PSoC are registered trademarks 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, 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 under its copyright rights in the Software, a personal, non-exclusive,
nontransferable license (without the right to sublicense) (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. Cypress also grants you a
personal, non-exclusive, nontransferable, license (without the right to sublicense) 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 to the minimum extent that is necessary for you
to exercise your rights under the copyright license granted in the previous sentence. Any other use, reproduction, modification, translation, or
compilation of the Software is prohibited.
CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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, lifesupport 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 Company shall and hereby does release Cypress
from any claim, damage, or other liability arising from or related to all Unintended Uses of Cypress products. Company 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-10197 Rev. **
9