Arduino Interrupt pins problem

Two things occur to me regarding the programs in Reply #18

in your first program this line is bad practice

        isrCount=0;                                       //####

Because isrCount is a 4-byte variable there is a risk that one of the bytes will be changed by the ISR while you are trying to set it to 0. You should update it with interrupts supended - like this

       isrCount = 0;

However, IMHO, there is nothing to be gained by setting the number back to 0.

And in the second program I would not have this line

          if(millis() - lastMillis>=1000){

inside the section of code where interrupts are disabled. You should ensure the interrupts are disabled for the shortest possible time.

Without trying your program (which I don't have time to do) I can't understand why it makes a difference which interrupt pin is used, although I assume the two pins have different priorities if you study the Atmega 328 datasheet closely. (It's a good read at bedtime :) )


I assume the two pins have different priorities

Dear Robin,

I am very thankful for your time and advices. Maybe this is the answare of my question. I just wondered about the difference between two pins with the same code. I will read closely the datasheet later to know more about it.

And yes, you are right about those two lines. However, it was a sample to show the difference.