Menu

Sleep command

Help
Moto Geek
2018-06-21
2018-06-21
  • Moto Geek

    Moto Geek - 2018-06-21

    I have a project where I need to be running on batteries (first for me). The project idea is simple, PWM an led from off to full and back to off within a 2 to 3 second period (like its "breathing"), and do this once a minute or up to once every five minutes. To make the unit last a bit longer, I want to put the pic to sleep, do its thing and go back to sleep without user interaction.

    Since this is its only purpose in life, I want to use a small pic, like a 10f or 12f, 6 or 8 pin package. I can not find any information when I search for "sleep" in the GCB help documentation. I did search in the forum and there is a bit of info, some which goes way back, and I'm not very clear on what to do, or if methods have been implemented in the latest compiler versions.

    Is there a "straight forward" tried and true simple method for using the sleep feature of the pic micro where it pretty much just runs in a loop, basically waking itself up, doing it thing, and going back to sleep? Also, since this is a relatively simple operation, can the clock be turned way down to save even more power?

     
  • David Stephenson

    Sleep is easy just put in the line
    SLEEP
    the difficult part is the wakeup.
    I normally do it using a timer. Either the watchdog timer (if you don't need too much accuracy) or an external clock crystal on timer1 (if you want it to the second). You could also use an interrupt pin press.
    If you are running on a battery you also have to make sure that everything that could be taking current is isolated during the sleep phase (measure the current to check it is within spec. during sleep)

     
  • kent_twt4

    kent_twt4 - 2018-06-21

    It is possible that you will want to check the condition of the battery voltage, to make sure that you do not run it down too low (i.e. rechargeable?). If so, then a 10F would need an adc channel like the 10f222. The baseline devices will need to use assembler instructions to maintain minimum use of RAM and program space.

    A more modern 10F would be the midrange 10F322 which adds a couple of hardware PWMs, and Interrput On Change among others.

    An eight pin device like the 12F1571 has the most when compared to the others including four hardware PWMs (RGB led?), four16 bit Timers, much more program space and RAM. I have confirmed extra low power of <1 ua in sleep mode.

    I would not play with the oscillator frequency until all other aspects of conserving current have been exhausted per previous post.

    Here is my sleep routine using the 12f1571 for an rgb led solar light:

    back2sleep:
      clrwdt
      'clears blinkies when entering sleep
      Red_Duty = 0
      Green_Duty = 0
      Blue_Duty = 0
      PWM1LDCON.LDA = 1
      PWM2LDCON.LDA = 1
      PWM3LDCON.LDA = 1
      If savebat = True then
        savebat = False
        'FirstEntry = True
        bcf PWM1CON,EN
        bcf PWM2CON,EN
        bcf PWM2CON,EN
        nop
        nop
        clrwdt
        asm sleep
        nop
      End If
    goto Main
    
     
  • Moto Geek

    Moto Geek - 2018-06-21

    Thanks for that info. Kent when you put your setup to sleep, how do you wake it back up to do its thing? For what I have in mind, there will be no user interaction other that having to change the batteries once they die. Do you use the WDT to wake it up?

     
  • kent_twt4

    kent_twt4 - 2018-06-21

    Moto, yes used the WDT to wakeup. On the 12f1571 there is a Software WDT, and used that, because I thought that the hardware WDT did not work as well at low voltages. There is the low voltage or "LF" version which might better fit your battery profile?

    Watchdog stuff:

    #config MCLRE=OFF, WDTE=SWDTEN, BOREN=OFF
    ...
    ...
    'WDTCON = b'00100101'    '256 sec, SWDTEN
    'WDTCON = b'00010111'    '2 sec, SWDTEN
    WDTCON = b'00011001'    '4 sec, SWDTEN
    'WDTCON = b'00011011'    '8 sec, SWDTEN
    'WDTCON = b'00011101'    '16 sec, SWDTEN
    
     

Log in to post a comment.