Recommend an input circuit for 3-12V square wave for freq. measuring using MCU - Page 1
Forum section: electronics / projects

author: Corporate666
author_rank: Unknown
timestamp: May 17, 2013, 06:21:44 am
content: I have a little diagnostic tool I am working on that will need to read engine RPM's. I'm not talking about right from the coil, but from the ECU - most ECU's have an engine speed output that is a 5V or 12V square wave. I guess some may be 3V too?Anyway, I took some readings on a scope from a couple of different cars around the shop and the square waves are somewhat ugly...Previously I have used something like a diode, then a resistor, then a reverse biased zener, then a small (maybe 100pF) cap to ground, into the base of an NPN transistor, and setting the MCU pin to pull up. The transistor pulling the pin to ground would seem to give me more variation in input voltage and give a nice crisp on/off transition for the MCU. But that's just a guesstimate.Anyone done something like this before and can recommend something? I'm guessing some decent filtering on the circuit power input is important too

author: Psi
author_rank: Super Contributor
timestamp: May 17, 2013, 08:45:37 am
content: I'm reading engine RPM for a project and haven't had any issues with the following.- The 22pf cap is for RF suppression- The 18V TVS is for transient protection above battery volts.- The 10k and 10nF serve two functions, they form an RC filter to smooth the pulses so they're easier to read on the mcu and the resistor limits the possible current into the mcu input.Note:For the make and model of car that this circuit was designed for the ECU RPM signals is always 0-5V.If you need the circuit to work for all types of RPM signals from 3V to 12V you will have to deal with 3.3V logic which will require more components if your MCU is 5V.You will also want a zener on the mcu input so 5V+ signals don't try and push the input above VCC(I will probably be adding a 4V zener to my circuit in the next revisionThe MCU code triggers an interrupt on the rising edge which stores the current count of a hardware timer.On the next rising edge interrupt the pulse length is calculated from the previous and current count. If the length is too short to be a real pulse its ignored.The pulse lengths are feed into a running average to smooth out any possible errors.Keep in mind that i'm not saying this circuit is the best solution, its just what i'm doing currently and haven't had an issues in the 50 or so cars i've used it on.

author: lewis
author_rank: Frequent Contributor
timestamp: May 17, 2013, 12:15:26 pm
content: If you micro has a comparator, you can feed the signal into the comparator pin with minimal interface circuitry. A 100K series resistor with a 4.7V zener down to ground (assuming 5V supply for the micro) will be sufficient. The comparator on some PICs can be connected internally to TMR1 in capture mode so you can easily measure duty cycle, pulse width etc. Also, the comparator can be configured with internal hysteresis to provide some noise immumity, or use the comparator output pin to provide some heavier external hysteresis. Ensure the PIC also has an internal DAC - you can configure the comparator voltage reference to be whatever you like.