View previous topic :: View next topic |
Author |
Message |
Futterama
Joined: 17 Oct 2005 Posts: 98
|
PIC12F683 wake up from sleep using Timer1 and INTOSC |
Posted: Sat Aug 23, 2008 2:07 pm |
|
|
Hello forum,
I would like to be able to wake up my PIC12F683 using Timer1 interrupt. I'm using the internal oscillator. It seems to me that Timer1 will only keep running during sleep if LP oscillator is enabled, and as far as I know, thats when running 31kHz internal osc. The LP will automatically be enabled when Power-Up-Timer is enabled.
The datasheet says the following:
Quote: | 6.7 Timer1 Operation During Sleep
Timer1 can only operate during Sleep when setup in
Asynchronous Counter mode. In this mode, an external
crystal or clock source can be used to increment the
counter. |
Note the word "can". I'm not sure if this means that Timer1 NEEDS an external oscillator.
This is my code:
Code: | #include <12F683.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES PUT //Power Up Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#int_TIMER1
void TIMER1_isr(void)
{
GP2 = !GP2; // Toggle LED
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_oscillator(OSC_31KHZ);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
TRISIO = 0b00000000; // Configure IO pin directions (all output)
GPIO = 0b00000000; // Set default output pin states
sleep();
}
|
The PIC will not blink the LED. It works if I use a "while(1);" instead of the sleep statement so interrupts are working.
What am I missing?
Best regards,
Futterama |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 23, 2008 3:23 pm |
|
|
Do you have an external 32.768KHz watch crystal (and capacitors)
connected to the Timer1 oscillator pins ? You need one.
The internal oscillators (LF and HF) don't run during sleep.
This post has sample code which shows how to wake up from sleep
with the Timer1 interrupt:
http://www.ccsinfo.com/forum/viewtopic.php?t=28158&start=8 |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Aug 23, 2008 3:46 pm |
|
|
No, I don't have a crystal. I'm trying to avoid that and only use the internal oscillator.
Well, I read your thread before posting and I searched a bit, and I found something about using the WDT. I have never used the WDT before, so I'll have to look into that and forget about the timer.
But in the datasheet it says that the WDT uses LFINTOSC so if no internal oscillator is running during sleep, I can't use that either? |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Aug 23, 2008 4:03 pm |
|
|
Ahh, the datasheet says:
Quote: | 12.7 Power-Down Mode (Sleep)
The Power-down mode is entered by executing a
SLEEP instruction.
If the Watchdog Timer is enabled:
• WDT will be cleared but keeps running. |
So it should be possible to use the WDT for interrupting a sleep.
But the datasheet also says the following:
Quote: | ...Other peripherals cannot generate interrupts, since
during Sleep, no on-chip clocks are present. |
With no on-chip clock, how can the WDT keep running? |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Aug 23, 2008 4:27 pm |
|
|
Hi,
I got the PIC to wake up using the WDT. I used PIC12F683 feature of enable/disable the WDT in software in my test. |
|
|
|