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