Author Topic: Recommend an input circuit for 3-12V square wave for freq. measuring using MCU  (Read 2075 times)

0 Members and 1 Guest are viewing this topic.

Offline Corporate666Topic starter

  • Supporter
  • ****
  • Posts: 2010
  • Country: us
  • Remember, you are unique, just like everybody else
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 :)

It's not always the most popular person who gets the job done.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10229
  • Country: nz
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 revision

The 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.
« Last Edit: May 17, 2013, 12:19:28 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline lewis

  • Frequent Contributor
  • **
  • Posts: 704
  • Country: gb
  • Nullius in verba
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.
I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf