I've read that it is possible to 'stack' SLEEP commands on a PIC so if, for example, you want a short watchdog timeout but a longer sleep period you can just use multiple SLEEPs and when the watchdog wakes from the first the processor will just see the next and go straight back to sleep.
I've got all interrupts disabled and nothing that would wake the unit from sleep other than the watchdog.
My code works fine with a single SLEEP. As soon as I add a second the processor resets as soon as the powerdown code executes.
Anyone got any ideas?
Even more oddly, I've read the status of RCON and the bits suggest a power-on reset!
Very occasionally I don't get this reset immediately but when this happens, the unit does not respond to the inputs which exit power-down mode. It's almost as if it has locked up. Usually the reset does happen within a few tens of seconds when this happens.
My code is:
Code: Select all
OSCTUNE = 0 // Disable PLL OSCCON = %00000000 // Select 31kHz oscillator WPUB = PowerDownPullUps // Enable battery status and in/lever pull-ups only While true INTCON2.7 = 1 // Disable pull-ups Asm Sleep // Sleep processor until Watchdog wakes it Sleep // Multiple sleep commands extend the period of maximum power saving. End Asm ClrWDT INTCON2.7 = 0 // Global Enable pull-ups If BattStat1 <> BattStat2 Then Break EndIf // Battery charging or full, move back in to active mode. If LeverSwitchPos <> Switch3 Then Break EndIf // Lever has changed, back to active mode Wend ClrWDT OSCCON = %01110000 // Ramp oscillator up to 16MHz OSCTUNE = %01000000 // Enable PLL so we are running at 64MHz