Skip to main content
Visitor II
September 17, 2025
Question

ADC Fluctuation

  • September 17, 2025
  • 6 replies
  • 447 views

Hello,

I have a ADC clock running at 96MHz prescaler divided by 10, 12bit, Sampling time 47.5 Cycles. I am just trying to sample this DC volgtages.  I have a battery that has around 20Volts, and I am stepping this voltage down using the voltage divider as U8, U1, U2 to be sampled by the ADC. I have two ADC measuring BN, and Vref to measure the current across the 1Ohm resistor. I am getting consistently accurate values, but I have this random 5mv difference or 30mV spikes that happens out of no where. I am not sure how to fix this to improve my ADC resolution. Could you please give me an idea how to proceed? 

I really appreciate the time and effort for this matter

 

Thank you

ytshin0877_4-1758084688725.png

 

ytshin0877_0-1758083861526.png

ytshin0877_3-1758084135450.png

 

 

 

 

 

    This topic has been closed for replies.

    6 replies

    Super User
    September 17, 2025

    Is any other ADC running at the same time?

     

    The 'G4 family has several ADC related errata, and a family-specific ADC appnote, try to read them. 

    JW

    Visitor II
    September 17, 2025

    Hello. I am using ADC1, ADC2, and ADC5. They all have same sampling time and clock dividing presaclers.

     

    Can running 3 ADC at the same time cause this?

     

    So I made all the sampling time to be the same, and I was able to improve to 5mV fluctuations, and I am wondering if this is the maximum resolution I can get?

     

    Thank you

     

     

    Visitor II
    September 17, 2025

    Now I have set the all the sampling time to 47.5 Cycles, and I am having 5mV fluctuation. Is this the best this adc can do?

    ytshin0877_0-1758085856155.png

     

    Super User
    September 17, 2025

    Is it 5mV at the ADC input, or at the battery? From the graph it appears that it is one ADC bin (i.e. change in LSB), if that's the case, you don't have many other options than filtering/averaging.

    I am not an expert just another user, and I don't use the 'G4 family actively.

    JW

    Visitor II
    September 17, 2025

    So the 5mv fluctuation is observed when I measure the voltage across 1ohm resistor. I have Vref to be 12V and this is stepped down to like 2V to be measured by stm, and another node measures about 13Volts. I get current based on voltage difference across these two nodes. 5mv fluctuation is when I measure both nodes and subtract from STM side. Are there any way to improve this?

    Explorer
    September 17, 2025

    Does "relay" in the schematics mean a magnetic device, i.e. a switch with a coil ?

    This can definitely cause such issues when switching.

    Visitor II
    September 17, 2025

    Relay is either turned on and off for charging and resting operation. when the charging is happening and collecting current, the relay is off(no current flowing through the coil), and I am using RF based relay to minimizing this effect.

    Where do you think this fluctuation is coming from? Is there anyway to optimize my ADC caps or sampling time, prescaler, and frequency?

     

    Any recommendtation would help a lot

    Explorer
    September 17, 2025

    I'm not a hardware designer, so my experience is limited.
    But does your MCU have separate V(DDA) pins ? If so, use them, and take some extra measures to stabilize this supply.

    In general, I would recommend to record overall current consumption together with the ADC inputs (battery voltage), to see if ADC spikes coincide with supply current spikes.

    Visitor II
    September 17, 2025

    A few ideas that usually help in this situation:

    • ADC oversampling / averaging: STM32 ADCs support hardware oversampling, or you can do simple software averaging across multiple samples. This reduces random noise and gives you a more stable reading.

    • Check with external measurement: Use an oscilloscope or a precision multimeter on the divided battery line and across the shunt to confirm whether the spikes are really present in the analog domain, or if they are only visible in the ADC results.

    Super User
    September 17, 2025

    You will always have some amount of noise in the ADC reading. You can't get 12 noise-free bits from the STM32 ADC. It looks like you only get a few counts of noise which is about as good as you can do.

     

    General tips for improving accuracy here:

    How to optimize the ADC accuracy in the STM32 MCUs - Application note