Faster method to read the ADC

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

cross mob
Mrinal
Level 4
Level 4
First solution authored 50 replies posted 25 replies posted

My ADC is running at 12MHz, it samples 5 channels and the actual sampling rate is 100KHz.

   

I just noted that reading a single channel using the ADC_GetResult16() command takes a whooping 1us at 48MHz CPU speed.

   

It takes over 5us to read the 5 channels. Now at 100KHz sampling rate, time between two successive samples is 10us out of which 5us is wasted in simply reading the ADC. Only 5 remains for performing other calculations before the next sample arrives.

   

This is very very slow. In fact what sense does it make if the ADC runs at 1MSPS and takes another 1us to read the channel.

   

Is there a faster method to read the ADC channels?

   

Can't we directly read the channel resistors?

   

Thanks

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You may use a PSoC4-M which has got DMA. So you can shovel the data to a buffer and work on it while the next data gets sampled and transmitted. This requires after setup no CPU intervention except the interrupt handling.

   

Reading (as recommended) the result registers directly in an eoc handler woud be quite suficient.

   

for (chan = 0;chan < MAXCHANNELS; chan++)

   

{

   

        *ResultVector++ = CY_GET_REG32((reg32 *)(ADC_SAR_SAR_CHAN_RESULT_IND + (uint32)(chan << 2u))) &
                ADC_SAR_RESULT_MASK;

   

}

   

You can set for a file the compiler optimization individually, so the rest of the project can be debugged.

   

 

   

Bob

0 Likes
Mrinal
Level 4
Level 4
First solution authored 50 replies posted 25 replies posted

Thanks Bob for the quick response.

   

POSC-4M sounds interesting. Time for me to take a deeper look at it.

   

Meanwhile, the method above  for reading the ADC registers directly, has reduced the channel read time from 1us to 189ns! It works well enough for me to ignore the M for some more time. Feeling Happy 🙂

   

Thank you!

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are always welcome!

   

Get hands on a CY8CKIT-043 with a PSoC4-M

   

 

   

Bob

0 Likes