cancel
Showing results for 
Search instead for 
Did you mean: 

Need to get specific number of samples from ADC, what flag to use to indicate when arraystoring samples is full?

MCrew.1
Associate III

Hello all,

I need to store 6000 incoming samples from the ADC, analyze these 6000 samples and then store 6000 new samples in the same location and I need to do this repeatedly. I am using HAL_ADC_Start_DMA function to start the channel and I want to use a flag to indicate when HAL_ADC_Stop_DMA should be called based on when the array is full. Is there a flag which indicates when the array is full? And how can I (once analyzed), clear/overwrite the data with new data?

Thanks,

MC

3 REPLIES 3
TDK
Guru

The conversion will stop when you reach the number of samples requested in HAL_ADC_Start_DMA. You can implement your own version of HAL_ADC_ConvCpltCallback to do something when the conversion is done.

Per the source file for STM32F4 (since you didn't specify a chip):

     *** DMA mode IO operation ***    
     ==============================
     [..]    
       (+) Start the ADC peripheral using HAL_ADC_Start_DMA(), at this stage the user specify the length 
           of data to be transferred at each end of conversion 
       (+) At The end of data transfer by HAL_ADC_ConvCpltCallback() function is executed and user can 
           add his own code by customization of function pointer HAL_ADC_ConvCpltCallback 
       (+) In case of transfer Error, HAL_ADC_ErrorCallback() function is executed and user can 
           add his own code by customization of function pointer HAL_ADC_ErrorCallback
       (+) Stop the ADC peripheral using HAL_ADC_Stop_DMA()

If you feel a post has answered your question, please click "Accept as Solution".
MCrew.1
Associate III

So when the array is full, the HAL_ADC_ConvCpltCallback function is immediately called? Can I then start the ADC again using the same array (once the previous samples have been analyzed) and it will not call this callback function until a new 6000 samples have been recorded? Or does the array have to be cleared first to prevent the callback function from triggering immediately? Would setting the DMA mode to circular allow for a new 6000 samples every time?

Thanks,

MC

Ozone
Lead

I don't mess with Cube/HAL.

Set up a DMA TC interrupt, which is called when the configured number of items is transferred.

In your case. probably 6000x2 bytes.

In the TC interrupt, either move the data or swap buffers, or else the next ADC conversions will start to overwrite the values.