ADC

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Andrew7
Level 3
Level 3
25 sign-ins 10 questions asked 10 replies posted

Using Signal Generator give following signals and find using ADC
a. Square wave input frequency range 50 Hz to 1 KHz in.

1) Find Frequency.

2) Find average voltage.

b. Input Sine wave 50 Hz to 1 KHz

1) Find Frequency.

2) Find Peak to Peak value.

3) Find Offset value.

Display the result using UART -> putty on the host computer once every 3 to 5 secs interval.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Anshuman7,

Attached is a basic project which samples input by ADC_SAR and stores it into the RAM Buffer (4000 samples) using DMA. Once all samples have been acquired, the ADC is paused and data "processing" begins. After that the cycle repeats.

     In this demo all data is simply output to the chart plotting software (SerialPlot) using UART.  You can put any own processing code in this section and send results to the Terminal (Putty) instead. The SerialPlot is a freeware tool, which can be downloaded online.

SerialPlot: interface to real-time data charts 

Download SerialPlot: Hackaday.io: SerialPlot - Realtime Plotting Software 

Project archive is attached.

/odissey1

 

Figure 1. Project schematic. The ADC_SAR is configured for external clock (40kHz), and DMA transfer length of 4000, which allows for total sampling time of (4000 samples / 40kHz) = 0.1sec. Once all samples have been acquired, DMA interrupt fires pausing ADC. ADC-DMA-RAM_SW_8bit_01b_ADC.png

 

Figure 2. Optional test signal generator. The wave is configured for 200 points per period. The output frequency is controlled by the Clock_DAC as: Fout = Clock_DAC/200. As shown: Fout = 10kHz / 200 = 50Hz. ADC-DMA-RAM_SW_8bit_01a_WaveDAC.png

 

Figure 3. The SerialPlot custom component for formatting the UART output and plotting acquired data. The component is already imported into the project. It is configured for 1-channel of Simple Binary uint8 data. UART is configured for 115k rate and connected to default Pin_12_7. ADC-DMA-RAM_SW_8bit_01a_UART.png

 

Figure 4. CY8CKIT-059 external connections. ADC input is on Pin_0_0. Optional Signal Generator output is on the Pin_3_0. The SerialPlot automatically connects through KitProg - no physical connection to the Pin_12_7 is necessary. Project annotation created using PSoC Annotation Library v1.0 

ADC-DMA-RAM_SW_8bit_01a_Kit-059.png

 

Figure 5. The SerialPlot capture of the 50Hz square wave centered at 2V, and 2V p-p amplitude. The SerialPlot charting software is configured for 115k, Simple Binary, 1-channel, uint8 data transfer, 4000 samples/page (as shown below).  

ADC-DMA-RAM_SW_8bit_01a_SerialPlot_50Hz.png

 

Figure 6. The SerialPlot capture of the 1kHz square wave centered at 2V, and 2V p-p amplitude. The SerialPlot  configuration is the same as above.

ADC-DMA-RAM_SW_8bit_01a_SerialPlot_1kHz.png

View solution in original post

0 Likes
8 Replies
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Hi Anshuman7,

Which part of this school assignment dont you understand ? Some things you need to do :

*Define which hardware to use 

* Write a program to read the ADC values into a buffer

* Write a program to analyse frequency and average voltage

(etcetera)

Which part are you stuck with ? For finding the frequency, draw a SquareWave graph with time and voltage axis and think what your would do to analyse what the frequency is.

 

0 Likes

Hello, I did this :
x=ADC_SAR_1_GetResult16();
y=ADC_SAR_1_CountsTo_Volts(x);
VDAC8_1_SetValue(y) to get the value.. now I want to know the logic to get the frequencies and peak to peak voltage value.. how do I do that and print in the UART (PuTTy) ?

0 Likes
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Why do you need VDAC8 for that ? Just put the y values in a buffer and go on as described in my previous reply. Take a good look at the previous homework assignments and you will find enough hints on how to print.

0 Likes

Can you do one part and send it to me? This is only my first assignment for ADC .. Also.. how to put in buffer?

0 Likes

As this is a homework assignment, you should be able to do it yourself (or find out yourself). With Buffer I mean an array of measurement data, basic C knowledge.

0 Likes

