Improving my project with sleep?

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Oct 4, 2010.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002
    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.
     
  2. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    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.
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  5. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002
    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?
     
  6. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    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.
     
  7. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002


    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.




    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.
     
  8. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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).
     
  9. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002
    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?
     
  10. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    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.
     
  11. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  12. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    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: Oct 6, 2010
  13. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    You could also switch on every second or so, turn on the comparator for a few hundred microseconds, then switch off.
     
  14. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    *** 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.
     
  15. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002

    So if I understand ypu correctly, implement my on pseudo sleep mode? Power up the ADC only when needed?
     
  16. GetDeviceInfo

    Senior Member

    Jun 7, 2009
    1,571
    230
    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.
     
  17. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002
    I completely redesigned the circuit and PCB last night. :) I added in the crystal.
     
  18. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Will this be your first interrupt service routine(ISR) programming attempt?
     
  19. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002
    First time with a PIC but I have messed with ISRs way back when I had a PET and an Atari. Messed with them a bit on the PC too.
     
  20. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    WOAH... Do you still have the PET?

    [​IMG]
     
Loading...