2020-02-16 08:43 PM
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.
2020-02-16 09:52 PM
2020-02-16 10:01 PM
> 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.
2020-02-16 11:44 PM
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.
2020-02-17 12:28 AM
> 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.
2020-02-17 12:32 AM
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.
2020-02-17 01:08 AM
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.
2020-02-17 01:44 AM
Should I start/stop DMA to measure only the areas shown in the picture?
2020-02-17 01:56 AM
If the ADC has nothing else to do, then why not?
2020-02-17 02:05 AM
You should start ADC with DMA one time.
__IO uint32_t pData[950] = {0,};
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) pData, sizeof(pData);
The ADC is in continuous mode and triggered by the timer in charge to produce PWM wave each rising edge.
In this case you only have to start or stop the PWM TIMER to synchronize ADC+DMA conversion with your waveform.
HAL_TIM_PWM_Start();
The DMA get the request to ADC in normal mode for the amount of sample pData, which fit into your T half period you want to convert.
Then pData array will contains 950 samples. And repeat again on next PWM rising edge for a new conversion of T.
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.