Time to excute command

Hello everyone,

In one of my project, I am using interrupt and my microcontroller is Arduino Pro mini (5V, 16MHz) ATMega328. I am using both interrupts. Under each interrupt I am calling a function like following:

detachInterrupt(0);

A_SIG=1;

B_SIG=digitalRead(PinB); // PinB is another interrupt pin

if(B_SIG==0){

pulses++;

}

if(B_SIG==1){

pulses–;

}

attachInterrupt(0,A_FALL, FALLING);

I am interested if I can find how much time microcontroller will take to execute this part of the program. Because I have a feeling while executing this part of the program another interrupt happens and micrcontroller can not detect it. So, basically missing interrupts.

Thanks in advance if you can help.

Post ALL of your code, using code tags.

You don’t need the detach and attach functions if you are using interrupts 0 and 1.

If you want to continue using attach and detach, the rest takes certainly less than 1 microsecond, but could be coded more efficiently, like this:

if (digitalRead(PinB)) pulses--;
else pulses++;

or (much faster) read the interrupt pin by direct port access, assuming that PinB is INT1, PD3:

if (PIND & 8) pulses--; //if PORTD, pin 3 is high
else pulses++;

To see how long a bit of code takes, set a pin high just before the code in question and set it low right after. Then you can use a scope to see the width of the pulse.

Wonderful, thank you both.