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.

Details about the project:

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);


enter image description here

  • 2
    \$\begingroup\$ 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? \$\endgroup\$
    – LordTeddy
    Commented May 11, 2023 at 13:02
  • 2
    \$\begingroup\$ 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) \$\endgroup\$
    – user16324
    Commented May 11, 2023 at 13:10
  • 2
    \$\begingroup\$ I think you're looking for a digital low pass filter on your ADC, how is your ADC value stored ? \$\endgroup\$
    – pm101
    Commented May 11, 2023 at 13:10
  • 1
    \$\begingroup\$ look up cascaded integrator comb (CIC) aka Hogenhaur filter. It's a very efficient moving average filter, ie very suitable for MCU implementation \$\endgroup\$
    – Neil_UK
    Commented May 11, 2023 at 13:13
  • 3
    \$\begingroup\$ 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. \$\endgroup\$
    – AnalogKid
    Commented May 11, 2023 at 13:18

1 Answer 1


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.

  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented May 11, 2023 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.