Skip to main content
gokhannsahin
Associate III
February 17, 2020
Question

STM32 ADC DMA Sample Rate Time

  • February 17, 2020
  • 16 replies
  • 9184 views

Hi everyone, 

I have some questions about using ADC. I have an analog channel and want to read it for a specified time according to my PWM signal because it has been used as a voltage sense on an inductor. However, I need more samples and have to check the changes. To do this, set two-timers, one has been used to get compare of PWM value, other trig the ADC for 100samples. Here I am confused right here. I'm not sure how to calculate the timing, also I'm afraid of getting overrun and wrong data. So, I need your help and have some questions about this application. By the way, I'm using STM32G431 which is new MCU.

  1. The datasheet says that the maximum of the clock frequency of the ADC module is 40MHz. The clock frequency of MCU is 160MHz. Then, should I set the clock prescaler of ADC as "Sync divided 4" or does it never exceed 40MHz anyway? (for example, what about in async 1?)
  2. If a new trig occurs by the timer used for trig before the adc read cycle is complete, will raw value be wrong?
  3. How should I set the trig time according to adc reading time?
This topic has been closed for replies.

16 replies

berendi
Principal
February 17, 2020
  1. It is not guaranteed to work above 40 MHz. Read: it might work every time on your desk, and sometimes fail in the field.
  2. You'll just get the previous conversion result again. The reference manual says, "Any hardware triggers which occur while a conversion is ongoing are ignored."
  3. Try continuous conversion mode, so after each conversion a new one is started right away by the ADC itself.
Ozone
Principal
February 17, 2020

> If a new trig occurs by the timer used for trig before the adc read cycle is complete, will raw value be wrong?

I suppose the the trigger is ignored, or previous conversion is abandoned. Never tried that.

What is the sampling rate you would need ?

Several STM32F variants support a dual/triple ADC mode, with intersected triggers to achieve a higher sample rate.

Not sure about such features for the G series.

gokhannsahin
Associate III
February 17, 2020

Actually,there is no specified sample rate.

I want to get the maximum possible sample so I can get more accurate results.

I enclosed the picture of pwm and the signal to be measured, you can see.

0690X00000DBeiWQAT.jpg

Ozone
Principal
February 17, 2020

> Actually,there is no specified sample rate.

> I want to get the maximum possible sample so I can get more accurate results.

On second look, this is contradictory.

You need a sampling rate/trigger related to your signal, and PWM cycle.

If your sampling point is unsynchronized (flaoting), you don't know what (when) you measure.

RomainR.
ST Employee
February 17, 2020

Hi gokhannsahin,

From STM32G474 datasheet (DS12589.pdf Rev2), the maximum ADC Clock frequency 60MHz (for single ADC operation)

Let's suppose you choose to set ADC prescaler to have ADC Clock = 40Mz, with a sample time 2.5 ADC Clock with 12-bit resolution.

You get ADC TConversion = (2.5+12.5) x 0.025µs = 0.375µs.

in this setup you are able to convert up to 950 samples (match and fit with your signal half period of 357µs)

In your case, you could use ADC in continuous mode (with Tconversion = 0.375µs) combined with DMA to convert the full period of your waveform and obtain an array of 1904 sample.

To synchronize ADC conversion with the full period, you can trigger your ADC one time at the rising edge of pwm and let ADC get the full period in continuous.

If you need less sample / period, increase ADC sample time according your need.

Best regards.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
gokhannsahin
Associate III
February 17, 2020

Should I start/stop DMA to measure only the areas shown in the picture?

berendi
Principal
February 17, 2020

If the ADC has nothing else to do, then why not?

berendi
Principal
February 17, 2020

I would just let ADC running continuously, set an analog watchdog on the signal with interrupt, and start DMA from the interrupt handler whenever it is above the range.

gokhannsahin
Associate III
February 18, 2020

Then, if I use the compare event of PWM to start DMA while in ADC conversion mode, it will take as many samples as the number of samples I have specified and occur interrupt. It will wait until the next event, so it will not work. I'm right?