View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
How to setup TIMER1 to wake up from sleep |
Posted: Tue Dec 22, 2015 4:49 am |
|
|
Hi, I read that only timer 1 is capable to wake up the processor from sleep. Although I tried number of settings to do so. Unfortunately I wasn't able to wake up using timer1 interrupt.
These options are provided by 16f628A.h:
Code: |
#define T1_DISABLED 0
#define T1_INTERNAL 0x85
#define T1_EXTERNAL 0x87
#define T1_EXTERNAL_SYNC 0x83
#define T1_CLK_OUT 8
#define T1_DIV_BY_1 0
#define T1_DIV_BY_2 0x10
#define T1_DIV_BY_4 0x20
#define T1_DIV_BY_8 0x30 |
Tried many combos without success though. Then I tried by setting the T1CON register, Code: |
#define T1SYNC (1 << 2)
#define T1OSCEN (1 << 3)
#define TMR1CS (1 << 1)
#define TMR1ON (1)
#byte T1CON = 0x10
T1CON = (TMR1ON | T1OSCEN | T1SYNC); |
But then I get problem programming the chip again. I went through all these struggles to recover the chip so I can program it again http://www.microchip.com/forums/m903622.aspx Any ideas how to avoid these issues and make TIMER1 to wake up the proc from sleep? _________________ A person who never made a mistake never tried anything new. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Dec 22, 2015 5:35 am |
|
|
You do realise you need an external crystal on the T1 clock pins?. Normally 32768Hz.
The settings needed are:
T1_EXTERNAL | T1_CLK_OUT | T1_DIV_BY_1
(you can use higher multipliers)
You also need to have the TIMER1 interrupt enabled before you sleep.
Then when the interrupt triggers (you don't actually need to have the INT_GLOBAL enabled, and if you don't, the interrupt handler will not be called), the chip will wake.
You must _not_ have SYNC enabled (this synchronises the timer to the master clock, and the master clock is _stopped_....)
Updated:
I also originally posted this with 'INTERNAL' selected, which is (of course) wrong.
Have updated it in case anyone else it trying to setup the timer and does have a crystal. Internal won't work, but without the crystal neither will external.
Last edited by Ttelmah on Tue Dec 22, 2015 3:49 pm; edited 1 time in total |
|
|
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Tue Dec 22, 2015 6:24 am |
|
|
Thank you T. Theere is no space for crystal on the PCB so I will be using WDT to wake up. _________________ A person who never made a mistake never tried anything new. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Dec 22, 2015 7:49 am |
|
|
In which case you can't wake with the timer. Quote from data sheet:
"A crystal oscillator circuit is built in between pins T1OSI
(input) and T1OSO (amplifier output). It is enabled by
setting control bit T1OSCEN (T1CON<3>). It will
continue to run during Sleep. It is primarily intended for
a 32.768 kHz watch crystal. Table 7-1 shows the
capacitor selection for the Timer1 oscillator."
You can only use the timer to wake if you have an external clock source for it. For watchdog wake up, you don't use the timer. Be aware of just how inaccurate the watchdog is on these chips. Nominal 18mSec, is actually 7 to 33mSec.
There are many later PIC's, that have an internal low power oscillator that can keep running when you are asleep, but not the 628, which is quite an old PIC (about 10 years). |
|
|
|