cancel
Showing results for 
Search instead for 
Did you mean: 

ADC output suddenly becomes constant

ikrosoft
Associate II

Hello,

I'm using the ADC on a STM32G431 to read 5 voltages at 20kHz. Everything works well, but suddenly the 5 channels "get stuck" or freeze, i.e. the value they measure becomes constant even though the voltages on the input pins still fluctuate. Sometimes the measured values resume to being correct again by themselves after a little while (like after 200 samples for instance), other times the values remain constant until I manually cycle the MCU power.

Some more details about the code architecture:

  • I use 5 channels of the ADC2 in single-ended mode
  • The sequence of 5 regular conversions (Single conversion mode) is triggered by TIM2's TRGO (update event at 20kHz)
  • Data is stored in an array by DMA in circular mode. In the DMA ISR I have code to copy and log this data (at each DMA transfer complete interrupt).

Some info about my debugging so far:

  • I've enabled ADC overrun interrupt and checked that it never gets fired
  • Same goes for the DMA transfer error
  • When logging the data I also log a timestamp (the value of a free running timer) to be certain that it's not my logging that gets stuck or that I'm seeing a scheduling problem. No issue there, the DMA ISR (and thus the logging) always gets called at 20kHz.
  • Although the ADC measures are unrelated, this same PCB is also powering a motor. And it looks like it's when the motor has to performs an abrupt speed step that the ADC values get stuck. But I've looked at VDDA (= Vref+) with an oscilloscope, and there's no particular glitch to be seen when the values get stuck.

NB: this is surprisingly similar to this question by @FChen.3​ , but since no answer was given there I thought sharing my case still is useful.

12 REPLIES 12
jtron.1
Associate III

Hi Igor,

Actually I am trying to measure the voltage of PWM signal at 1kHz with 50% duty cycle. Now the signal I am measuring having amplitude 3.1V checked on CRO and the ADC considering this and showing the results as per this for instance Vref is 3.3V ADC is 12-Bit. (4095/3.3)xADC_IN0=3846 which is I am getting with slightly jumping that is not a problem for now. But, when I check the voltage with multimeter it is showing 1.6V now I am confusing what's going on.?

I want to just measure the PWM signal with right way.

Also tried one thing I used 1uF,25V electrolytic capacitor just after the PWM signal and 10K resistance in series with ADC pin by doing this it is showing right value as per the multimeter. I am not sure that it is right way to measure the PWM signal or not.

Am I doing right or wrong here pl let me know??

What sort of thing I should be taken care of while measuring PWM signal.?

First learn teory... PWM is modulation type and need demodulate before measure.
Schematics is PWM out – R – C to gnd R and C need calculate based on freq and max pin current ...
Demodulated voltage can you measure on C.
jtron.1
Associate III

Ok thanks for the reply.