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

Timer1 prescaler not work, PIC18F24J11

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



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

Timer1 prescaler not work, PIC18F24J11
PostPosted: Wed Jul 18, 2012 8:52 am     Reply with quote

I don't know why prescaler configuration doesn't affect Timer1 counting frequency. Despite of prescaler configuration, it seems like T1_DIV_BY_1.

I've tried to configure it manually, but without success.
Actually (even when T1_DIV_BY_8) the Timer1 overflow is occurring each two seconds, but it should be 16seconds). I've tried other prescaler values, but without success.

See the code:
Code:

//setup_timer_1(T1_EXTERNAL | T1_DIV_BY_8);   
//T1CON = (T1_EXTERNAL | T1_DIV_BY_8);
T1CON = 0b10111111;  //does the same than above


enable_interrupts(INT_TIMER1); //enable Timer1 interrupts
enable_interrupts(INT_RTC); //enable RTC interrupts
enable_interrupts(GLOBAL); //enable interrupts


I'm using crystal of 32kHz for Timer1 and 16MHz for main oscillator.
I'm using the built-in RTC also. It's working pretty good!

Thanks for any help.
Regards folks!
_________________
Eduardo Guilherme Brandt
Ttelmah



Joined: 11 Mar 2010
Posts: 19559

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 9:32 am     Reply with quote

To use an external crystal on T1, you need:
T1_ENABLE_T1OSC

Without this, it'll assume you are feeding a clock in on the input pin. I'm surprised it gives anything.

setup_timer_1(T1_EXTERNAL | T1_ENABLE_T1OSC | T1_DIV_BY_8);

However I'd have expected your manual settings to work. Do a text search on the code and 'make sure' nothing else is changing timer1. It sounds as if something else is changing the value.

Compiler version?.

Best Wishes
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 10:41 am     Reply with quote

Dear Ttelmah,

You´re right again, I forgot timer1 Enable bit(T1_ENABLE_T1OSC).


I´m using compiler version 4.124.
Function setup_rtc(RTC_ENABLE,0) was changing Timer1 configuration.

Can this function change T1CON or could it be just a bug?

Thanks a lot!
_________________
Eduardo Guilherme Brandt
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 12:42 pm     Reply with quote

The RTC on that chip can use the T1 external clock input. If you check the data sheet for the PIC (section 17.2.2.1) you'll see that the RTC has to enable bit 3 of T1CON to work, so setup_rtc() probably does affect the register.
Eduardo__



Joined: 23 Nov 2011
Posts: 197
Location: Brazil

View user's profile Send private message

PostPosted: Wed Jul 18, 2012 1:39 pm     Reply with quote

Thanks Jeremiah.
_________________
Eduardo Guilherme Brandt
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