On Tue, 14 Jun 2005, PicDude wrote: > Got a problem here with a PIC application where the lowest (rightmost) digit > of a numerical value is "toggling" back and forth between 2 (consecutive) > values rapidly -- example it will jump back and forth between 283 and 284 > rapidly (like 3-4 times a second, which is the update rate on the display). > better way -- is there? Not really. This problem is inherent with noise on A/D converters. You did a low pass filter with an override rule. It will solve the problem only for high frequency noise, as you seem to have. What you can do is take each two consecutive values and average them. This yields one extra bit of precision (at half the ad rate). The extra bit will 'toggle' as above but at half the speed. This is a basic low pass filter. You can extend this as you did to three or more samples. It depends on the type of noise you have. Overriding the low pass filter is not necessarily a good idea. For example if the signal is then used in a pid loop the 'extra' rule of changing the output immediately if it changes by more than 1 count is equivalent with extra (nonlinear) D gain in the pid loop. Then if you adjust the loop for correct coefficients for fast change it will have too low D for small changes and precision will not be good near the setpoint. taintstafl. The fix consists in allowing the noise into the pid and setting a deadband at the *output* of the pid in this case. Peter -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist