Question

I have PIC18F87J11 with MPLAB C18. I am trying to limit the consumption of battery by the device by forcing it to go to sleep. I noticed upon entering the sleep mode, timer0 stops counting up any further until awaken. Also the only method I know to wake up the device is when it receives a message from another node since I have a MRF89XA transceiver.

To put my device to sleep I just call it this function which is defined in the Compiler header file.

Sleep(); 

Q1: How do I wake up the device other than by receiving a message from some node? In the DataSheet it says to EXIT BY INTERRUPT or by EXIT BY RESET but how do you do that if there is no timer?

By reading the DataSheet its stated that Timer1 must be used to be able to monitor the time, is that really the case?

All I really want is to lower battery usage as much as possible and keep the timer working on sleep mode.

Thanks!

Was it helpful?

Solution

Yes, Timer1 is the only timer that can operate in Sleep mode. From datasheet:

Entering Sleep mode from any other mode does not require a clock switch. This is because no clocks are needed once the controller has entered Sleep. If the WDT is selected, the INTRC source will continue to operate. If the Timer1 oscillator is enabled, it will also continue to run.

To run a timer with minimal power consumption, use Sleep mode and Timer1.

If you wish to use other peripherals, like Timer0, while in power-managed mode, there's an alternative to Sleep mode called the Idle mode:

If the IDLEN bit is set to ‘1’ when a SLEEP instruction is executed, the peripherals will be clocked from the clock source selected using the SCS<1:0> bits; however, the CPU will not be clocked. The clock source status bits are not affected. Setting IDLEN and executing a SLEEP instruction provides a quick method of switching from a given Run mode to its corresponding Idle mode.

To set the IDLEN bit to 1, add OSCCON |= 0b10000000; somewhere before issuing Sleep();.

Obviously Idle mode will consume a bit more power than Sleep mode, since peripherals are left operating.

OTHER TIPS

I had this exact problem, but it was a minor oversight on my behalf. Timer1 can have/has a sync bit, called something like:

T1CONbits.nT1SYNC = 1; // Timer1 External Clock Input Synchronization Control bit.

This syncs the timer 1 the the main clock. As the main clock doesn't run in sleep mode, it cant sync and hence Timer1 does not operate. All i needed to do was ensure that I wasn't syncing Timer1 to the primary clock. configure it in the right sleep mode i.e. not deep sleep or idle or vBAT, and everything worked.

I was using MPLABx and XC8 with a PIC18F97j94

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top