Thanks everyone for the help. I really appreciate it. I'll try to answer all the replies.
PaulS:
So, how is this an analog signal? The voltage is either high to trigger the coil or low. Sounds digital to me. Now, there is a ramp up and a ramp down, but the signal is basically a square wave, not a sine wave.
Well I could try treating it like a digital signal. I tried triggering the interrupt by LOW instead of FALLING, but it didn't work. It never gave me any output. When I changed it to FALLING, it worked, except for that extra triggers.
PaulS:
If you are getting more than one interrupt per spike, then you need to debounce the signal. That is, you ignore a second interrupt if it occurs too close after the previous one. To do that, you record when the interrupt is triggered, after copying the last time (which might be 0) to the previous time variable.
unsigned long currTime;
unsigned long lastTime;
void spark()
{
lastTime = currTime;
currTime = micros();
if(currTime - lastTime > longEnough)
{
// Count this pulse
}
}
I could try that. I didn't know how to write it out. I think it should work if I work find a good amount of time that would be long enough to get rid of the extra interrupts, but short enough to not ignore actual pulses.
Sembazuru:
You should probably find out some details about that pulse before connecting it to your Arduino and/or developing a sensing algorithm. For example, what are the voltages going to be? If you look at the voltage scale of the picture you linked to (yes, I know it isn't your signal), you see that it goes to 15kV (that is 15,000V). A signal that large is guaranteed to let out the magic smoke somewhere on your Arduino.
Find a friendly shop or friend who can actually put some sort of scope on your engine to find out what the signal will look like. Design a circuit to safely get that signal (and possibly shape it or clean it up) to your Arduino, and then decide how to write a program to count the pulses. If the engine is modern enough, you might be able to actually get a TTL-style pulse out of the on-board computer, or even a decoded tach reading. (I'm not that familiar with OBD protocols so I can't help you beyond pointing you in that direction.)
Yeah I'm not hooking it up to a spark plug wire. My coil is actually supposed to output 45,000 volts to the spark plugs rather than 15,000. But I'm connecting it to the negative side of the coil. I measured it and it only has around 14 volts at any given time. I used a voltage divider circuit so that if I get 20 volts input, the Arduino will only see 5 volts max.
TanHadron:
What does your hardware connection look like? How are you conditioning the signal so that it will trigger the interrupt?
I'm just connecting a wire from the negative side of the coil to a voltage divider circuit to the Arduino.
PeterH:
That's a recipe for a dead Arduino. There are all sorts of voltage transients coming off the coil LT circuit and you will need to buffer that signal down to TTL levels before it is safe to connect it to your Arduino. Having done that, a plain old digital read will be all you need to read it.
Well I hope not. What do you mean by a digital read?