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:
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
Bookmarks