detecting interrupt has happened?

AlainD

Well-known member
Hi

Is there a way to detect that an interrupt has happened?

Fasttouchread uses noInterrupts/interrupts, but can easily but run multiple times if an interrupt has occured.

I can run it twice to see if an intterupt has happened in one of those two runs, but a flag or "interrupt counter" would be nice.
 
Hi

Is there a way to detect that an interrupt has happened?

Fasttouchread uses noInterrupts/interrupts, but can easily but run multiple times if an interrupt has occured.

I can run it twice to see if an intterupt has happened in one of those two runs, but a flag or "interrupt counter" would be nice.

Any ISR or callback that you write yourself, or that you can modify, can include code to increment a counter. The processor itself does not count interrupts. What interrupt(s) do you want to count?
 
I was thinking of ISR's that I haven't written. Adding a count myself is easy ;-)

On the other hand I's read somewhere that an ISR (that does something) takes about 27 cycles, which makes detecting -for me in this application- rather easy.
 
I was thinking of ISR's that I haven't written. Adding a count myself is easy ;-)

On the other hand I's read somewhere that an ISR (that does something) takes about 27 cycles, which makes detecting -for me in this application- rather easy.

Hard to answer a question like this in a vacuum. Do you have a specific interrupt source in mind?
 
I was thinking of ISR's that I haven't written.
Of course you could always hook into any ISR by manipulating the vector table. Here an example (T4.0) showing how to intercept the systick ISR which is called every millisecond. The intercepting code simply increments a counter value and then calls the original ISR.

Code:
#include "Arduino.h"

typedef void (*ISR_t)();
ISR_t originalISR;

volatile uint32_t cnt;  // this is our "call counter"

void setup()
{
    originalISR     = _VectorsRam[15];               // store the address of the original ISR (here the systick ISR) ...
    _VectorsRam[15] = [] { cnt++;  originalISR(); }; // ...and replace by ours which will simply increment the counter and then call the original IRS
}
void loop()
{
    Serial.println(cnt); // print the counter value every 10ms
    delay(10);
}
which prints the expected:
Code:
647
657
667
677
687
697
707
717
727
737
747
757
767
777
787
797
807
817
827
 
Last edited:
Back
Top