cancel
Showing results for 
Search instead for 
Did you mean: 

5 ADc channels to scan within 20us.

BDasa.1
Associate II

Hi I'm currentlz working on STM32G071RB nucleo board to measure five different voltages across a laser within the ON duration of the Laser i.e 20us using DMA. My ADC finishes conversion every 17us(checked using LED in the ADCconcmplt callback). When there is no time constraint(i.e when the laser is always ON) the ADC gives out the correct voltages across 5 nodes but when I try to read the ADC voltages within 20us it appears that the ADC voltages at two nodes are almost halfed. I'm using an exti to trigger the ADC. I collect the ADC smples in the ADCconvcmplt call back and I use a timer of 1s to average the samples collected. Any inputs regarding this is really appreciated. I tried debugging the software but is of no help. kindly help me with your suggestions

15 REPLIES 15
TDK
Guru

How do you know it's giving you incorrect values? Can you show a scope plot of the event?

The ADC in the STM32G0 is a SAR type ADC. It's not going to be awesome at a single measurement like this, particular if the event has noise associated with it and with a limited sample time. There's not going to be an easy answer here. Ensure your ADC inputs are sufficiently low impedance.

https://www.st.com/resource/en/application_note/cd00211314-how-to-get-the-best-adc-accuracy-in-stm32-microcontrollers-stmicroelectronics.pdf

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

Thanks for your response. I have attached screenshot from the osci and the the five node voltages from the terminal. In the osci plot the yellow plot corresponds to the duty cycle of the Laser within which all the 5 voltages have to be scanned and the red voltage is the toggle led function placed in the ADCconvcmplt callback. Whne the laser is always on (i.e when the yellow line is consatnt at 5v) I get the correct voltage readings (verified using a multimeter) also shown the terminal plot CW_mode.jpg, but when I try to turn the laser ON and OFF at a high modulation rate(1KHz-20KHz) I get incorrect readings or I'm sampling at the wrong instant.

BDasa.1
Associate II
 
BDasa.1
Associate II
 
berendi
Principal

The HAL callback mechanism has a couple of μs overhead, so you might get wrong values in the callback if the conversion sequence is started every 20 μs and takes 17 μs.

When the ADC is triggered by EXTI, the overhead from HAL isn't going to affect when the conversion happens.

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

I notice the red pulses and yellow pulses do not line up. If you're triggering on a rising edge of the yellow signal, there should only be one ADC conversion cycle. Seems like it's triggering more often than this. In other words, it doesn't look like your ADC conversions are synced to the laser pulse at all.

I would slow down the pulse frequency to see if they sync up and to make sure they're being triggered on the correct edge.

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

I have never said that.

It affects when the results are read.

BDasa.1
Associate II

I have used the osci in single mode and I'm triggering the ADC on the falling edge of ext11 and also my ADC is running in continuos mode. Could you please elaborate on the errors arising from my approach. In the call back I'm just summing the samples transferred by the DMA after conversion. Do I have to Stop my ADC in the call back and start it again?

Thank you berendi and TDK