Has anyone written code to read an automotive tach signal?
turbosupra
Posts: 1,088
I believe my tach signal is low side pulses per minute. I'd like to see someones prop code if they don't mind sharing.
Did you have to do anything on the hardware side? I'd theorize that the prop could handle the pulses per minute without additional hardware, maybe sans a pull up resistor?
Did you have to do anything on the hardware side? I'd theorize that the prop could handle the pulses per minute without additional hardware, maybe sans a pull up resistor?
Comments
Initially I tried a simple high value series resistor (100K) directly into a port pin. This works ok at idle, but as soon as the revs come up and the voltage starts to creep up (I get 2V p-p at idle and 40v p-p at redline) things go haywire. I've borrowed a portable cro now and I'm going to have a crack at it again on Boxing day to see if I can add some "simple" passive external conditioning to calm it down. If that fails I'll have to built a zero crossing detector and some hysteresis to really clean it up.
Anyway, the code is probably no good to you, but all I'm doing is timing 8 input cycles by using a waitpeq/waitpne loop in a separate cog. That cog writes the timed period to the hub and some spin code converts it to RPM. It's pretty ugly and untidy.
I guess my point was you might want to look at some external signal conditioning. I'm thinking a simple low pass filter at the moment using an RC network, but I'll see how the next test pans out. It'd be easier if I could just walk to the car in the driveway and do the tests [noparse];)[/noparse]
<edit> forgot the code
the extra delays in there help it settle, but it still bounces and false triggers at high rpm so I need to try something else. This is the code for the Cummins, so it gives me RPM for 2 pulses per cycle.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
Ants
Do you think a transistor could switch fast enough to keep up with the vr sensor pulses, to deal with my voltage issue? Maybe an optocoupler on a circuit with a 3v source and pull down resistor?
I'll really have to think about how to code for what you suggested with predicted pulse time, I thought it would be as easy as measuring tickets per second [noparse]:([/noparse]
I was planning on using a cog counter in the Positive (or Negative) Edge mode, so I can do other tasks with the cog at the same time. I am not sure of the hardware to safely interface a either 5v or 12v signal to the prop. I was looking at what they use for Megasquirt, and it was an optoisolator, but I am not sure of the reasoning behind a optoisolator versus a transistor between the signal and prop
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
@ry.david, there's a sticky thread or an app note that details interfacing 5/12 to the prop with several methods. I'm pretty sure the MS' opto helps keep the coil flyback voltage/ringing from getting to the processor. Most Kettering coils produce a flyback of 1-300+ volts on the coil -, you really don't want that too near logic level components.
I'd love to see the sample code, when you have a chance, especially the logic behind it. Did you use an oscope to calculate the microseconds at idle and then go from there to build a reference table?
Revision 2
Would an optocoupler be a better choice, or is EMI not going to be a concern?
Post Edited (turbosupra) : 12/23/2009 8:40:03 PM GMT
Step1: usec/tooth*36 = usec/rev
Step 2: ((1000000/(usec/rev))*60) = rpm
Remember that the Prop has no hardware floating point capability for variables, everything has to be integer. Scale accordingly!
You could also use one of the floating point objects as well.
Your diagram needs to have the Zener between signal and ground, the resistor would be between the Zener and prop.
EMI's always a concern around internal combustion engines. Route wires intelligently, ground appropriately with shielded wire and see how it works.
Post Edited (pmrobert) : 12/23/2009 8:20:55 PM GMT
Thanks for the hint about floats, I did not know that
I haven't had any issue thus far.
In any case, if you have access to the ECU logic levels, the op amp will work.
Sorry for the confusion
Post Edited (Miner_with_a_PIC) : 12/24/2009 4:54:23 AM GMT
I tried this on the ECU for a Toyota 2AZ-FE from my daily driver.
Mine is for a 2zz, so I'd imagine whatever you did would work perfect for me, and if you don't mind sharing, I'd rather take the easier road, then the harder
Can we talk via email?
Since I expect to pick up on a generic NO ecu output, I had a similar circuit, but with a pull down resistor added. I didn't allow for a cap, but darn good point on that!
As for software, one way is a with a (semi) dedicated cog to time-stamp the edge. The loop looks like:
- set the counter in level detect mode to match HIGH level. Set the step to 1, and the phase to CNT.
- spare time, do speed calcs from last transition
- wait for pin LOW
- store the counter value
- set the counter in level detect mode to match LOW level. Set the step to 1, and the phase to CNT.
- spare time, do speed calcs from last transition
- wait for pin HIGH
- store the counter value
The trick is pre-loading the counter with CNT, and therafter it keeps counting up in lock step with CNT until the input changes.
I have code that does that, but has a mess of other stuff in there, such as calibratable odometer and start detection. Can post if wanted.
BTW if the tacho is not critical, you can monitor it on a round robin basis. I will probably do that as I just want a informational display of tacho and also injector duty cycle. The odo is critical, hence got a dedicated cog.
Post Edited (matb) : 12/24/2009 1:20:19 AM GMT
I would like to see your code if possible, just to see some example code of what you did, especially the syntax.
What it will do is clamp the max voltage to 3v3 and the voltage drop will be throught the 100K resistor which should not interfere with the existing circuit. A capacitor should not be required.
Why is the polarity of the zener reversed? The way you have it, the zener will always conduct when the input voltage is about 0.6V so you will never see a high. When a zerer is reverse biased, the zener will conduct whenever the voltage is above its voltage reference (3v3 in this case - a 2v7 would also be fine). When it conducts, the current it passes causes a voltage drop on the resistor.
Why is it on the prop side? In the above I showed the 100K resistor (could probably use a 1M also) is used to drop the voltage. This protects the prop and does not (should not because of the high resistance) interfere with the existing circuit.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
MOORE'S LAW: The capabilities of electronics shall double every 18 months.
cloyd's corollary: Hardware is easy, software is hard.
As usual, code needs more cleanup.
@Matb, thanks so much for the code, now to try and institute it, since my car is a 4 stroke coil on plug (no waste spark) I may have to have it read something every 2 revolutions, correct?
And the consensus is that this is the best setup for my voltage follower?
1) The tach signal is insufficient to drive the LED in the optocoupler
2) No current limiter for the LED in the optocoupler
3) Optocoupler output transistor is inserted in the opposite polarity
See attached image for suggested fixes...the 100k value probably needs some experimentation. Please note that the signal at the pin is expected to be inverted in the attached schematic (i.e. pin high with no signal and low when signal pulse is applied to tach input). Simple changes to software could correct for this.
Incidentally does anyone know what to do with the dangling base on the optocoupler output?
I didn't look too closely at the second circuit as I was unsure what its purpose was.