Nap and sleep commands


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce ,
    with a little playing around got that to work the way i need it to. The only thing to do now then is that this program has 2 "sleep" modes .
    1 that sleeps for 1 second which using code Bruce helped with works fine, but i had the other sleep mode which runns for around 8 hrs using a PBP "Sleep 28800" i.e sleep for 28800 seconds = 8 hrs . Obviously i am trying to save as much power during this sleep as possible, so rather than use the PBP sleep command is there a more efficent way of doing this long sleep using ASM Sleep, do i have to set my watchdog prescaler for as big as it goes and count how many times it wakes up ? i belive the largest prescale time i can set is 65536 which would equate to 2.11 seconds , dosent seem logical to have it wake up every 2 seconds advance a counter then sleep again..
    Am i better off just using the PBP sleep ? or am i missing something ?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    i need to do another function that basicly flashes a led on for 50ms then off again aprox every second.
    This is what the code example above does.

    If you need it to sleep longer just set the prescaler for the watchdog timeout period in WDTCON to 65536, then set the 2nd prescaler in OPTION_REG to 1:128.

    Then it will sleep a lot longer, but it's not going to be able to blink your LED every 1 second. It will be sleeping for the entire 270 second period. If you need even longer, then you could let it sleep for ~270 seconds, wakeup, increment a variable, then go back to sleep.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Similar issue on 18F4550

    I am also trying to minimise power consumption on a 18F4550 which connects to a PC via USB, but for >24 hours I need it to sample the ADC and store to external I2C memory with lowest current on battery only (USB disconnected)- present setup uses 42 mA and only lasts 9 hours - not enough - I have tried to adapt your answer for the 18F4550:
    Code:
    Development:
    DEFINE NO_CLRWDT 1
                lcdout $FE, $C0, "USB Low Power   "
                
                T0CON.7 = 0     ' Disable USBservice interrupts TMR1 still running @ 25 Hz
    '            UCON.1 = 1     'UCON not defined in PBP 2.46
    @	clrf	UCON			; Disable USB & detach from bus
    @	clrf	UIE  			; Mask all USB interrupts
    @	movlw	DETACHED_STATE
    @	movwf	usb_device_state
    
    lowpower:   IF dSecs = 1 THEN  
                    dSecs = 0
                    lcdout $FE, $02, "Time ", dec2 Hours, ":", dec2 Minutes, ":", dec2 Seconds, "   "
                ENDIF
                ' Do all the other stuff here (read ADC, store to Mem) 
                CLEARWDT
    'CONFIG2H = %00011111 ' WDT enabled with a period of 32768 * (1/31kHz) - PO default - cant access easily
                WDTCON = 1
    @ SLEEP            ' for a sleep period of about 1.057 seconds
    @ NOP              ' Execute a NOP on WDT or interrupt wakeup
                WDTCON = 0         ' Disable WDT when not needed for power savings.
                goto lowpower
    But no joy - sleeps but never wakes up!!!
    I am (sadly) using PBP 2.46 (waiting for 2.60 to arrive) and am using DT_INTS with a 100 mSec interrupt to keep USBservice'd (on TMR0, turned off here) and a 40 mSec interrupt on TMR1 to update the clock (which I need))
    I have tried using TMR1 to wake from sleep but no joy there either. OSC 48

    Any help would seriously help my follicular challenge! TIA
    Peter
    ps I am running TMR1 at 25 Hz - the slowest I can go on the 18F4550 as max prescaler is 1:8 - Is this interfering with the WDT - I have never really got to grips with the WDT and I have read the manual but cant make head nor tail of it!

  4. #4
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default ?Answered my own question

    Well, I carried on trying and reread the Datasheet - It states
    The power-managed Sleep mode in the PIC18F2455/2550/4455/4550 devices is identical to the legacy Sleep mode offered in all other PIC devices. It is entered by clearing the IDLEN bit (the default state on device Reset) and executing the SLEEP instruction.
    I tried making IDLEN = 0 which is what I understand by clearing it - no good, BUT making IDLEN = 1 does work - at least the RTC display is updated so the PIC must be coming out of sleep with Timer 1 and is sleeping (some) as the current consumption drops from 42 mA to 26 mA. Not sure it is definitely cracked but seems to be - now to try and eek out more power consumption. I would still value wiser PIC'ers opinion though?
    Code:
    Development:
                lcdout $FE, $C0, "USB LP, SEC_IDLE"
                T0CON.7 = 0     ' Disable USBservice interrupts
    '           UCON.1 = 1      ' UCON not defined in PBP 2.46
    @	        clrf	UCON	; Disable USB & detach from bus
    @	        clrf	UIE  	; Mask all USB interrupts
    lowpower:   IF dSecs = 1 THEN  
                    dSecs = 0
                    lcdout $FE, $02, "Time ", dec2 Hours, ":", dec2 Minutes, ":", dec2 Seconds, "   "
                ENDIF
                OSCCON.7 = 1     '"Clear" IDLEN - Set surely?
    @           SLEEP
    @           NOP
                goto lowpower
    Any comments guys?

  5. #5
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    OK - it IS late but I am now starting to understand the Datasheet - I am switching into an Idle state, not a sleep by using
    Code:
                 OSCCON.7 = 1     'Set IDLEN - switch to SEC_IDLE
    if I use
    Code:
                 OSCCON.7 = 0     'Clear IDLEN - switch to SLEEP
    the PIC goes to sleep but wont wake up on Timer 1 interrupt. The consumption does drop to 15 mA.
    Help please!!! How can I get Timer 1 to wake the Pic from sleep?

    I am going to sleep now - hope my Timer 1 wakes me! My anaesthetist friends tell it is easy to put someone to sleep - the skill is in getting them to wake up afterwards - guess that is true of Pics too!

    Peter

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you don't want to use a power managed mode with peripherals clocked during sleep, use an external 32,768 watch crystal for Timer1.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Jun 2005
    Location
    Surrey, England
    Posts
    35


    Did you find this post helpful? Yes | No

    Default

    Thanks for your help Bruce - it has clarified my (mis)understanding - looks like an external Xtal for Timer 1 is the way to go.
    BTW in case anyone is mislead by:
    Also Timer1/Timer0 will only operate from the internal clock during sleep if you're using a power managed mode that clocks peripherals while the CPU sleeps
    into thinking Timer0 could be used to wake the 18F4550 from sleep, I noticed this in the datasheet:
    Since Timer0 is shut down in Sleep mode, the TMR0 interrupt cannot awaken the processor from Sleep.
    I would have preferred to use timer0 for my clock as I could get that down to 1 Hz with its 1:256 prescaler otherwise . I suppose this is probably also true of Timer1 (without external Xtal) and should have given me the answer Bruce so clearly gave!
    Peter

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    WDT on the 4550 has a 4mS period. With the postscaler set to 32,768, you have about 2.18 minutes before it will wakeup.

    Also Timer1/Timer0 will only operate from the internal clock during sleep if you're using a power managed mode that clocks peripherals while the CPU sleeps.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts