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.

1 ACCEPTED SOLUTION

Accepted Solutions
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.

View solution in original post

12 REPLIES 12
MM..1
Chief II

Try configure MCU clock without PLL (HSI or HSE)

ikrosoft
Associate II

Thanks for you answer.

Sadly I can't do without the PLL (the MCU needs to be running at almost max speed), but still I've managed to reduce the PLL_N multiplication factor from 84 to 21. It looks like it's not helping though, the ADC still freezes.

Why do you point at the PLL? Is there some known bugs or undocumented limitations?

As suggested in the aforementioned thread, I've tried to restart the ADC + DMA when ADC freeze is detected. This indeed allows resuming ADC operation back to normal, but it's not really a solution.

Any other ideas of what could cause the observed ADC freezes?

Igor Cesko
ST Employee

Hi ikrosoft (Community Member),

Please check if the VREF+ / VSSA decoupling is perfect. Capacitors (1uF + 100nF) must be located very very close to the VREF+/VSSA pins. Please read recommendations for ADC in application note AN5346.

Regards

Igor

Hi Igor,

Thanks for your input. VDDA/VSSA pins are indeed well decoupled using 1uF+100nF ceramic caps placed ~1mm from the pins, but the caps are on the other side. I'll try and move them to the same side just in case.

Best,

ikrosoft

Igor Cesko
ST Employee

Hi ikrosoft (Community Member),

What is the ADC clock? What is the "constant" ADC value (output word from ADC)? Which device revision are you using? Try to replace DMA with interrupt or polling method - to identify if the problem is in the DMA or not.

Regards

Igor

jtron.1
Associate III

Hi All.

I am trying to use STM32F103 devices ADC channel number 0 and 1.

I checked the voltage over the pin IN0 and IN1 is 0.8V to 0.99V without giving any input to the pin due to this I am getting wrong value.

Could you please tell me the cause for this??

Thanks

Igor Cesko
ST Employee

Hi jtron.1,

If ADC input pin is floating then the input voltage is undefined and if you are measuring this floating pin the voltage is some residual voltage on sampling capacitor.

Why are you not providing some voltage on IN0 and IN1 an measuring it?

Regards

Igor

jtron.1
Associate III

Thanks for the reply Igor.

Will residual voltage affect the accuracy?

When I try to pull this voltage down then I got 0000 reading on my display.

Can I use external pull down resistor.??

My concern is this the floating pin voltage is about 900mV to 1V so if I apply voltage less than 900mV will it work?

Because I want to measure voltage less than 600mV.

I did not provide yet as I was stuck in floating voltages I am getting on IN0 and IN1.

Thanks...

Igor Cesko
ST Employee

Hi jtron.1,

The voltage on floating ADC input pin is very weak - so external signal easily force own voltage on pin. The source signal impedance must follow the datasheet requirements: impedance less than 50 kOhm.

Regarding the voltage on IN0 and IN1 : what is the ADC result (data from ADC) for those channels? Are they zero or another values? And is this value fixed also if input volatge is changing?

Regards

Igor