cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating effective ADC sample rate when using Timer Event to trigger conversion [STM32H7]

bnguy.1
Associate III

I understand the TIMER event can automatically trigger an ADC conversion that gets saved to memory (via DMA)..

But if the ADC is configured to SCAN more than 1 channel, does that mean that sample rate per channel must be the TIMER rate divided by the number of channels? i.e. does each trigger event cause only one channel in the scan list to be converted... or does each timer event trigger the ADC to perform a conversion across all SCAN channels ("NbrOfConversion")?

Or is it a configurable option of the ADC how it will handle it?

7 REPLIES 7
TDK
Guru

It is configurable. You can configure the number of channels to convert per trigger with the ADC_CR1_DISCEN and ADC_CR1_DISCNUM fields. If DISCEN=0, it'll convert all channels in the sequence. There are corresponding options in CubeMX (Discontinuous Conversion Mode).

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

it appears to do one scan of all the channels then stop, when hadc1.Init.DiscontinuousConvMode = ENABLE. It does not seem to convert / DMA the number of samples specified in : HAL_ADC_Start_DMA

When hadc1.Init.DiscontinuousConvMode = DISABLE, it scans all channels, and fills the entire buffer. However, each channel is not sampling at the TIMER event. For example, when NbrOfConversion = 3 versus 1, then I get 3 times LESS the number of HI/LO samples per channel with the exact same square-wave input.

I tried  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV and ADC_EOC_SINGLE_CONV but it did not appear to impact the sample rate when more than 1 channel is converted;

What do you want it to do? How are you triggering it?
If you feel a post has answered your question, please click "Accept as Solution".

Ideally, I'd like for the ADC to sample all the channels at the Timer Event rate.

The Timer Event is currently triggering the conversion, however, if there is more than 1 channel in the SCAN, then it seems only one channel gets converted per trigger event... it then converts the next channel in the scan list on the next trigger event, and so on.

Is it possible, for the ADC to scan all channels upon the Timer Trigger event?

TDK
Guru

> I'd like for the ADC to sample all the channels at the Timer Event rate.

Disable continuous conversion mode.

Disable discontinuous conversion mode.

With that, it'll convert one full sequence per trigger.

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

Disabling continuous and discontinuous, I still get half the number of samples for a single cycle of a square wave input when switching from NbrOfConversion = 1 , to NbrOfConversion = 2

It seems if I want to maintain a given sample rate, the timer needs to take into account the number of channels.

You may want to drop Cube/HAL lingo and discuss the issue in terms/register bits/fields given by RM.

In 'F4, there's a SCAN mode, enabled by SCAN bit in CR1, doing exactly this. It has a dedicated subchapter in the ADC chapter. I don't use 'H7 but I doubt there is nothing comparable there.

JW