pdubinsky
Joined: 25 Nov 2005
Posts: 66
Location: South Carolina
|
|
Posted: 17 December 2009, 18:50 PM Post subject: ZX24N Interrupts |
|
|
Back some time ago, there was a discussion on a tachometer app in which someone suggested using a native mode 24N and an ISR routine to capture pulse timing. The discussion moved to InputCapture and never discussed using the interrupts again.
I'm curious, has anyone used the ISR routines in the 24N? Is there any practical difference between using the external interrupts as opposed to the pin change interrupts (other than the limited pins necessary for the the external interrupts)? Are variables used as storage in the ISR routine globally available to sub main?
TIA & Happy Holidays,
Paul |
|
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 17 December 2009, 19:24 PM Post subject: Re: ZX24N Interrupts |
|
|
| pdubinsky wrote: | | Is there any practical difference between using the external interrupts as opposed to the pin change interrupts[...]? | One difference is that with each external interrupt there is only possible interrupt source (unless you combine them using external hardware). In contrast, with a pin change interrupt there could be up to 8 possible sources of the interrupt depending on the pin change interrupt mask that you use. Multiple interrupt sources requires additional logic in your program to sort out which one (or more) of the sources triggered the interrupt.
| pdubinsky wrote: | | Are variables used as storage in the ISR routine globally available to sub main? | The visibility rules are identical to non-ISR procedures. That is, if you define a variable within a procedure (or ISR), that variable will not be visible from other procedures. In order to share data between an ISR and other procedures you must use module-level variables.
There are several issues to consider when sharing data between procedures. Firstly, for multi-byte variables (e.g. Integer, Long) you must enclose accesses to the variable in an Atomic block. This provides atomic access to the variable, guaranteeing that another procedure will not be allowed to run (possibly accessing the same data element) in the middle of the multi-byte access. Note, too, that read-modify-write operations on all variables (regardless of size) must be similarly protected.
Secondly, when an ISR shares data with other procedures you must define the variables with the Volatile attribute. This attribute tells the compiler that the variable can be modified at any time by and, therefore, the compiler cannot make certain optimizations. |
|