Hardware interrupt help

Hi folks, I am having difficulty getting my hardware interrupt to play nicely. I want to trigger my interrupt code just once per interrupt, but when i feed a signal to the arduino (the equivalent of one rising edge), I get a continuous loop of the interrupt sequence. How can i increment this to happen only once per interrupt event?

int sparkPin = 13;

void setup() { pinMode(sparkPin, OUTPUT); attachInterrupt(0, spark, RISING); }

void loop() { }

void spark() { digitalWrite(sparkPin, HIGH); delayMicroseconds(3200); digitalWrite(sparkPin, LOW); }

Try setting a global flag (declare it before void setup() ) within spark, if void sees the flag set disable the interrupt:

detachInterrupt(0);

Not sure the delay works inside the ISRs either. Gets discussed here a lot; pretty sure delay() doesn't, not sure about delayMicroseconds.

You can do a for:next loop to count up a bunch to use as a delay timer in the ISR.

hikerjohnson: Hi folks, I am having difficulty getting my hardware interrupt to play nicely. I want to trigger my interrupt code just once per interrupt, but when i feed a signal to the arduino (the equivalent of one rising edge), I get a continuous loop of the interrupt sequence. How can i increment this to happen only once per interrupt event?

What signal? How do you know this is happening?

CrossRoads: Not sure the delay works inside the ISRs either. Gets discussed here a lot; pretty sure delay() doesn't, not sure about delayMicroseconds.

delayMicroseconds is OK - it just does a counting loop.

when i feed a signal to the arduino

How are you doing this? Are you by any chance using a button or other hardware that needs debouncing?

This is the earliest stages of an electronic ignition for a motorcycle.

I am using a 2AV54 hall sensor as a pickup, and am triggering a BIP373 to get spark at my plugs. It's wasted spark so cam and crank synchronization isn't necessary.

Awhile back, I looked at the signal from the 2AV54 on a scope, and it looked pretty clean to me, but i threw on a high-pass filter anyways.

Because its for a very time-sensitive application, traditional "wait awhile" debouncing wont work, at least I do not think it will.

Eventually I will need to implement an RPM-based lookup table to give appropriate spark delays.

Now, I am very very weak on programming skill, but it seems to me that what I wrote ought to give me just one instance of spark per rising edge event. What happens instead is I just get continuous spark. The nature of a spark coil being what it is, this indicates that the BIP373 is triggering continuously as long as the interrupt pin is pulled high.

So, still looking for an answer.

Have you got some sort of measuring device, like an oscilloscope or logic analyzer? Without hooking it up to the transistor, or the spark plug, it would be interesting to see if the output line (pin 13) actually goes on, stays on for 3200 uS and then turns off again.

... I looked at the signal from the 2AV54 on a scope ...

Ah, I see you do. Well measure both the input (the pickup) and the output (pin 13) and check it is doing what it is supposed to. The sketch looks OK to me.

My suggestion is to have it flash a unique sequence (Or use Serial) when the arduino starts up (before attaching the interrupt) so you know it isn't resetting for some reason (brown-out, etc).

If you are not going to be doing anything in the main loop, you might as well put the code in there rather than the interrupt.