View previous topic :: View next topic |
Author |
Message |
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
Timer1 prescaler not work, PIC18F24J11 |
Posted: Wed Jul 18, 2012 8:52 am |
|
|
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: 19484
|
|
Posted: Wed Jul 18, 2012 9:32 am |
|
|
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
|
|
Posted: Wed Jul 18, 2012 10:41 am |
|
|
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: 1343
|
|
Posted: Wed Jul 18, 2012 12:42 pm |
|
|
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
|
|
Posted: Wed Jul 18, 2012 1:39 pm |
|
|
Thanks Jeremiah. _________________ Eduardo Guilherme Brandt |
|
|
|