View previous topic :: View next topic |
Author |
Message |
Guest
|
RTCC Issue |
Posted: Wed Nov 28, 2007 8:31 am |
|
|
I have a PIC16F877A that has a RTCC ISR that runs CONSTANTLY, no matter what I do. Nothing else in the program even gets a chance to respond.
I'm virtually certain that it's something to do with timer0 configuration and I know it's 8 bit (from the datasheet).
setup_timer0(RTCC_INTERNAL | RTCC_DIV_x);
x I've tried from 2 to 256, and with 8-bit it *shouldn't* even be running right? But it does and nothing else gets executed.
I've also seen in the forum where the compiler has to be explicitly told the timer0 is 8-bit and I've done so but still the same effect.
How would I check to ensure that the RTCC interrupt flag is being reset? I thought the compiler did that automatically.
#INT_RTCC
void pid_ISR()
{
disable_interrupts(GLOBAL);
disable_interrupts(INT_RTCC);
disable_interrupts(INT_RB);
.
.
.
set_timer0(0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RB);
}
#INT_RB
void counter_ISR()
// A "homemade" ISR to deal with only having only one counter.
{
int8 b;
b = input_b();
if (!(b & 0b10000000)) ++cur_r_enc;
if (!(b & 0b01000000)) ++cur_l_enc;
}
void Initialize(void)
{
set_tris_a(0b00001111); // This is for the analog inputs.
set_tris_b(0b11000000); // This is for our homemade timer.
set_tris_d(0b11111111);
setup_adc_ports(ALL_ANALOG); // Set up port A for analog input.
setup_adc(ADC_CLOCK_INTERNAL);
// Initially configure our RTCC
setup_timer_0(RTCC_DIV_128);
// Setup Timer 2
setup_timer_2(T2_DIV_BY_16, 0xC0, 1);
// Configure the PWM ports.
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
}
I've removed a lot of the code inside the RTCC handler. There really isn't that much. A Lot of the if statements were written to avoid constantly running compares and there is no floating point being done.
I also have another ISR for port B. That code works fine when it's in a stand-alone program so I'm pretty sure that's not the problem. Can't see how it could interfere with RTCC.
Inside the main() portion, it is only when I enable_interrupts() that the problems start.
Anyone have any thoughts? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 28, 2007 2:53 pm |
|
|
#INT_RTCC
void pid_ISR()
{
disable_interrupts(GLOBAL);
disable_interrupts(INT_RTCC);
disable_interrupts(INT_RB);
.
set_timer0(0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RB);
}
Don't enable/disable Global interrupts inside the isr. See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=31091&start=1 |
|
|
Guest
|
|
Posted: Wed Nov 28, 2007 3:16 pm |
|
|
What about preventing interruption of the ISR itself? How can one assure that it makes it all the way through before it is being called again? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 28, 2007 3:25 pm |
|
|
The 16F-series PICs automatically disable global interrupts in hardware
when they jump to the isr.
Download the 16F877A data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf
Look in section 14.11 on Interrupts.
It describes the behavior of the PIC when it enters an interrupt routine:
Quote: | When an interrupt is responded to, the GIE bit is
cleared to disable any further interrupt. |
And when it leaves the interrupt routine:
Quote: | The “return from interrupt” instruction, RETFIE, exits
the interrupt routine, as well as sets the GIE bit, which
re-enables interrupts. |
In other words, you don't have to touch the Global interrupts flag.
It's all handled for you by the PIC and the compiler. |
|
|
|