Author Topic: Smoothing an LCD readout  (Read 3717 times)

0 Members and 1 Guest are viewing this topic.

Offline brainwashTopic starter

  • Frequent Contributor
  • **
  • Posts: 463
  • Country: de
    • Hack Correlation
Smoothing an LCD readout
« on: July 07, 2013, 12:23:06 pm »
I'm trying to display a voltage but it varies quite widely. I do have an bar graph in place but I'm trying to find out the best approach for the digital one.
I went with the old approach of x= (255*x+y)/256 but it settles VERY slowly near the final voltage. I tried other coefficients and what works best for responsivity is 9&10, but I lose a lot of precision (around 2-3 bits). I'm working with 12bit samples (4096 value) and I would like to avoid buffers if possible.
The above formula AFAIK is a single pole low pass filter.

Is there any other way to achieve something like a voltmeter display? I'm targeting 200ms rise/decay time and settling within 1 or 2 seconds. I'm doing measurements every 5ms and display every 200ms.

I'm sure some of you have done this before so maybe you have a 'recommended choice'.
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4698
  • Country: au
  • Question Everything... Except This Statement
Re: Smoothing an LCD readout
« Reply #1 on: July 07, 2013, 12:40:08 pm »
as far as readable numbers go, while experimenting with my own project, i found any more than 4 updates a second got hard to define the full readings, with 3.2 being about the ideal for updates and readability,

as far as the bar graph goes, depending on how fast you can update your display, keep it to about a max of 10 updates a second, so probably average over those 100ms, and if you have the option probably have min and max markers, so an oscillation is clear,
 

Offline brainwashTopic starter

  • Frequent Contributor
  • **
  • Posts: 463
  • Country: de
    • Hack Correlation
Re: Smoothing an LCD readout
« Reply #2 on: July 07, 2013, 01:13:53 pm »
No, the bargraph updates when the display is drawn, so each 100-200ms.
The problem is that the numbers jump up and down because the ADC is picking up the peaks from PWM switching. I could add a capacitor in the divider to smooth it out but I thought that maybe there is a software solution for this.
I'm displaying 3 digits after decimal for <10V and two for >10V. Worst case I just give up the last digit (milivolts) since it's pretty close to the noise floor. The other option would be to go with a big buffer and do the weighted or boxcar averaging.

I'm just asking if anyone has done a digital voltmeter (or similar) and what values they have used. Except batteries everything real-world is producing noise in the readouts.
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16362
  • Country: za
Re: Smoothing an LCD readout
« Reply #3 on: July 07, 2013, 02:24:46 pm »
Add 4 samples in unsigned binary and then do a right shift twice to divide by 4. This reduces the jitter a lot.
 

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 252
  • Country: nl
Re: Smoothing an LCD readout
« Reply #4 on: July 07, 2013, 04:29:27 pm »
(...)
The problem is that the numbers jump up and down because the ADC is picking up the peaks from PWM switching. I could add a capacitor in the divider to smooth it out but I thought that maybe there is a software solution for this.
(...)
Except batteries everything real-world is producing noise in the readouts.
That's why good hardware design is important. Do you have a hardware low pass filter in front of the ADC at all? If not start reading on Sampling theory, anti-aliasing and Nyquist and why that a simple RC low pass filter is an absolute must before going into an ADC. (Analog Devices has a chapter on that in their Data Converter Handbook, free downloadable at their website)

Next; you want to solve in software what is probably mostly a hardware problem. IMO that's completely the wrong way of thinking. Noise management is first and foremost a hardware design case. Minimize the noise going into the digital domain, and only then decide what extra filtering in software is needed. So please put that capacitor in place before going along with a software solution.

 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13892
  • Country: gb
    • Mike's Electric Stuff
Re: Smoothing an LCD readout
« Reply #5 on: July 07, 2013, 05:00:54 pm »
I went with the old approach of x= (255*x+y)/256 but it settles VERY slowly near the final voltage.
A fixed moving avarage will settle more quickly - e.g. the avarage last 4 or 8 samples
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Smoothing an LCD readout
« Reply #6 on: July 07, 2013, 06:05:05 pm »
I sometimes use a non-linear approach to try and combine the effects of a stable display when the input has settled, but retaining the ability to react quickly to sudden changes in input.

If the input isn't changing rapidly, then I use a moving average as Mike suggests. Store however many numbers you want to average in a table, then whenever you take a new reading, pick the next slot in the table, subtract the figure that's there from your running total, and add the new sample. Keeping a running total and adding/subtracting from it saves having to add up the contents of your table every time, so you can have a table limited only by memory size rather than CPU speed.

If, however, you sample an input which is radically different from your displayed figure, then rather than just adding it to your table and letting it get averaged away, clear the table entirely and 'seed' it by filling it up with copies of the figure you've just sampled. Discard your running total figure as well, of course, and re-compute it by multiplication.

Depending on how your system responds, you might be able to add some additional cleverness. For example, don't 'seed' the table until you've seen two results in a row, both of which are similar to each other but significantly different from the running average.

Offline brainwashTopic starter

  • Frequent Contributor
  • **
  • Posts: 463
  • Country: de
    • Hack Correlation
Re: Smoothing an LCD readout
« Reply #7 on: July 07, 2013, 06:13:07 pm »
Some details: I'm using the LM4F processor from TI - it has an integrated FPU and hardware averaging (2x-64x) so I can afford to do fancy stuff. This thing samples just near the PSU output caps so it's probably smooth enough. I'm making this for myself, I know adding a cap or hardware filters would smooth out stuff but I want to try stuff.
In parallel I'm also doing some graphing of the data and making decisions, so I need a real-time sample. I could use a second ADC input with the hardware filtering applied but I'm already sampling 4 values.

Thank you for the moving average suggestion, I guess the 1-pole LPF filter is really more suited for changing signals.

I could 'lie' on the display and use the real-time stuff for OVC/OVP (protection) but I would like it to settle just like my meter does: 5.004V. So I also want repeatability.
 

Offline brainwashTopic starter

  • Frequent Contributor
  • **
  • Posts: 463
  • Country: de
    • Hack Correlation
Re: Smoothing an LCD readout
« Reply #8 on: July 07, 2013, 07:42:32 pm »
I'm attaching an Excel file I'm playing with, maybe it will be useful for someone else as well.
I'm targeting 50-100mV of noise (the scope says 40mV PkPk), it seems that the weighted average gives the best response
Edit: In the picture the amp connections are floating, ignore that
« Last Edit: July 07, 2013, 07:47:20 pm by brainwash »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf