How can I decrease the update rate of the analog conversion?

I'm working on this analog converter circuit. The potentiometer is connected to pin AN0. The resistance value is shown on a 7 segment display. The circuit works fine but the ADC's update rate is too fast. I want to decrease the update rate of the ADC converter (I want the value to slowly change if that makes sense.) I have some ideas about how to solve the issue:

1. Getting the average of every 10 or so resistance values and show that on the display.
2. Slowing down the convertion process by changing the prescaler value of the ADC (but it can't be set more that 1/64.)

If you have any other ideas or know how I can actually apply my solutions I would appreciate it.

Microcontroller: PIC18F4620

Potentiometer: 2k Ohm

ADC code (the rest of the code is about the 7 segment display):

    setup_timer_0(RTCC_INTERNAL | RTCC_DIV_16 | RTCC_8_BIT);
set_timer0(160);



Schematic:

• I'm not convinced you mean precision. Precision is how small a measurement is, usually the number of bits for an ADC - ie a 10-bit ADC is more precise than an 8-bit. Do you perhaps mean you want a slower update rate? So you get new values to the display slower? Commented May 11, 2023 at 13:02
• If you mean it's fluctuating too fast, i.e. too noisy, then averaging is a good way to go. Accumulate 2^N samples, then divide by 2^N. (For N=4, just drop the last nibble, etc)
– user16324
Commented May 11, 2023 at 13:10
• I think you're looking for a digital low pass filter on your ADC, how is your ADC value stored ? Commented May 11, 2023 at 13:10
• look up cascaded integrator comb (CIC) aka Hogenhaur filter. It's a very efficient moving average filter, ie very suitable for MCU implementation Commented May 11, 2023 at 13:13
• Your question is not clear. If the pot is changed rapidly, do you want the display to wait, and then snap to the new value (a slow update rate)? OR, do you want the displayed number to slowly step to the new value as if the pot were turned slowly (lowpass filter of the data). These are two very different problems to solve. Commented May 11, 2023 at 13:18

It's usually desirable to not update the display too frequently, say more than 3x per second. Around 2x-3x per second is good. Too low an update rate and the lag is irritating to the user. Too fast and you could get numbers flipping back and forth between two values leading to a confusing display.

If your reading rate is, say 100x per second you could simply add every 32 values then arithmetic right-shift 5 bits (divide by 32) and display. That's effectively a boxcar FIR (Finite Impulse Response) filter. That would give you a display update rate of about 3x/second. You just have to ensure that the sum does not overflow. If you add up enough readings and there is enough of the right kind of noise in the reading you may be able to effectively increase the resolution of the ADC by as much as $$\\log_2(\sqrt{\text n})\$$ bits, where n is the number of readings.

If you want filtering beyond reducing the update rate, one easy approach is to insert an IIR (infinite impulse response) filter. That's very simple if you have periodic ADC reads (fixed period). The concept is to pick some number $$\\alpha\$$ < 1 and each time you do an ADC conversion you update the value v with reading r as follows:

v = v(1-$$\\alpha\$$) + r($$\\alpha\$$), and then display v

If $$\\alpha\$$ = 1 you have instant updates and the history does not matter. As $$\\alpha\$$ approaches zero the display takes longer and longer (in terms of sample times) to approach the ADC reading. Mathematically, it never quite gets there, but it gets close enough. If you don't have floating point available you would have to do some scaling to use integer math. You can also find approximate formulas for the -3dB cutoff frequency of the IIR filter, but if you're not thinking in those terms I doubt it will be helpful.

The two approaches can be combined, and you can certainly use more sophisticated filtering techniques but the above may be enough. Here is a paper that describes moving average filters, for example. The rabbit hole is deep on signal processing.

• You might want to wait a bit longer (say 24h) before choosing an answer. Picking an answer early discourages additional answers, which could be better. You can un-pick. Commented May 11, 2023 at 14:16