View previous topic :: View next topic |
Author |
Message |
seed_87
Joined: 13 Oct 2013 Posts: 2
|
Using timer0 and timer1's interruptions in the same code |
Posted: Sun Oct 13, 2013 2:16 pm |
|
|
Hi!
Can it be done? What would be the downside of that?
I'd imagine if the PIC called one of the isr (lets say timer1's isr) then it wouldnt interrupt that isr in order to call timer0's isr, right?
In any case, would you still do it?
Something like (btw, using PIC16F887):
Code: |
void main()
{
//Configuracion timer0 - RTCC
setup_timer_0( RTCC_INTERNAL | RTCC_DIV_64);
set_timer0(0);
enable_interrupts(INT_RTCC);
//Configuracion timer1
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(0);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
}
#int_rtcc
void timer0_isr()
{
}
#INT_TIMER1
void clock_isr()
{
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Oct 13, 2013 2:49 pm |
|
|
Yes
Quote: | What would be the downside of that? | Depends on the PIC.
With PIC16's you have to wait for one ISR to finish before the other can run.
With PIC18s you get two priorities. The higher level can interrupt the lower level.
Quote: | In any case, would you still do it? | Of course, with the usual caveats.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
seed_87
Joined: 13 Oct 2013 Posts: 2
|
|
Posted: Sun Oct 13, 2013 5:49 pm |
|
|
Oh, i see..
Many thanks mike!! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19384
|
|
Posted: Mon Oct 14, 2013 1:01 am |
|
|
and (of course) the 'having to wait', shouldn't matter, provided you repeat the mantra (and use it), of 'keep the handlers short'. If the handler just does the job required (read a time, increment a counter, etc. etc.), and exits immediately, the second handler will then be called with only a tiny delay.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|