Академический Документы
Профессиональный Документы
Культура Документы
Features
ADC as a voltage ADC, with input range from 0 to 3.3 V
Perform a simple two-point calibration to improve ADC accuracy
PWM control using potentiometer
Sends measurement to a host (PC) using UART
General Description
This is a PSoC Creator example project. Analog to digital converters are important to all mixed
signal designs. With a couple of external resistors, the PSoC 4000 can be configured as an
ADC. This project demonstrates a voltage ADC, how to perform a two-point calibration, and how
the firmware can interpret the input to control a PWM and send data using UART.
Cypress Semiconductor Corporation 198 Champion Court San Jose, CA 95134-1709 408-943-2600
Page 2 of 10
Project Configuration
This example project primarily uses the CSD ADC, SW Tx UART, and PWM components. It also
uses Pins, a Clock, a 7bit IDAC, and an Analog Mux. Shown in Figure 2 is the Top Design
schematic of this project.
Figure 2. Top Design Schematic
Component Configuration
PSoC 4000 ADC Component
The ADC component has no parameters and requires no configuration.
Page 3 of 10
TCPWM Component
The purpose of the TCPWM is to output a pulse stream with a duty cycle that is dependent on
the input voltage. The TCPWM component is configured to be a PWM, as shown in Figure 3.
Selecting the PWM radio button enables the PWM tab seen in Figure 3.
Figure 3. TCPWM Configuration tab
The configuration for the PWM tab is shown in Figure 4. The duty cycle is determined by the
Period and Compare parameters. Its initial duty cycle is 100%, but is adjusted by firmware as
the project runs.
Page 4 of 10
SW Tx UART Component
This component is placed to send the converted voltage information to the external host via
UART. Note that this component is only a transmitter. By default, in this project, the BaudRate
parameter is set to 115,200. The configuration for the SW Tx UART is shown in Figure 5.
Page 5 of 10
IDAC Component
The PSoC 4000 has two internal IDACs, and the IDAC component has options to configure it as
either 8-bit or 7-bit. However, the 8-bit hardware is used internally by the ADC component, so
the Resolution parameter of this IDAC must be 7-bit. The Polarity, Value, and Range
parameters can be fully specified, their value does not affect the ADC. Only the Resolution
parameter must be set (to 7-bit), and the IDAC must be enabled (such as by a call to the
IDAC_Start() API). The default configuration of the IDAC can be seen in Figure 6. IDAC
Configure TabFigure 6.
Page 6 of 10
Project Description
When initialized, the ADC performs a self-calibration (no input) using the ADCs API. Then a
two-point calibration is performed in firmware.
The input voltage is an unknown. Assuming the ADC interprets the input with some offset and
gain error, ti can be modeled as a linear equation:
. Where y is the measured
voltage, m is some gain error, x is the unknown true voltage, and b is a voltage offset. We can
calculate values for m and b by using two known voltages for inputs.
The input is set to a low-driven pin and measured by the ADC, then set to a high-driven pin and
measured. This gives the two points needed for calibration
Using the known voltages of low and high-driven pins (Defined in main.c as VSS_MV = 1mV and
VDD_MV = 3408mV.), an offset and a gain adjustment are calculated.
To calculate the offset, first find the slope between the two input points.
Then use the second point and the slope-intercept formula to calculate the offset.
Page 7 of 10
All future measurements are adjusted to meet the calibration by applying the offset first, then the
gain adjustment.
These calculations are described in the code of main.c, using actual variable names and some
minor adjustments for integer arithmetic. The offset and gain adjustment values are sent over
UART before the project enters an infinite loop.
Inside the infinite loop, the ADC takes a measurement. The measurement is adjusted to the twopoint-calibrated value. Then both values are sent over UART, and the PWM duty cycle is set to
be the ratio of measured input voltage to maximum.
: 115200bps
Data Bit
: 8 bits
Parity
: None
Stop
: 1 bit
Page 8 of 10
Expected Results
The output pin of the PWM is also connected to the CY8CKIT-040 red LED which is active low.
At low input voltage, the PWM duty cycle will be small and the LED will appear to be constantly
on. As input voltage increases, the duty cycle will increase and the LED will begin blinking. As
input voltage increases further, the LED will be lit for decreasing amounts of time, causing it to
appear to dim.
The UART transmission of a sweep over a 3.3 V range is shown in Figure 8.
Page 9 of 10
The output of the PWM of a different sweep over a 3.3 V range is shown in Figure 9. The PWM
updates at the same time the UART transmits, which is every 500 ms.
Figure 9. Logic Analyzer PWM expected result
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 lifesupport systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
PSoC is a registered trademark, and PSoC Creator and Programmable System-on-Chip are trademarks of Cypress Semiconductor Corp. All other trademarks or registered trademarks
referenced herein are property of the respective corporations.
Any 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 lifesupport 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.
Page 10 of 10