> For my next project, I want to initiate some action when my car exceeds > approximately 10mph. The "speedo" sensor is some kind of proximity > switch on the output end of the gearbox/diff. So, the output it a 12v > ish square wave, of frequency proportional to speed. My multimeter > measures the frequency at about 20 Hz at 10mph. > > So, to measure this frequency, my idea is to use the CCP, in capture > mode, with an appropriately prescaled timer. My Capture ISR will > increment a counter each time the CCP event fires, if the timer > represents a (period) shorter than 40ms (ie, faster), and, when the > counter gets to an appropriate number, perhaps 20 ish, I'll inititiate > the other code. Idea of using the counter is to filter out any bounces > or other muck in the line. > > Leading to my first question- does this plan seem like a workable idea? Yes, especially if this is a one off. If this is for volume production you can substitute the CCP module with is little clever software in a 12F629 (I've done exactly that to detect a boat engine speed above a pre-set threshold). > Secondly, is the question of how to interface the 12v square signal > with the pic? I'd thought of using an optoisolator, but is there a > better, or simpler way of protecting the pic from a) getting 12v not 5v > and b) any dirty spike type things? I think I need a relatvely high > impedance, because the signal goes into the ECU, so if I steal too much > of it, I may make the car rather ill. In automotive and similar environments, I like all signals coming in thru 100Kohm resistors whenever possible. A small capacitor afterward will filter some spikes, and clamping diodes can easily handle the rest. I would further detect this signal with a significant amount of hysterisis. If it's always a 0-12V signal, then scaling to 5V after the 100Kohm series resistor, a little capacitive filtering, then into a schmitt trigger input may be good enough. The toughest issue in an automotive environment is not the signals however, but the power. You need to tolerate 200V spikes that last a few milliseconds, several volts of noise continuously, and an average that fluctuates from 9 to 15V under normal conditions. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu