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

RTCC Issue

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








RTCC Issue
PostPosted: Wed Nov 28, 2007 8:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 28, 2007 2:53 pm     Reply with quote

#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








PostPosted: Wed Nov 28, 2007 3:16 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 28, 2007 3:25 pm     Reply with quote

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