Skip to main content
BDasa.1
Associate II
June 30, 2020
Question

5 ADc channels to scan within 20us.

  • June 30, 2020
  • 11 replies
  • 4732 views

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

This topic has been closed for replies.

11 replies

TDK
Super User
June 30, 2020

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
BDasa.1Author
Associate II
July 2, 2020

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
BDasa.1Author
Associate II
July 2, 2020

..

BDasa.1
BDasa.1Author
Associate II
July 2, 2020

..

berendi
Principal
July 2, 2020

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.

TDK
Super User
July 2, 2020

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""."
berendi
Principal
July 2, 2020

I have never said that.

It affects when the results are read.

TDK
Super User
July 2, 2020

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""."
BDasa.1
BDasa.1Author
Associate II
July 2, 2020

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

TDK
Super User
July 2, 2020

> ContinuousConvMode = ENABLE;

This seems wrong here, if you're just trying to convert one channel per trigger. Not sure though.

> Do I have to Stop my ADC in the call back and start it again?

No, you shouldn't need to do this. Ensure DMA is in circular mode and it shouldn't stop.

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

I want to convert 5 channels in continuos mode. I have used DMA in circular mode for peripheral to memory transfer.

S.Ma
Principal
July 2, 2020

Does G0 provide a trigger pin to launch a one shot dma circular round? Ideally use twice buffer size so you have double buffer time to process the previous batch while new one is being converted. then with dma interrupts you will latency relax constrains.