Beginner PIC tachometer project

Thread Starter

Howesy

Joined Mar 28, 2008
4
Hi,

I'm a beginner in electronics and have started playing around with PIC's. I'd like to start a project to complement my motorcycling hobby. I'd like to monitor the engine speed of my bike and record the peak rpm and average.

The tacho on my bike is controlled from the ecu which outputs a 10.5v square wave. My understanding is that this is at too high a voltage to be connected directly to a PIC which operates at 5v max.

Can anyhow explain the electronics I'd need between the ecu output and the PIC (a diagram would help!).

FYI. My bike is a Honda CBR1000RR and the PIC I'm using is a PIC18F4520.

Regards.
 

Søren

Joined Sep 2, 2006
472
Hi,


The tacho on my bike is controlled from the ecu which outputs a 10.5v square wave. My understanding is that this is at too high a voltage to be connected directly to a PIC which operates at 5v max.

Can anyhow explain the electronics I'd need between the ecu output and the PIC (a diagram would help!).
From the tacho output to the PIC I/O put a resistor of around 10k to 50k and put a zener diode (Vz = 4.7V to 4.9V) between the same PIC pin and ground (V_ss on the PIC) anode towards the PIC pin.

A diagram seems a bit overkill for 2 simple 2-terminal components ;)
 

SgtWookie

Joined Jul 17, 2007
22,230
A 10k resistor will allow just 1.05mA of current through itself with a 10.5v signal. That actually might be close to the maximum resistance limit for this application. I don't know how much current the PIC needs to see as an input signal, and in particular what the input capacitance is, which should be in the PIC's datasheet.

At low RPM's, the input capacitance will have a negligble impact, but at high RPM the RC time constant may be cause for concern. The Zener diode itself has some capacitance, which must also be taken into account.

See the attached circuit diagram and simulated O-scope trace. Soeren's proposed circuit is on the right. The output from his circuit is the green trace below. The slow fall time may be cause for concern if your PIC does not have Schmitt inputs, as it may cause unwanted oscillations and resultant heating. Usually, you want such signals to have very short rise and fall times.

I threw together the circuit on the left.
R1 limits the input current through the base of Q1 to under 1mA. R1 could actually be increased to 50k Ohms without impacting the output.
Q1 amplifies the current supplied via R1.
R2 limits current through Q1's collector to approximately 10mA.
C1 is a bypass capacitor; it ensures a steady supply of current for R2.
When Q1's collector voltage rises to 4.7, D1 acts as a shunt limiter to prevent the voltage from rising further.
The output signal (the yellow trace) is inverted from the original tach signal, but this should not present a problem. You'll see that the rise and fall times are much shorter than the simple resistor/Zener combination.
 

Attachments

Nomad

Joined Oct 21, 2007
43
most pic applications i've seen call for 4.7k or 10k as pull ups. the weak internal pull ups are 100k. I would lose the zener all together. use either a simple 2 resistor voltage divider, or the Sgt Wookie's circuit with the collector resistor r2 changed to 4.7k and going to the pics 5v supply instead of the vehicles 12v. no zener needed. nor the cap for that matter as your 5v supply should already have filtering caps, along with one or more at the pic itself.
 

SgtWookie

Joined Jul 17, 2007
22,230
Nomad's 2nd suggestion sounds better - that of losing the Zener and using the transistor with a 1k Ohm resistor to the PIC's power supply. A 1k pull-up resistor on the collector will limit maximum collector current to 5mA. Eliminating the Zener also removes it's capacitance, which will result in shorter rise and fall times and a more "square" input signal.
 

Søren

Joined Sep 2, 2006
472
Hi,

[...] I don't know how much current the PIC needs to see as an input signal,[...]
But still you choose to (wrongly) assume that there's a problem?


[...] at high RPM the RC time constant may be cause for concern.
No it won't. One thing is your blind faith in sims (which is cause for concern), but your total lack of a link to reality is even worse - you're indicating that a fall time of slightly above 2µs should present a problem in automotive ignition timing.


See the attached circuit diagram and simulated O-scope trace. Soeren's proposed circuit is on the right. The output from his circuit is the green trace below. The slow fall time [..]
Time for yet a reality check - I seriously doubt that Howesy's Honda turns 4.800.000 (4.8 million) RPM as you seem to believe - however it might be equipped ;)


[...] cause for concern if your PIC does not have Schmitt inputs, as it may cause unwanted oscillations and resultant heating.
See, if you had some experience with PIC's, you would know. You are inventing problems that just aren't there, I really wonder why and what you're trying to prove.


[...] Usually, you want such signals to have very short rise and fall times.
Really? So what I have learned during decades of involvement with automotive ignitions for high power motors, about the very transient ridden automotive electrical environment has suddenly changed?

In short: Don't use sims since they only really work well inside the fairy tale environment it creates. Don't use sims with data so far from real life specs. And finally... Get to know both PIC's, the problems with designing for the automotive environment and some sensible tutoring on engine RPM before you invent problems that isn't there and try to solve them with an overengineered circuit that has no transient dampening.
Or to put it even shorter: Keep your advice to something that you are knowledgable about, whatever that might be.

A simple voltage divider will be quite problematic as well, as the PIC will most likely commit seppuko on the first load dump transient it sees.
If any changes should be made to the no-nonsense resistor/zener circuit at all, it should be adding a slight bit of capacitance parallel to the zener.
 

thingmaker3

Joined May 16, 2005
5,083
Debate is encouraged here. Confrontation is not. Let's keep the discussion on the circuitry. Confine attitudes and personal jabs to other websites - we don't do those here.
 

