View previous topic :: View next topic |
Author |
Message |
Dutch2
Joined: 05 Oct 2007 Posts: 8
|
Use Timer1 to wake up from sleep |
Posted: Wed Jan 30, 2008 10:39 pm |
|
|
I would like to go to sleep and then wake up via Timer1 on a 16F887:
6.4Timer1 Oscillator
A low-power 32.768kHz crystal oscillator is built-in
between pins T1OSI (input) and T1OSO (amplifier
output). The oscillator is enabled by setting the
T1OSCEN control bit of the T1CON register. The
oscillator will continue to run during Sleep.
The Timer1 oscillator is identical to the LP oscillator.
The user must provide a software time delay to ensure
Timer1 gate source is software configurable to be the
proper oscillator start-up.
TRISC0 and TRISC1 bits are set when the Timer1
oscillator is enabled. RC0 and RC1 bits read as ‘0’ and
TRISC0 and TRISC1 bits read as ‘1’.
6.8Timer1 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. To set up the timer to wake the device:
• TMR1ON bit of the T1CON register must be set
• TMR1IE bit of the PIE1 register must be set
• PEIE bit of the INTCON register must be set
The device will wake-up on an overflow and execute
the next instruction. If the GIE bit of the INTCON
register is set, the device will call the Interrupt Service
From what I understand is that Timer1 can cause a wake up from sleep when using an external oscillator. I'm using an internal oscillator, but it seems you can use the 32kHz in sleep mode?
This is what I have:
Code: | Value = 0;
while (TRUE) {
fprintf(PC,"Hello!\n\r");
Value++;
if (Value == 5) {
bit_set(PIE1,0);
bit_set(IntCon,6);
T1CON = 0b00111111;
clear_interrupt(INT_TIMER1);
enable_interrupts(INT_TIMER1);
fprintf(PC,"Goodbye!\n\r");
sleep();
delay_cycles(1);
Value = 0;
}
delay_ms(250);
} |
It prints 4 times Hello! and one Goodbye! but it never returns from sleep... what am I missing?
Thanks in advance,
D2. |
|
|
Dutch2
Joined: 05 Oct 2007 Posts: 8
|
|
Posted: Wed Jan 30, 2008 10:42 pm |
|
|
Forgot this part:
#byte PIE1 = 0x8C
#byte T1CON = 0x10
#byte IntCon = 0x0B
D2. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|