Improving my project with sleep?

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
My first major PIC project is coming along nicely (after a long summer break on the shelf :) ).

Basically it is a solar panel / light controller. The PIC monitors the output of the solar panel. When the voltage drops below a settable level, an adjustable timer is started. When the timer expires, the light is turned on.

After the light comes on, another timer is started. The battery level is monitored. The light is turned off when the second timer expires or when the battery level drops below a settable amount, whichever comes first.

The project has an LCD panel and a couple of buttons to allow setting of the various functions of the timer.


The current code design is a little crude. Right now it polls the analog input for the voltages and binary inputs for button press. The timer is also polled until it reaches the given value.

I currently save a little power by only lighting the backlight after a button press. The light is turned off after one minute of no buttons being pressed.

I would like to save more power.

Can I also use the same output that powers the backlight to turn off and on the LCD itself?

How can I improve my project and save more power using sleep?

I guess where I maybe need the most help is how to monitor my analog inputs without having to poll them. I don't need details, just pointed in the right direction, though a ling to a sample project would help.
I seem to remember reading something about comparators.
 

maxpower097

Joined Feb 20, 2009
816
Set a RTC timer every 5 minutes to wake up and check your voltages, then go back to sleep. Or put it to sleep and have voltage pin wake it, or timer wake it up when its time to work.
 

Markd77

Joined Sep 7, 2009
2,806
Depending on the PIC an accurate way to keep time in sleep mode is to use a watch crystal on Timer1.
Have a look for a low power mode for the LCD, I think you can put them into sleep mode.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Depending on the PIC an accurate way to keep time in sleep mode is to use a watch crystal on Timer1.
Have a look for a low power mode for the LCD, I think you can put them into sleep mode.
Thanks really don't need anything super accurate. I want to keep things as simple as possible. Within a few minutes is just fine. After all it is just a timer for a light. The idea is to turn it on X minutes after the panel can no longer sense light. Previous experienced showed (with a simple dumb controller) that the light came on way too early when there was still plenty of ambient light.


But will the on board clock still work in sleep?

As far as the LCD it has a KS066 driver which is HD44780 compatible. I don't see anything in the HD44780 datasheet that would put the LCD to sleep. I would assume it would be in the command set somewhere?
 

maxpower097

Joined Feb 20, 2009
816
Depending on the chip. I know the 16 bit pics and higher have RTCC in sleep mode. I'm sure some 8 bits will have it. Might require an extra RTCC chip to externally pull a pin high when the alarm goes off to trigger an interupt. Thats the way we did it on our PIC16LF877 project. Working on a PIC24 project now that has the RTCC built in with sleep, but I'm planning on adding an external RTCC chip just to compare and make sure the uC is doing what its supposed to do. Your LCD will be cut out going to sleep because your pics gonna shut down the PMP if your 16 bit, or your pins if your not.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Depending on the chip. I know the 16 bit pics and higher have RTCC in sleep mode. I'm sure some 8 bits will have it. Might require an extra RTCC chip to externally pull a pin high when the alarm goes off to trigger an interupt.


Sorry RTC is Run Time Clock. What is the second C in RTCC? The last pas

Datasheet says:

An on-chip crystal oscillator circuit is incorporated
between pins OSC1 (input) and OSC2 (amplifier output).
It is enabled by setting the Timer1 Oscillator Enable bit,
T1OSCEN of the T1CON register. The oscillator is a
low-power circuit rated for 32 kHz crystals. It will
continue to run during all power-managed modes.

I guess his means it works during sleep? The next to the last sentence confuses me a bit. Not sure if it means I need a crystal or not.




Your LCD will be cut out going to sleep because your pics gonna shut down the PMP if your 16 bit, or your pins if your not.
I am using 8 bit a PIC 18F14K22. I am using 4 bits on the LCD. So the LCD will automatically sleep when it no longer sees input? And it will wake up when the PIC starts "talking" to the LCD again?

Since I rarely need the LCD, couldn't I just power down and power up the LCD along with the backlight? But one problem I see there is I would have to reinitialize the LCD after it is powered up which I guess is no big deal.
 

Markd77

