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

PIC18F8920... RTCC as 16 bit timer

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



Joined: 06 Jul 2004
Posts: 3

View user's profile Send private message

PIC18F8920... RTCC as 16 bit timer
PostPosted: Tue Jul 06, 2004 9:17 am     Reply with quote

I have been trying to use Timer0 in an 18F8720 device as a 16-bit timer. I can get my code to work when it is configured as an 8-bit counter, but when I set it to 16-bits, no interrupts occur. Here is a code snippet of a modified version of EX_STWT.C example from CCS:
------------------------------------------------------
#int_timer0 // This function is called every time
void clock_isr() { // the RTCC (timer0) overflows (255->0).
// For this program this is apx 76 times
if(--int_count==0) { // per second.
++seconds;
int_count = INTS_PER_SECOND;
}
}

void main (void)
{
BYTE start;

int_count = INTS_PER_SECOND;
set_timer0 (0);
setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);

InitializeSystem();
do {
printf("Press any key to begin.\n\r");
getc();
start=seconds;
printf("Press any key to stop.\n\r");
getc();
printf("%u seconds.\n\r",seconds-start);
} while (TRUE);
}
------------------------------------------------------

When the initialization line is as follows timer 0 interrupts are generated.

setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);

When the RTCC_8_BIT option is eliminated, which should cause timer 0 to become 16-bit, timer0 interrupts do not occur.

setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256);

Anyone experienced this? Is there a work-around? Thanks.
Pogostik



Joined: 06 Jul 2004
Posts: 3

View user's profile Send private message

Typo in headline... Pls excuse
PostPosted: Tue Jul 06, 2004 9:20 am     Reply with quote

In my header I meant to type 18F8720. I don't think the 18F8920 is available yet....
Guest








PostPosted: Tue Jul 06, 2004 10:13 am     Reply with quote

Did you wait enough time? Setting up timer0 to 16 bit in your case could means 256 seconds (cca. 4 minutes) instead of the original 1 second.
Pogostik



Joined: 06 Jul 2004
Posts: 3

View user's profile Send private message

PostPosted: Tue Jul 06, 2004 10:27 am     Reply with quote

Are you saying... setting timer0 to 16 bits and initializing it to 0 would result in 65535 ticks before interrupt; whereas setting it to 8 bits would require only 256 ticks before interrupt? I think that may be it. Let me try it with those adjustments.

OK... it works fine now. Thanks for the tip...
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