Thread Starter

Howesy

Joined Mar 28, 2008
4
I've given the circuit a try (10K Resisitor and 4.7v Zener) and had no joy. With the resistor inline no pulses are recorded. If I bypass the resisitor then I get pulses being counted but it stops the tacho on my bike working.

Is there anyway around it?
 

SgtWookie

Joined Jul 17, 2007
22,230
Oops! You MUST use a resistor to limit the current. Otherwise, the Zener will forcibly clamp the ECU tach output signal to 4.7v, which may either damage the Zener or the ECU tach signal output circuit.

Let's try Nomad's recommendation.

See the attached; the leftmost circuit is an adaptation of his recommendation. The base current limiter (R2) has been increased to 47K so that current draw on the ECU is minimal. However, the output signal is inverted from the input signal (see the green trace on the simulated O-scope)

The circuit in the middle preserves the polarity of the input signal. This may or may not be important. The base resistor is 10k because the current demands are less, due to the emitter load resistor. Note that this signal has faster rise/fall times than the first one.

The item on the right is just a simulation of your ECU producing a 0V/10.5V pulse at 10kHz.
 

Attachments

SgtWookie

Joined Jul 17, 2007
22,230
After some more testing with simulated loads, the middle circuit is much more promising than the leftmost one.

The blue waveform (A) is a simulation of Soreone's circuit (bottom center) with a simulated load of just over 1mA, with some capacitance added in for good measure. The capacitance is likely smaller than what is actually in your circuit, due to parasitics from the run length of the wiring. If the input on your PIC is a Schmitt trigger, the voltage would be insufficient for triggering; 3.33v would be required.

The yellow waveform (B) is from Nomad's suggested modification of the first circuit I'd put up (on the left). It was necessary to increase the base resistor to keep the current draw from the ECU tach output circuit low. The response is significantly better than the circuit you are currently using and better than my initial suggestion, however it still can be improved upon; as the output is barely over the Schmitt trigger requirement.

The green waveform (C) is a variation on the same theme (top center). You'll note that the output waveform swings from rail to rail, and the rise/fall times are better than either of the previous circuits.

As far as my background - well, my projects have historically been a bit higher performance than automobiles, like this one:


I was involved in the YF-22 project from the early years back in the 80's - and every single circuit in the avionics suite was simulated using SPICE, using a now-archaic Dartmouth Time Sharing System.

I find Soreone's lack of faith disturbing...
 

Attachments

Thread Starter

Howesy

Joined Mar 28, 2008
4
Thanks for your help again. I'm pretty new to this (as you can probably tell). I was also intending to use this on my friends bike. I'm not sure of his bike's output spec but would this circuit work on any signal output between 5v - 12v?
 

SgtWookie

Joined Jul 17, 2007
22,230
The upper center schematic (R3, Q2, R4, output C) will work from 12v down to 5.9V providing a swing from 0v to a minimum of 4.85v with the load shown.

With a 5v ECU tach signal, the output from the same circuit will be 4.19v - still plenty high enough to ensure a logic 1 is present on the uC's input.

Even Nomad's modification of my original circuit would continue to work, at 4.1v maximum output.

Soreone's resistor/Zener combination would provide less than 1.6v, and would continue to not function as desired.
 

Cas

Joined May 9, 2008
2
I'm about to start a project on bikes and will collect some waveforms for a number of bikes - so then you should be able to come up with a final solution to measure your signals/RPM. I have a similar problem and can hopefully help to some degree as I am about to get some equipment to measure ignition waveforms - I have an experienced autoelectrician from the local AA that is also helping me on this. I have difficulty in reading the last png files . I have done some measurements on cars and most of them have different waveshapes which was confirmed by the autoelectrician.
 

Digi Dave

Joined Apr 25, 2008
26
The output from your ecu is a square wave at 10.5v so it will probably be a variable frequency output IE when you rev the bike the "frequency" of the signal will increase and not the voltage, so you will need a Frequency to Voltage convertor.( just like what your rev counter is doing!!!)
 

Cas

Joined May 9, 2008
2
I would be carefull in making any assumption on the voltage that reaches the ECU. In most cases these voltages for the tachometer /RPM from the ignition are directly from the secondary side of a coil which voltages are in the order of 10KV ! In the case of motorcycles it could be even more...the safest is to find a full circuit diagram and determine what is the source that reaches the ECU. The other problem is that the actual signal is actually very slow in frequency ...which could be be in the ballpark figure of 50 to 200Hz with very high peaks that are difficult to see on old analog scopes as you won't see the details of the very high peaks -if that is true in your case.(the same slow frequency case if you tap on the speed) You need a good digital scope in such a case with a high voltage inductive probe- my guess is something like the fluke RPM80 probe but I'm not so sure on bikes as the RPM/frequency is a higher then car. Your PIC is bound to die if this is a high voltage that is provided to it. The wave shapes are not cast in stone and can differ from one to next automotive solution. Be carefull in some a case to use automotive multimeter cause the bike might have a higher RPM that can't be measured -to measure is to know.

If you are not sure how to calculate the sums on RPM, I'll give the formulas but the only message is that it (the signal) is very slow in comparision with other electronics.

If the voltage has been successfully converted to a safe voltage (+correct shape - which is the magic/trick) within the PIC power supply range, then one can actually directly feed it into the PIC and use a program that measure the frequency for you - the pic is much faster then this. I've know a number of ways in software by using usually an interrupt-counter type routine -if that is the only thing you want to measure. I do not use the PIC currently but I can do one of number of flow charts.
 
Top