This blog post is also the Part of PSoC 6 WiFi-BT Pioneer Kit (CY8CKIT-062-WIFI-BT) - Review Product LinkProduct Link (Figure 1). This post is also related to previous ones so for better understanding kindly take a look at those too.
Figure 1: PSoC6 WiFi-BT Pioneer Kit (details)
In the previous post we have learn how to successfully build and test the Hello World project based on UART_printf example. And also created a new project of Blinky LED without using any pre-built examples. Now we will built learn how to read ADC of PSoC6 MCU.
Read ADC (Ambient Light Sensor)
As we have already know that one of the major feature of PSoC6 MCU is its Analog signal handling capabilities. It has SAR ADC, op-amp, low power comparator, analog MUX, current and voltage DAC. In this project we will learn how to use SAR ADC of PSoC6 in continuous sampling mode to read the analog output voltage of ambient light sensor (figure 2) available on TFT shield of this kit. Its schematic is also shown in figure 3.
Figure 2: Ambient Light Sensor (datasheet: HERE) Available on TFT Shield
Figure 3:TEMT6000 Analog Ambient Light Sensor Available on TFT Shield (source HERE)
After reading the analog value, it will be transmitted to PC through UART. In this project we will use the previously created HELLO WORLD project and add the ADC functionality in it so that we can monitor the output of ALS. In this Project we will also use hardware samples averaging feature of PSoC6 ADC module. All the steps with detail are given below (Skipping all those steps that are previously mentioned). In this example void CyDelay(uint32 milliseconds) (figure 4) delay function is used to slow down the UART ADC data transmission.
Figure 4: Builtin delay function in PSoC Creator (source HERE)
Open the UART_printf project in PSOC Creator add scanning SAR ADC component in existing TopDesign schematic.
Double on newly added ADC component to Configure it. Modify the VRef Select, Number of Channels and Input Mode.
Go to Common tab in ADC configuration dialog and ADC Sample Mode should be Continuous and Click OK
ADC component will look like this after Configuration
Add Analog Input pin
Open the Analog Input Pin configuration dialog and rename it to ALS_Shield and change its configuration if required
Before selecting the Hardware pin for analog input. Find the ALS of TFT shield connection to PSOC6 Pioneer Board. It is connected to P10_0/A0 of PSoC6 Pioneer Board.
Assign the P10_0 to Analog Input Pin added into TopDesign Schematic.
Add the following lines before the forever for loop in int main() function in main_cm4.c file
Modify the forever for loop in main_cm4.c file to continuous read the ALS value and transmit it to PC through UART
Build and Program the PSoC6 pioneer board and verify the Ambient light sensor ADC value in UART monitor
Change the Number of Samples Averaged to 64 in ADC component configuration dialog to get the smooth values of ALS. After modifying it build and reprogram the PSoC6 Pioneer board to test the result.
ALS values will become smooth after increasing the number of sample averaged.