Search code examples
microcontroller

Static variables inside interrupts


When working with a microcontroller such as a PIC32MZ is it acceptable to use static variables inside the interrupt? This would be for a time counter. If the interrupt triggers every one msecond and a flag is needed every second.

Also is it necessary to make this variable volatile or its existence inside the interrupt makes it volatile?


Solution

  • Yes static inside the interrupt routine is not a problem.

    Volatile is not required in my opinion because you only access the variable from the isr function.