Removing noise from ADC for STM8S 8-bit microcontroller
There are several possible causes for this CODE SPREAD.

deterministic noise entering along with the signal; try 1,000 ohms in series, and 0.1uF capacitor from the ADC Analog VIn pin, to Ground (analog Ground?) with very short leads on the capacitor.

is the MCU or ADC well bypassed, right at the AVDD pins?

is the ADC VREF pin well bypassed, with the capacitor going right to the AGROUND pin


and importantly

consider a GROUND PLANE, tho that will not fend off magnetic fields of SwitchReg or power transformers; standard copper foil is useless below 4 MHz edge rates;

I assist a musician in embedded_systems for signal processing of music instruments. He has used these methods, plus moderately shielded cables, PLUS NO BLACK BRICK POWER SUPPLIES anywhere nearby, to reduce Code Spread from 30 milliVolts down to &lt; 1 millivolt.