I know how to find frequency/average voltage of a waveform on paper of any waveform. Since I'm new to Psoc/Embedded C, I'm unable to proceed with clarity. I just wanted an example because I'm finding it difficult to implement to logic in the coding environment of the Psoc.. Thankyou for whatever help you provided.

0 Likes

The first thing to do is note your range of input frequencies.  Your minimum is 50Hz and maximum is 1kHz, so you will need to take samples over at least a 20ms period to catch the entire waveform at 50Hz (try using a timer + interrupt to space out when your samples are taken to ensure you get nice even spaces of time between each sample).  You will also need to ensure that you are taking samples quickly enough to be able to determine frequency from your sampled data.

As far as finding the average voltage, it should be as simple as dropping your ADC sample values into an array and then taking an average of all the values inside the array.  Sum them up (try a for() loop to iterate through the values), then divide by the number of samples. Tip: If your number of uint16_t samples is a power of two (say, 64), you can do the division with a right shift operation (>>) rather than an actual division operation.  Divide by 2 is shift one bit to the right.  Divide by 4 is shift two bits to the right, Divide by 8 is shift three bits to the right, and so on.  A divide by 64 would be a shift 6 bits to the right.  It's quicker than doing an actual division operation.

For finding Peak to Peak, using your array of ADC samples, iterate through the array (here's another for() loop) and identify the highest and lowest values.  These should be your peaks, then just take the difference between them (max-min).

You should be able to find the frequency from the amount of time between max or min peaks.  This is easy to calculate if you know how much time is between each sample of the ADC.

Hopefully this should be enough to get started.  If you need to know how to work with loops or arrays, or how to configure a timer and corresponding interrupt, you may need to look into learning a bit about the C language, programming, and microcontroller principles in general.  The thing to know is that folks will usually be happy to answer specific targeted questions about these sorts of things, but few will have patience to do someones homework assignment for them.

0 Likes
lock attach
Attachments are accessible only for community members.

Anshuman7,

Attached is a basic project which samples input by ADC_SAR and stores it into the RAM Buffer (4000 samples) using DMA. Once all samples have been acquired, the ADC is paused and data "processing" begins. After that the cycle repeats.

     In this demo all data is simply output to the chart plotting software (SerialPlot) using UART.  You can put any own processing code in this section and send results to the Terminal (Putty) instead. The SerialPlot is a freeware tool, which can be downloaded online.

SerialPlot: interface to real-time data charts 

Download SerialPlot: Hackaday.io: SerialPlot - Realtime Plotting Software 

Project archive is attached.

/odissey1

 

Figure 1. Project schematic. The ADC_SAR is configured for external clock (40kHz), and DMA transfer length of 4000, which allows for total sampling time of (4000 samples / 40kHz) = 0.1sec. Once all samples have been acquired, DMA interrupt fires pausing ADC. ADC-DMA-RAM_SW_8bit_01b_ADC.png

 

Figure 2. Optional test signal generator. The wave is configured for 200 points per period. The output frequency is controlled by the Clock_DAC as: Fout = Clock_DAC/200. As shown: Fout = 10kHz / 200 = 50Hz. ADC-DMA-RAM_SW_8bit_01a_WaveDAC.png

 

Figure 3. The SerialPlot custom component for formatting the UART output and plotting acquired data. The component is already imported into the project. It is configured for 1-channel of Simple Binary uint8 data. UART is configured for 115k rate and connected to default Pin_12_7. ADC-DMA-RAM_SW_8bit_01a_UART.png

 

Figure 4. CY8CKIT-059 external connections. ADC input is on Pin_0_0. Optional Signal Generator output is on the Pin_3_0. The SerialPlot automatically connects through KitProg - no physical connection to the Pin_12_7 is necessary. Project annotation created using PSoC Annotation Library v1.0 

ADC-DMA-RAM_SW_8bit_01a_Kit-059.png

 

Figure 5. The SerialPlot capture of the 50Hz square wave centered at 2V, and 2V p-p amplitude. The SerialPlot charting software is configured for 115k, Simple Binary, 1-channel, uint8 data transfer, 4000 samples/page (as shown below).  

ADC-DMA-RAM_SW_8bit_01a_SerialPlot_50Hz.png

 

Figure 6. The SerialPlot capture of the 1kHz square wave centered at 2V, and 2V p-p amplitude. The SerialPlot  configuration is the same as above.

ADC-DMA-RAM_SW_8bit_01a_SerialPlot_1kHz.png

0 Likes