preventing an interrupt ?

i use an interrupt on a pin to increase a counter

the speed of the counts is very fast and sometimes the interrupt prevents the void loop from continuing

the void loop prints the output to the serial port

Qu - is it possible to stop the interrupt from breaking the print to the serial port


alternatively i have tried printing to the serial port inside the interrupt, this works fine. I also output the time since the board started

but when the frequency increases the millis() number stops counting and remains constant till the system slows down again

I am guessing calling millis() takes too long

Qu - is it possible to stop the interrupt from breaking the print to the serial port

Yes, you can disable and re-enable interrupts at any time. Generally a bad idea, but it's up to you. Use interrupts() and noInterrupts();

I am guessing calling millis() takes too long

Wrong. The call to millis() takes hardly any time at all. The Serial.print(), on the other hand, takes forever...

Rather than using an interrupt and software to increment a counter you might consider using one of the built-in timer-counters. I believe they can be driven by an external clock. Since the counting is done in hardware there is no software overhead. You would just read the register(s) to get the count. You can use the 16-bit timer/counter 1 to count up to 65535 or use the 8-bit timer/counter 2 to count up to 256. In either case you can have an interrupt signaled when the counter overflows so you can extend the count almost forever in software.

"Do it in software only if you can't do it in hardware." -Abraham Lincoln

"Do it in software only if you can't do it in hardware." -Abraham Lincoln

And here is me thinking that was a quote from Taft!