|
|
View previous topic :: View next topic |
Author |
Message |
Yann Guest
|
12F629/675 Timer1,Sleep |
Posted: Wed Nov 13, 2002 9:34 am |
|
|
Hello
I want to know if it's possible to put the pic12F629/675 in sleep mode and get it wake up by Timer1 if I using a cristal+cap. for my clock? The datasheet it not very clear. I know that we have to put the Timer1 counter in asynchronous mode. I have to get a 3s delay, but it's imposible to use the wdt, because it do a 2400ms delay.
thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 8845 |
|
|
johnpcunningham Guest
|
Re: 12F629/675 Timer1,Sleep |
Posted: Wed Nov 13, 2002 10:54 am |
|
|
ff
According to the spec, for TIMER1 to operate during sleep:
Timer1 must be on (T1CON<0>)
TMR1IE bit (PIE<0>) must be set
PEIE bit (INTCON<7>) must be set
you need a clock slow enough and to set the TIMER to the proper value to have a 3 second overflow.
///////////////////////////////////////////////////////
Another ways would be to use the WDT. You can set the WDT to wake up at different time frequencies. Although not perfect, it can get you close, still save power, free up 2 pins, and eliminate an extra clock.
Maybe you can run a staged loop like:
WDT for 2300ms
sleep
WDT for 576ms
sleep
WDT for 144ms
sleep
(close enough to 3 seconds..now go do something)
___________________________
This message was ported from CCS's old forum
Original Post ID: 8851 |
|
|
Yann Guest
|
Re: 12F629/675 Timer1,Sleep |
Posted: Wed Nov 13, 2002 2:16 pm |
|
|
ok, is it possible to do a staged loop with wdt like below?
Because, when a pic is wake up from sleep by a wdt, it's because the wdt involve a reset, so the pic return to the beginning of it's program, so I'm out of my loop? no?
/*************************************************************/
:=
:=According to the spec, for TIMER1 to operate during sleep:
:=
:=Timer1 must be on (T1CON<0>)
:=TMR1IE bit (PIE<0>) must be set
:=PEIE bit (INTCON<7>) must be set
:=
:=you need a clock slow enough and to set the TIMER to the proper value to have a 3 second overflow.
:=///////////////////////////////////////////////////////
:=Another ways would be to use the WDT. You can set the WDT to wake up at different time frequencies. Although not perfect, it can get you close, still save power, free up 2 pins, and eliminate an extra clock.
:=
:=Maybe you can run a staged loop like:
:=
:=WDT for 2300ms
:=sleep
:=WDT for 576ms
:=sleep
:=WDT for 144ms
:=sleep
:=
:=(close enough to 3 seconds..now go do something)
___________________________
This message was ported from CCS's old forum
Original Post ID: 8862 |
|
|
johnpcunningham Guest
|
Re: 12F629/675 Timer1,Sleep |
Posted: Wed Nov 13, 2002 5:31 pm |
|
|
Assume the PIC is put to sleep mode. When the WDT "wakes up" it will run the next line of code and not reset. A WDT reset will only occur if the processor is running and the WDT times out; therfore you need to reset the WDT in your code. So the answer is no, it will not reset when it wakes up from sleep.
One thing to point out is that the sleep() command will be treated as a NOP if there is an interrupt pending. See pg 63 of the 12F675 manual.
INTCON = 0b00000000;//clear everything, MOSTLY THE FLAGS
PIR1 = 0b00000000;//clear peripheral interrupt flags
restart_wdt(); //only needed for first pass
WDT for 2300ms
sleep
WDT for 576ms
sleep
WDT for 144ms
sleep
___________________________
This message was ported from CCS's old forum
Original Post ID: 8871 |
|
|
johnpcunningham Guest
|
Re: 12F629/675 Timer1,Sleep |
Posted: Wed Nov 13, 2002 5:35 pm |
|
|
:=Assume the PIC is put to sleep mode. When the WDT "wakes up" it will run the next line of code and not reset. A WDT reset will only occur if the processor is running and the WDT times out; therfore you need to reset the WDT in varous sections of your code to prevent the timeout. Probably best to set the WDT to its max value of 2304ms while the code is running to prevent such a timeout.
So the answer is no, it will not reset when it wakes up from sleep.
:=
:=One thing to point out is that the sleep() command will be treated as a NOP if there is an interrupt pending. See pg 63 of the 12F675 manual.
:=
:=INTCON = 0b00000000;//clear everything, MOSTLY THE FLAGS
:=PIR1 = 0b00000000;//clear peripheral interrupt flags
:=
:=restart_wdt(); //only needed for first pass
:=WDT for 2300ms
:=sleep
:=
:=WDT for 576ms
:=sleep
:=
:=WDT for 144ms
:=sleep
___________________________
This message was ported from CCS's old forum
Original Post ID: 8872 |
|
|
R.J.Hamlett Guest
|
Re: 12F629/675 Timer1,Sleep |
Posted: Thu Nov 14, 2002 5:29 am |
|
|
:=:=Assume the PIC is put to sleep mode. When the WDT "wakes up" it will run the next line of code and not reset. A WDT reset will only occur if the processor is running and the WDT times out; therfore you need to reset the WDT in varous sections of your code to prevent the timeout. Probably best to set the WDT to its max value of 2304ms while the code is running to prevent such a timeout.
:=
:=So the answer is no, it will not reset when it wakes up from sleep.
:=
In the context of the 'sleep time' though, you have to also consider the massive errors in WDT times. The time for a watchdog timeout, is not 'X' msec, but a very variable number around this point. The variation on most production chips is fairly small, but over the full temperature and voltage range, can be very big. For instance on the 18Fxx2 family, the defined interval for an 'unprescaled' watchdog, is '7mSec minimun, to 33mSec max'. If the full prescaler is used, this give a time interval of between 0.896 seconds, to 4.224 seconds. Several people on this group, ran into problems with this, when some early chips were routinely returning 'short' time intervals below 1 second.
So if accurate times are required, forget the watchdog. Better to do something like have an external clock chip, that generates an interrupt at a low frequency, and itself draws little power (like the DS1307), and then use this to wake up occasionally, and check if the required delay has been reached.
Best Wishes
:=:=
:=:=One thing to point out is that the sleep() command will be treated as a NOP if there is an interrupt pending. See pg 63 of the 12F675 manual.
:=:=
:=:=INTCON = 0b00000000;//clear everything, MOSTLY THE FLAGS
:=:=PIR1 = 0b00000000;//clear peripheral interrupt flags
:=:=
:=:=restart_wdt(); //only needed for first pass
:=:=WDT for 2300ms
:=:=sleep
:=:=
:=:=WDT for 576ms
:=:=sleep
:=:=
:=:=WDT for 144ms
:=:=sleep
___________________________
This message was ported from CCS's old forum
Original Post ID: 8896 |
|
|
|
|
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
|