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 support@ccsinfo.com

setup_timer_0 and RTCC_8_BIT really required to work right?

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



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

setup_timer_0 and RTCC_8_BIT really required to work right?
PostPosted: Fri Mar 27, 2009 5:34 pm     Reply with quote

I'm really sorry if this has been covered in other topics - I did search around briefly.

I'm on a 18F2620 w/ compiler version 4.030.

Is it really necessary to have RTCC_8_BIT in setup_timer_0()? I thought since the RTCC was only 8-bit on the 18F2620 (at least RTCC_16_BIT isn't in the chips .h file), that it would just default to that.

I was getting unexpected timings, and figured out it was off by a factor of about 250-ish. I tried inserting RTCC_8_BIT in setup_counter_0, and it works fine.

Doesn't work:

Code:
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_4);


Does work:

Code:
setup_timer_0(RTCC_INTERNAL | RTCC_8_BIT | RTCC_DIV_4);


Any comments on this to understand it better would be appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 5:44 pm     Reply with quote

Quote:
I thought since the RTCC was only 8-bit on the 18F2620

The 18F2620 data sheet says this:
Quote:
11.0 TIMER0 MODULE
• Software selectable operation as a timer or
counter in both 8-bit or 16-bit modes

REGISTER 11-1: T0CON: TIMER0 CONTROL REGISTER
bit 6 -- T08BIT: Timer0 8-Bit/16-Bit Control bit
1 = Timer0 is configured as an 8-bit timer/counter
0 = Timer0 is configured as a 16-bit timer/counter

http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 9:39 pm     Reply with quote

[quote="PCM programmer"]
The 18F2620 data sheet says this:
Quote:
11.0 TIMER0 MODULE
• Software selectable operation as a timer or
counter in both 8-bit or 16-bit modes


Okay, lesson to be learned here: always check the datasheet. 18F2620.h (in 4.030 at least) doesn't have an option to set it up as 16 bit. It would be nice if one could assume that meant it didn't have that option.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 10:03 pm     Reply with quote

Here are the constants for vs. 4.089. It's setup as a 16-bit timer if
you don't specify RTCC_8_BIT.
Code:

#define RTCC_INTERNAL   0
#define RTCC_EXT_L_TO_H 32
#define RTCC_EXT_H_TO_L 48

#define RTCC_DIV_1      8
#define RTCC_DIV_2      0
#define RTCC_DIV_4      1
#define RTCC_DIV_8      2
#define RTCC_DIV_16     3
#define RTCC_DIV_32     4
#define RTCC_DIV_64     5
#define RTCC_DIV_128    6
#define RTCC_DIV_256    7

#define RTCC_OFF        0x80 

#define RTCC_8_BIT      0x40 


The function only does one thing. It writes to the T0CON register:
Quote:
.... setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1);
00028: MOVLW 88
0002A: MOVWF T0CON
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