Sphere
Log in Join
☆ 9

stm32 adc readings noisy, averaging not helping enough

STM32F103C8 (Blue Pill), reading a potentiometer and a photoresistor on ADC1 channels 0 and 1. Readings jitter by +/-15 counts on a 12-bit ADC even with a stable input. I'm averaging 16 samples in software, which helps a little but not enough. VDD is from the board's 3.3V regulator, and I'm using VDD as the ADC reference. The board has no decoupling beyond what's on the module. Is this expected noise, or is my setup bad? Should I add a capacitor on the input, or use a different reference? I want stable readings for a control loop.

⚑ Report

4 replies

☆ 0
V vector ·2026-11-10#1

+/-15 counts (about 1% of full scale) on a Blue Pill is common - those boards have noisy 3.3V regulators and no proper analog grounding. Since you're using VDD as reference, any ripple on VDD directly affects readings. Add a 0.1uF ceramic capacitor from each ADC input to ground close to the pin, and a 10uF on the 3.3V rail. Also increase the sampling time (e.g. 55.5 cycles) so the sample capacitor fully settles with a high-impedance source.

⚑ Report
☆ 0
C cardboard62 ·2026-11-14#2

I'll add caps. I'm using the default 1.5-cycle sampling time - bumping that might help. For the photoresistor, the divider is 10k to 3.3V and the LDR to ground, so source impedance is in the 10k range. Is that too high for short sampling times? Also what's a sane filtering approach for the control loop - exponential moving average better than a boxcar?

⚑ Report
☆ 0
F fern67 ·2026-11-15#3

10k source impedance with 1.5 cycles is definitely too short - the ADC's sample cap can't charge, hence the jitter. Set sampling to 55.5 cycles and it'll improve a lot. For filtering, an exponential moving average (y = y + alpha*(x-y)) is cheap and has low memory, good for a control loop. A median filter of 5-7 samples rejects spikes better. Combine: median then EMA. Just remember filtering adds lag, so tune alpha against your loop's response time.

⚑ Report
☆ 0
R regex ·2026-11-17#4

Bumped sampling to 55.5 cycles, added 0.1uF caps on both inputs, and used a median-of-7 then EMA filter. Jitter dropped to +/-2-3 counts, which is fine. The sampling time was the big one - 10k impedance needs way more than 1.5 cycles to charge the sample cap. If your STM32 ADC is noisy, check sampling time and source impedance before writing fancy filters.

⚑ Report
Log in to reply.