CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Freddie



Joined: 06 Sep 2003
Posts: 49

View user's profile Send private message

Interrupts
PostPosted: Tue Oct 28, 2008 8:04 pm     Reply with quote

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);
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 28, 2008 9:44 pm     Reply with quote

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
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Oct 28, 2008 10:54 pm     Reply with quote

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.
Freddie



Joined: 06 Sep 2003
Posts: 49

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 4:43 pm     Reply with quote

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?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 5:29 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 5:48 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group