Joined Sep 7, 2009
2,806
An on-chip crystal oscillator circuit is incorporated
between pins OSC1 (input) and OSC2 (amplifier output).
It is enabled by setting the Timer1 Oscillator Enable bit,
T1OSCEN of the T1CON register. The oscillator is a
low-power circuit rated for 32 kHz crystals. It will
continue to run during all power-managed modes.

I guess his means it works during sleep? The next to the last sentence confuses me a bit. Not sure if it means I need a crystal or not.
This means you need a crystal between the pins (+ capacitors to ground). On the PIC12 and PIC16 chips I normally use this is the only timer that runs during sleep except the watchdog timer which has awful accuracy (and varies with voltage and temperature).
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
This means you need a crystal between the pins (+ capacitors to ground). On the PIC12 and PIC16 chips I normally use this is the only timer that runs during sleep except the watchdog timer which has awful accuracy (and varies with voltage and temperature).
That would be pins OSC1 and OSC2. I am already using RA5 to drive my LCD. RA5 and OSC2 are on the same pins, Can I still use RA5?
 

GetDeviceInfo

Joined Jun 7, 2009
2,195
however, your lowest power draw probably comes from a deep sleep with only the watchdog waking, or an external device with lower power demands.

You could use the comparator interrupt to wake, but running that section in sleep has power penalties.
 

Markd77

Joined Sep 7, 2009
2,806
Quote:
Originally Posted by Markd77
This means you need a crystal between the pins (+ capacitors to ground). On the PIC12 and PIC16 chips I normally use this is the only timer that runs during sleep except the watchdog timer which has awful accuracy (and varies with voltage and temperature).

That would be pins OSC1 and OSC2. I am already using RA5 to drive my LCD. RA5 and OSC2 are on the same pins, Can I still use RA5?
It's either oscillator or I/O. In fact you can't use timer1 and RA4 and RA5 at the same time.
Looking at the datasheet, it seems that using the LFINTOSC at 31KHz uses at most 80uA which is a pretty decent power saving and you can use the pins. It's only about twice as much as full sleep mode.
 

maxpower097

Joined Feb 20, 2009
816
Sorry RTC is Run Time Clock. What is the second C in RTCC?
RTC = Real Time Clock
RTCC = Real Time Clock/Calander

Not sure if one just shows time, and the other shows time and date. Or if its the same thing just used differently in different datasheets.
You could then wire in an external RTC like this one to then alert a pin on the pic when its time to wake up and check voltages.
http://cgi.ebay.com/INBOARD-RTC-Cou...ultDomain_0&hash=item1c150cd37d#ht_3431wt_716
You can find a bunch of external RTC's that draw very very low power. I would use one of these and then alert the pic every so often to do work. You can set the RTC to turn a pin on high when the alarm goes off. Then program the pic to detect a certain pin going high as an interupt and thus waking it up.
 
Last edited:

tom66

Joined May 9, 2009
2,595
however, your lowest power draw probably comes from a deep sleep with only the watchdog waking, or an external device with lower power demands.

You could use the comparator interrupt to wake, but running that section in sleep has power penalties.
You could also switch on every second or so, turn on the comparator for a few hundred microseconds, then switch off.
 

maxpower097

Joined Feb 20, 2009
816
You could also switch on every second or so, turn on the comparator for a few hundred microseconds, then switch off.
*** Not trying to hijack thread Its just were both working on RTC projects and could probably help each other out asking questions.

Than being said I thought about going that route. My project needs to goto sleep for 5 min, wake up, check some data, then do something if data matches, or go back to sleep for 5 min. Would I save much power doing it that meathod? Or would polling once a second then sleeping and waking every second save the same amount. If it wouldn't save that much I'd love to poll it every second. I'm just worried about battery life. My project needs to run on battery power for over a year. I guess I could use a dual mode for when its plugged in poll every second but in power failure to poll every 5 minutes. I already plan on killing the LCD backlight on power failure and cut LED's to half power and shorter bursts.
 

GetDeviceInfo

Joined Jun 7, 2009
2,195
the RTC route might be more conservative. Using it's alarm function to wake your controller at some reasonable interval. You could also use it to do your timing functions, rather than the controller, which would be sleeping in the meantime.
 
Top