Professional Documents
Culture Documents
Author Message
Code:
#PRIORITY TIMER1,RA
if(--int_count==0) {
++minutes;
int_count = INTS_PER_MINUTE;
}
if (minutes==2) {
output_high(pin_a5);
// delay_ms(1000);
// output_low(pin_a5);
}
}
#INT_RA
void porta_change_isr()
{
delay_us(250);
if (!input(PIN_A4)) {
disable_interrupts(INT_TIMER1);
output_low(pin_a5); // Red LED
}
if (input(PIN_A4)) {
int_count = INTS_PER_MINUTE;
minutes = 0;
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(0);
1 от 4 01.3.2007 г. 09:55
CCS :: View topic - Enable Timer1 interrupt in another ISR? http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...
enable_interrupts(INT_TIMER1);
output_high(pin_a5); // Red LED
}
#use fast_io(a)
input_a(); // dummy read
}
I can get in an out of the RA ISR. The LED on pin_a5 goes on and off. However Timer1 does not
seem to be running, and I never get into the Timer1 ISR (I.e. the debug LED on pin_a3 never
goes on)
BR. //Arno
What PIC are you using, and what's your compiler version ?
Joined: 06 Sep 2003
Posts: 6775
Can you post a main() function, with all of your setup code for the
Joined: 06 Sep 2003
Posts: 6775 timer, and the port i/o pins, comparators, etc., ?
In other words, I want to drop the code into MPLAB and have it compile
with no errors. Then I can look at it.
2 от 4 01.3.2007 г. 09:55
CCS :: View topic - Enable Timer1 interrupt in another ISR? http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...
Well... it would help if I would select a port for the debug LED that actually can be used as an
Joined: 29 Aug 2005
Posts: 9 output. RA3 isn't one of those.
I swapped RA3 and RA4 and now everything is working fine.
I still have one question. Do I explicitely need to clear the interrupt flags, or does the compiler
take care of that for me?
I now have some clear_interrupt() statements in the ISR as shown below. Are those really
needed?
Code:
#INT_RA
void porta_change_isr()
{
delay_ms(200);
if (!input(PIN_A3)) {
disable_interrupts(INT_TIMER1);
output_low(pin_a5); // Red LED
}
if (input(PIN_A3)) {
int_count = INTS_PER_MINUTE;
minutes = 0;
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
set_timer1(0);
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
output_high(pin_a5); // Red LED
}
clear_interrupt(INT_RA);
}
Clearing the interrupt is absolutely required. The compiler doesn't take care of that for you. If a
Joined: 24 Jun 2004
Posts: 557 timer is enabled, it will set its overflow flag when it overflows regardless of whether its interrupt
Location: Edmonton AB is enabled.
Canada
Whoops - have to clarify. If you enable the timer interrupt, you must clear any outstanding
timer interrupts. As PCM has said, no need to clear the other one - the compiler does that
automatically.
Last edited by newguy on Fri Sep 29, 2006 3:19 pm; edited 1 time in total
You don't need to clear the RA interrupt flag at the end of the isr.
Joined: 06 Sep 2003
Posts: 6775 The compiler automatically puts in a line of ASM code to do that for you.
See the lines shown in bold below.
Quote:
.................... }
.................... clear_interrupt(INT_RA);
0088: BCF 0B.0.................... }
....................
....................
0089: BCF 0B.0
008A: BCF 0A.3
008B: GOTO 02B
You can turn on/off a timer from anywhere in your code, including an ISR. Simply set/clear the
Joined: 23 Sep 2003
Posts: 430 bit that enables the timer.
Location: Utah
Ronald
3 от 4 01.3.2007 г. 09:55
CCS :: View topic - Enable Timer1 interrupt in another ISR? http://ccsinfo.com/forum/viewtopic.php?t=28343&highlight=inte...
pe1icq wrote:
Joined: 08 Sep 2003
Posts: 1104 Do I explicitely need to clear the interrupt flags, or does the compiler take care of that for
Location: Houston me?
Code:
set_timer1(0);
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
If you dont clear the interupt flag before enabeling the interupt it might jump to the timer 1
interupt routine as soon as it leaves the RA interupt.
Page 1 of 1
4 от 4 01.3.2007 г. 09:55