CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to setup TIMER1 to wake up from sleep

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

How to setup TIMER1 to wake up from sleep
PostPosted: Tue Dec 22, 2015 4:49 am     Reply with quote

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: 19326

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 5:35 am     Reply with quote

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. Embarassed
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

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 6:24 am     Reply with quote

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: 19326

View user's profile Send private message

PostPosted: Tue Dec 22, 2015 7:49 am     Reply with quote

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).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group