View previous topic :: View next topic |
Author |
Message |
Freddie
Joined: 06 Sep 2003 Posts: 49
|
Interrupts |
Posted: Tue Oct 28, 2008 8:04 pm |
|
|
I'm trying to understand how interrupts work. Is there a good tutorial somewhere?
Question #1
To turn on the INT_TIMER1 is it better to do this:
Code: |
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
|
or this:
Code: |
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
|
Question #2
After the following code runs will INT_TIMER0 and INT_TIMER1 be enabled or do you have to reenable each one again separately?
Code: |
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
disable_interrupts(GLOBAL);
enable_interrupts(GLOBAL);
|
|
|
![](templates/subSilver/images/spacer.gif) |
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Tue Oct 28, 2008 9:44 pm |
|
|
Freddie,
I enable the individual interrupts first and then the global interrupt. So I use Code: | enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL); |
Disabling a particular peripheral interrupt bit has no effect on other bits or the global bit. Similarly, even when the global is disabled, the timer1 and timer0 remain enabled.
Rohit |
|
![](templates/subSilver/images/spacer.gif) |
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
Posted: Tue Oct 28, 2008 10:54 pm |
|
|
Also, having the interrupts disabled doesn't disable the interrupt flags - it only means they have no effect on program execution. You can still test, for example, the Timer0 interrupt flag (T0IF), even if global and Timer0 interrupts are disabled. Similarly, an interrupt can wake up the PIC from sleep even if global interrupts are disabled.
That comes in handy some times. |
|
![](templates/subSilver/images/spacer.gif) |
Freddie
Joined: 06 Sep 2003 Posts: 49
|
|
Posted: Wed Oct 29, 2008 4:43 pm |
|
|
Thanks. A few more questions...
Quote: |
Similarly, even when the global is disabled, the timer1 and timer0 remain enabled.
|
So what does enable_interrupts(GLOBAL) actually do then?
Quote: |
can still test, for example, the Timer0 interrupt flag (T0IF), even if global and Timer0 interrupts are disabled.
|
So if the interrupts are disabled, how do you clear the TMR0IF flag? |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Oct 29, 2008 5:29 pm |
|
|
enable_interrupts(GLOBAL) modifies the global interrupt bit in processor status register.
The methods to reset the interrupt flags are documented in detail in the hardware manuals. Some are reset implicitely, e. g. by reading a data register, others have to be reset explicitely. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 29, 2008 5:48 pm |
|
|
Quote: | So what does enable_interrupts(GLOBAL) actually do then? |
Download the 16F-series PIC Reference manual on interrupts:
http://ww1.microchip.com/downloads/en/DeviceDoc/31008a.pdf
Look at the interrupt logic schematic on page 4. The global enable
bit (GIE) is the last enable in the chain. It controls everything.
You can see this clearly in the schematic.
Quote: | So if the interrupts are disabled, how do you clear the TMR0IF flag? |
Look at the clear_interrupt() function in the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Also note that CCS puts in code at the end of the INT_TIMER0 interrupt
service routine to automatically clear that bit. You don't have to put in
code to do it. |
|
![](templates/subSilver/images/spacer.gif) |
|