View previous topic :: View next topic |
Author |
Message |
dazlogan
Joined: 19 Oct 2003 Posts: 24 Location: Cambridge, UK
|
Timer 1 not interrupting (PIC12F629 with 32kHz crystal) |
Posted: Mon Mar 29, 2004 4:16 pm |
|
|
Hi,
PIC = 12F629
Clock = 32kHz crystal (LP mode)
PCM = V3.153
Using MPLAB 6.4 & simulator, I cannot get timer 1 to fire.
Here's the simple code:-
Code: |
#include <12F629.h>
#use delay(clock=32768)
#fuses LP,BROWNOUT,NOWDT,PUT
#int_TIMER1
TIMER1_isr() {
a++;
}
void main() {
setup_counters(RTCC_INTERNAL,RTCC_DIV_32);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_comparator(FALSE);
setup_vref(FALSE);
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
while(1){}
}
|
Any pointers appreciated!, thanks.
Regards,
Darren |
|
|
valemike Guest
|
|
Posted: Mon Mar 29, 2004 4:26 pm |
|
|
When I use an external (not on osc1 and osc2, but rather on rc0 and rc1) 32Khz clock for Timer1, this code works:
Code: | setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL); |
But when i use an external 4MHz clock, this is what works:
Code: | setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
set_timer1(0); |
|
|
|
dazlogan
Joined: 19 Oct 2003 Posts: 24 Location: Cambridge, UK
|
8-) |
Posted: Tue Mar 30, 2004 1:28 am |
|
|
It seems to be working now, i am getting an 8 second interrupt which is correct.
Now how do I get the chip to wake up from sleep on a timer 1 interrupt?
Thanks
Regards,
Darren |
|
|
dazlogan
Joined: 19 Oct 2003 Posts: 24 Location: Cambridge, UK
|
code |
Posted: Tue Mar 30, 2004 1:36 am |
|
|
here's the code by the way which works:
Code: |
int a;
// timer 1 interrupt, triggers every 8 seconds
#int_TIMER1
TIMER1_isr() {
a++;
}
// main function
void main() {
#byte CMCON=0X19
#byte INTCON=0X0B
setup_counters(RTCC_INTERNAL,RTCC_DIV_32);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(0);
setup_comparator(FALSE);
setup_vref(FALSE);
CMCON=0x07;
INTCON|=0XC0;
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
while(1){
//a++;
//sleep();
}
}
|
The INTCON|=0XC0 made the difference.
But I still need to wake up from sleep.
Thanks
Regards,
Darren |
|
|
|