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

    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

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


    Did you find this post helpful? Yes | No

    Default

    Since our production circuit board has been professionally produced, there is not room for an extra Xtal and caps to drive TMR1 so I am trying to get the WDT to do the wake from sleep but with only partial success. In particular it doesnt seem to matter what I put as a postscaler value the WDT seems to cycle at a fixed period of around 578 mSec (suspiciously similar to Nap 5 frequency!). I am setting CONFIG2H by using this instead of the corresponding (commented out) line in 18F4550.INC:
    Code:
    asm
           __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_256_2H
    ;must comment out in 18F4550.INC, or change there, else duplicate error
    endasm
    and then:
    Code:
                i = 0
    lowpower:   lcdout $FE, $02, "WDT ", hex2 i, 
                i = i + 1
                ' Do all the other stuff here (read ADC, store to Mem) 
                clearwdt
                WDTCON = 1       'SWDTEN
    '           OSCCON.7 = 0     'Clear IDLEN - switch to SLEEP 
                OSCCON.7 = 1     'Set IDLEN - switch to SEC_IDLE
    @           SLEEP 
    @           NOP  
                WDTCON = 0    ' WDT off
                goto lowpower
    and i increments 128 in 74 secs (period = 578mSec), but different values of _WDTPS_1024_2H etc. make no difference. What am I missing here? It makes no difference whether I make the CPU sleep or idle (except to the current consumption 3 or 15 mA - most of the 3 lost in the 9v voltage regulator).
    DEFINE NO_CLRWDT 1 makes no difference and the CLEARWDT also seems to make no difference!

    I would like to have the ability to control the frequency as expected and am thinking I can sleep for most of the 1 second I want and fine tune with another timer while awake - PAUSE would be the simplest. Any ideas gratefully received!

    Peter

    PS It just occurs to me that I am using a Bootloader - could this mean that the Postscaler is set by the bootloader and not changed by my program - if so can I do anything to change this ??edit the bootloader somehow.
    Last edited by FinchPJ; - 25th August 2010 at 21:36. Reason: Postscript

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


    Did you find this post helpful? Yes | No

    Default

    Most bootloaders will not allow you to change config settings, but the Microchip USB loader will, or you can change WDT config settings at runtime.

    See these threads:

    http://www.picbasic.co.uk/forum/showthread.php?t=4093

    http://www.picbasic.co.uk/forum/show...ghlight=config

    Or just open the loader .HEX file, make your changes, save it, and reprogram the PIC with the new loader firmware.
    Last edited by Bruce; - 26th August 2010 at 19:09.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Now that is seriously helpful - Sorry I didnt spot those earlier on my searches - thank you so much for your help Bruce (and Darrel) - you are amazing!

    Peter

Members who have read this thread : 0

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