At 05:59 PM 2/15/01 -0500, you wrote: >>In analog electronics, this could be done by low-pass filtering the >>signal, AC coupling it, and applying a zero-crossing detector with >>some hysteresis. You can do the same thing digitally, assuming >>the frequency isn't too high. > >This would require another input pin, however. No, I mean do it all with the same A/D values. Easy if you call the measurement routine with a fixed period (Ts). Just code two low pass filters (the first above the frequency of interest to get rid of the high frequency noise, the second cascaded filter below the frequency of interest to give the "AC coupling" offset (or you *may* be able to use a fixed value for this). Preload the second one so it starts up faster. Subtract the two filter outputs and you have a cleaned-up signal that has nice (hopefully) zero crossings. Look for the transition +Vth if the output is currently low, for -Vth if the output is currently high. You need to pick Vth, and the filter frequencies (and types if you don't use a simple first-order lag- but I'd try that first). Pick those things so it works reliably. ;-) Best regards, =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Spehro Pefhany --"it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu