Nap and sleep commands


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    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!

  2. #2
    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?

  3. #3
    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

  4. #4
    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

  5. #5
    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

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


    Did you find this post helpful? Yes | No

    Default

    Sleep & Power managed modes can be a little confusing.

    With IDLEN = 0 the SLEEP instruction shuts down everything except for the watchdog timer if it's enabled. This stops all internal clocks by stopping the main oscillator. The internal 31kHz that the WDT uses is still operating so the WDT can timeout and wake it from sleep.

    PRI_RUN, SEC_RUN, and RC_RUN are the only 3 modes that don't require execution of the SLEEP command to enter.

    These are selected by changing bits in the OSCCON register. These modes let you change the oscillator. SEC_RUN would switch to the oscillator on Timer1.

    This keeps everything running, but on the lower power osc that's connected to the Timer1 osc pins.

    RC_RUN switches to the internal RC oscillator. Both can consume less power than most external crystals. PRI_RUN operates from whatever oscillator you have selected in config.

    The IDLE modes PRI_IDLE, SEC_IDLE, and RC_IDLE are entered by setting the IDLEN bit, then selecting the oscillator with OSCCON bits 1,0 then executing the SLEEP instruction. If you already have the oscillator selected for the idle mode you want, then just setting IDLEN before executing the SLEEP instruction is all that's required.

    IDLE modes just put the CPU to sleep, but keep clocks available for all peripherals.

    SEC_IDLE or RC_IDLE would normally be the lowest power options. It would run all peripherals from the LP oscillator on Timer1, or the internal RC oscillator "set for 31kHz".

    Look in the Electrical Characteristics section of the datasheet under Power-Down and Supply Current for various modes & power consumption.

    The key is the IDLEN bit. When this bit is clear, it doesn't matter what oscillator or mode is selected. The execution of a SLEEP instruction will shut everything down except for the WDT if enabled.

    When the IDLEN bit is set, and the SLEEP instruction is executed, then it enters one of the 3 IDLE modes with the CPU shut down, and peripheral clocks provided by whatever osc you have selected in OSCCON bits 1,0.
    Last edited by Bruce; - 21st August 2010 at 16:03.
    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 all your help Bruce - this is a followup to report that an external 32 KHz crystal and two 33 pF caps have sorted my sleep problems - for the record this works a dream:
    Code:
        T1CON   =   %00001110
    with a TMR1 interrupt (RTCupdate) of:
    Code:
    asm
    TMR1Const = 8000h
    ADD2_TMR1   macro
                BCF     T1CON,TMR1ON, 0     ; Timer OFF
                MOVLW   LOW(TMR1Const)      ; +1
                ADDWF   TMR1L,F, 0          ; +1
                BTFSC   STATUS,C            ; +1/2
                INCF    TMR1H,F, 0          ; +1
                MOVLW   HIGH(TMR1Const)     ; +1
                ADDWF   TMR1H,F, 0          ; +1
                endm
    RELOAD_TMR1 macro
                ADD2_TMR1
                BSF     T1CON,TMR1ON, 0     ; +1=7 cycles overhead before Timer ON
                endm
    LOAD_TMR1   macro
                MOVE?CT  0, T1CON,TMR1ON
                MOVE?CB  0, TMR1L
                MOVE?CB  0, TMR1H
                ADD2_TMR1
                endm
    endasm
    RTCupdate:
    @      RELOAD_TMR1
           Seconds = Seconds + 1
           dSecs = 1
           if (Seconds < 60) then IHdone
           Minutes = Minutes + 1
           Seconds = 0
           if (Minutes < 60) then IHdone
           Hours = Hours + 1
           Minutes = 0
           if (Hours < 24) then IHdone
           Days = Days + 1
           Hours = 0
    IHdone:                     'Restore context and RETFIE
    @   INT_RETURN
    and a sleep inducing routine of:
    Code:
    gosleep:
                lcdout $FE, $C0, "USB LP, SLEEP   "
                T0CON.7 = 0     ' Disable USBservice interrupts
    @           INT_DISABLE TMR0_INT
    @	        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 = 0     'Clear IDLEN - switch to SLEEP 
    @           SLEEP
    @           NOP
                goto lowpower
    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