cancel
Showing results for 
Search instead for 
Did you mean: 

What is the role of "Continuous Conversion" ADC option, when using Timer Event to trigger conversion?

bnguy.1
Associate III

I've enabled the ADC's SCAN option to convert 8 channels, and have the conversion triggered from a 16khz Timer Event. A DMA stream is enabled to get the data.

I'm unsure what the ADC's Continuous Conversion ("ContinuousConvMode") should be set to. For example, if enabled, then once the first trigger event happens, it will therafter run continusouly?

Also, is it the case that ch1 would always be sampled in sync with the 16khz trigger event, but channel 8 is always sampled at 16khz+delta? i.e. the timer event indicates only the time the first channel will be sampled?

Finally, is it best practice to first start the dma, then the timer, or the other way around? And in CIRCULAR mode, the DMA length is set to the number of channels to be converted before wrapping back to the start of the buffer?

#define NUMBER_OF_ADC_CONVERSIONS                    8
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_DATA[0], NUMBER_OF_ADC_CONVERSIONS );
HAL_TIM_OC_Start (&htim4, TIM_CHANNEL_1 ); 
 

3 REPLIES 3
TDK
Guru

> For example, if enabled, then once the first trigger event happens, it will therafter run continusouly?

Correct. Continuous conversion means once triggered, the ADC will never stop. This is the ADC_CR2_CONT bit. The reference manual has good info on it.

> Also, is it the case that ch1 would always be sampled in sync with the 16khz trigger event, but channel 8 is always sampled at 16khz+delta? 

I'm 80% sure this is configurable. You can either have it convert all channels on each trigger, in which case it acts like you describe, or only a single channel per trigger. I think this is controlled by ScanConvMode. 80% sure.

Actually, I think it's always like you describe when converting multiple channels. Could be wrong.

> Finally, is it best practice to first start the dma, then the timer, or the other way around?

Set up the DMA, then the ADC, then the timer that triggers the ADC. That way, the DMA is ready to act immediately. Otherwise, you will introduce a race condition.

> And in CIRCULAR mode, the DMA length is set to the number of channels to be converted before wrapping back to the start of the buffer?

For circular mode, the length of the DMA buffer as passed by the last parameter of HAL_ADC_Start_DMA is the number of transfers to make before restarting. Typically this is some multiple of the number of channels you're converting so that each location in memory holds the same channel information.

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

Which STM32?

>Also, is it the case that ch1 would always be sampled in sync with the 16khz trigger event,

I don't think so.

In continuous conversion mode, the ADC starts a new conversion as soon as it finishes one

To me, this doesn't sound like waiting for trigger, but honestly I did never care much for ADCs. And they also differ quite significantly between families.

Start with reading the ADC chapter in RM.

JW

bnguy.1
Associate III

It seems the ADC must be set to continuous in order for the timer event to trigger a conversion. When continuous is disabled, the adc does only 1 set of conversions.. despite continuous timer events.