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

Wake up frequently from sleep
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Spaeth



Joined: 05 Jun 2020
Posts: 27

View user's profile Send private message

Wake up frequently from sleep
PostPosted: Sat Jan 16, 2021 7:01 am     Reply with quote

Hello,

For an application the PIC should go into sleep mode to save energy and wake up frequently from sleep without any input from outside the PIC.
The sleep time may vary between several 10s of seconds to 10..20 minutes.
How to do?

My idea is to set up a watchdog and wake up by WDT. To get longer sleep periodes the PIC restarts the WDT after wake up and enters sleep mode again, repeating this several times until the end of the wanted time period is reached.
But the timer of the WDT is not calibrated, so I do have a large range of accuracy of sleep/WDT times when I compare several PICs.

I'm looking for a solution with an accuracy of a few seconds for a sleep period of 10 minutes.

Any idea would be much appreciated.

Best regards
Thomas
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jan 16, 2021 7:57 am     Reply with quote

Do not use the WDT ! As you've found out the accuracy of it ,isn't, well, accurate.
Simply use a timer to interrupt the PIC from sleep. Without knowing which PIC I can say which timer,but most PICs have several timers that can set an interrupt 'flag'. How long a delay and frequency of the interrup is based upon clock and timer.There's usually 1 8bit and some 16 bit timers in a PIC.
There may be an example in teh examples folder or in the FAQ section of the manual but you should really post your PIC type as well as an example of the 'timing' you require.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Jan 16, 2021 9:21 am     Reply with quote

Worth understanding that a timer based on (say) a 32768 Hz crystal, can do
a wake up every two seconds. All your code needs do is maintain a counter,
decrement this, and go straight back to sleep. A chip that wakes for a
handful of processor cycles every two seconds, uses indetectably more
power than one that is permanently asleep. I've got chips in controllers
running off a CR2032, that have run for over two years, and the battery is still
over 3.1v. Waking every two seconds.
So for 10 minutes, you just set the counter to 300 wake cycles.
Spaeth



Joined: 05 Jun 2020
Posts: 27

View user's profile Send private message

PostPosted: Sat Jan 16, 2021 10:10 am     Reply with quote

Hello temtronic, thanks for the hint regarding using a timer instead of WDT! The chip I'm using is 16F1847.

Hello Ttelmah, thanks for the info!

The timing reqired changes, 10 sec, 20 sec, 1 min, 2 min, 10min, 20 min.
But when I have a 'base' timer with a time base of e.g. 2 sec I can use the method Ttelmah proposed.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 16, 2021 12:04 pm     Reply with quote

sleep_for_x_seconds() sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=45458&start=5
Note that the sample code uses a macro to create the interrupt_enabled()
routine. Since then, CCS created the built-in interrupt_active() routine
and it should be used instead.
Spaeth



Joined: 05 Jun 2020
Posts: 27

View user's profile Send private message

PostPosted: Sat Jan 16, 2021 1:46 pm     Reply with quote

Hello PCM programmer, many thanks, I will try it soon!
Spaeth



Joined: 05 Jun 2020
Posts: 27

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 5:10 am     Reply with quote

Hello PCM programmer, did you use an external oscillator?
I tried your code using a PIC16F1847 with an internal oscillator, it does not run.
May it be that the internal oscillator does not run in sleep mode except the WDT timer?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 5:16 am     Reply with quote

It's using the Timer1 oscillator with a watch crystal. That oscillator runs
even when the PIC is in sleep mode.
Spaeth



Joined: 05 Jun 2020
Posts: 27

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 5:25 am     Reply with quote

Hello, now I checked the data sheet:

Quote:
21.4 Timer1 Oscillator
A dedicated low-power 32.768 kHz oscillator circuit is
built-in between pins T1OSI (input) and T1OSO
(amplifier output). This internal circuit is to be used in
conjunction with an external 32.768 kHz crystal.
The oscillator circuit is enabled by setting the
T1OSCEN bit of the T1CON register. The oscillator will
continue to run during Sleep.

The timer 1 oscillator is based on an external crystal and then the oscillator will run during sleep!

Any solutions for a PIC running without external oscillator/crystal?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 7:34 am     Reply with quote

Some of the PIC's have an internal reasonably accurate low power
oscillator that can run when asleep. The external crystal oscillator has
the advantage of accuracy, and being very low power.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 8:24 am     Reply with quote

I always wonder about the 'save energy' threads....considering it's cheap and easy to just use a larger capacity battery ! Sure you can optimize code, settings,components but at a huge cost in R&D time. Hmm, 'battery'. Is that just a single '3 v coin cell' or a '12V battery pack'?
I don't know the 'project' requirements, but normally you use an 'L' version of a PIC for reduced power needs. The big concern is what is the required 'life' of the device and where it will be used. If it only needs to be used for a month, that's easy....3 years...another story. Indoors...real easy, outside here in Canada ,in winter..not so easy but can be done.
Spaeth



Joined: 05 Jun 2020
Posts: 27

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 11:31 am     Reply with quote

Hello temtronic,

I cannot use a larger capacity battery, the size is limited to a CR2/3 / 16340 LiIon cell. The max capacity is around 700...800 mAh.

I cannot use 'L' version because the voltage of the battery may exceed 3.6V, the voltage of the battery can reach 4.1V.

The application is a remote temperature/humidity sensor with a RFM69 transceiver. The transceiver is being switched from sleep to receive mode to receive a synchronisation command, then sending the data and switched into sleep mode, the PIC is than also going into sleep mode. After a period of 10 min. the PIC should be waked up, putting the transceiver in receive mode and so on. As the transceiver RFM69 does not have a sleep mode with wake up timer (the RFM12 does have! but I cannot use it because of the lower RF power) the wake up mechanism must come from the PIC. The PIC runs with the internal oscillator. No external oscillator nor crystal is possible.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 12:50 pm     Reply with quote

You need to say 'what PIC', or (perhaps more importantly), what PIC
format/size is involved. There may well be equivalent ones that do have the
high accuracy timer. Also, many of the L PIC's will support 5v operation.
700mAHr is a lot of power. However since 'weather' is involved, you have
to remember that most batteries lose a huge amount of power when the
temperature falls.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 1:47 pm     Reply with quote

re:
Quote:
the voltage of the battery can reach 4.1V.

If that's the case, you'll destroy the RFM module......
at least according to the spec sheet from Sparkfun....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 17, 2021 5:23 pm     Reply with quote

Spaeth wrote:
No external oscillator nor crystal is possible.

The Timer1 oscillator is independent of the internal oscillator.
It uses separate pins. It is certainly possible.

I think you are using the 16F1847 (or possibly the 16LF1847). For that
chip the T1 oscillator is on the ICSP pins (B6 and B7). Somewhere it's
documented that you must disconnect the watch crystal from those pins
when you program the PIC using ICSP. I checked the schematic for
one of my projects, and I've got solder jumper pads between one side
of the 32.768 KHz crystal and Pin B6. A blob of solder is put across the
pads after the PIC is programmed.

I also have two 22pf caps, one on each side of the crystal to ground.

Also, my project is battery powered. The PIC and all circuits run off
3.6v. I don't know why you have to use 4.1 volts. If you use a 3.6v
battery, you can use the "LF" version of the PIC and it uses much less
power in sleep mode than the "F" version.

The crystal is Seiko SC32P-12.5PF20PPM.

The caps are Yaego CC0805JRNPO9BN220.
0805 ceramic, 22 pf, 50v, NPO, 5%
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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