Alan B. Pearce wrote: > You are better off filtering the RA0 input. You may find that you need > to take two or three readings to get a stabilised value if you are > expecting things to happen fast, but I would have thought this is the > sort of use where the person keeps their finger on the button until the > desired action happens, so speed is not essential, so a longish (1/10 > to 1/4 sec?) time constant on the filter would be fine. I agree about the filtering, but not so sure that 250mS might not be annoying. I guess it depends on exactly what the user expects to happen. The tricky part of the filtering will be that the step response needs to be matched between the data signal and the supply reference, otherwise glitches will look like valid signals. This is why I would do only relatively fast filtering in analog, just to smooth out the nasty spikes and avoid aliasing in the A/D. Maybe a two pole filter on each signal that has a 90% step response around 5mS. Sample each A/D input as fast as possible, say one sample every 200uS (1000 instructions on 20MHz PIC). That means each signal is sampled every 400uS. Now do a digital filter on each signal with a 90% step response around 20-25mS. One pole shifting 4 bits and another shifting 3 bits comes out close enough. That gives you about a 93% step response in 50 iterations or 20mS. Since these final slower filters are digital, they will be exactly matched. Now that the filtered digital values are available, the code can come along every 1 or 2 mS and do the divide to recover the single value. It won't recognize a valid state until the resulting level has been within 5-10% of a valid level for 25mS. That will prevent triggering on intermediate states as the filtered values slew from one end to the other. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist