PDA

View Full Version : Watchdog periodic wakeup



jimbostlawrence
- 15th August 2012, 13:19
Hi all,

The solution to this is probably very straightforward but I'm trying to use the watchdog as a wakeup timer based on the roughly 4ms 'no postscaler (=1)' setting...

The inc file is as follows:


NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F26J53, r = dec, w = -311, f = inhx32
INCLUDE "P18F26J53.INC" ; MPASM Header
CONFIG XINST = OFF
CONFIG PLLDIV = 2;
CONFIG WDTPS = 16;
CONFIG WDTEN = ON
CONFIG OSC = HSPLL; INTOSCPLL
CONFIG ADCSEL = BIT12
CONFIG RTCOSC = T1OSCREF
CONFIG IESO = OFF
CONFIG CFGPLLEN = ON
CONFIG CPUDIV = OSC1
CONFIG CLKOEC = OFF
CONFIG SOSCSEL = LOW
CONFIG DSBOREN = OFF
NOLIST
endif
LIST
BLOCK_SIZE EQU 64

...whilst the PBP program is:



Include "modedefs.bas"

DEFINE OSC 24

ancon0 = %11111111
ancon1 = %00011111

intcon = 0
intcon2 = %11110101
intcon3 = %00000000

blue_led var portb.2
red_led var portb.1

ADCON0.0 = 0
ADCON1 = 15

trisa = %00000000
trisb = %10100000
trisc = %00000000

pmdis0 = %11111101
pmdis1 = %11111101
pmdis2 = %11111111
pmdis3 = %11111111
WDTCON.0 = 1

main:
high red_led
low blue_led
sleep 5
@ nop
high blue_led
low red_led
sleep 5
@ nop
goto main

Essentially, I just want the board to go to sleep minimising current but wakeup every 4 ms or so, switch and LED, or do something, and go back to sleep.

But... the LED switching frequency seems to be a function of the SLEEP value as opposed to the WDT postscaler value. I assumed that once the device was asleep, that was it fo rthe SLEEP command and when it woke up, it was past that, through the NOP command and onto the next line of code... and hence the value of the SLEEP command was meaningless....
i.e. if I set the sleep values to SLEEP 1, the LED switching frequency is far quicker than for SLEEP 5...

Please help...

Regards

Jimbo

pedja089
- 15th August 2012, 13:23
Use @ SLEEP
PBP SLEEP will override your wdt settings.

jimbostlawrence
- 15th August 2012, 13:33
ARGHHHHHHHHHHHHH it was THAT simple?!

:) ok, now I'm smiling!

Many thanks... I think that answers other questions that have been bubbling away in the back of my mind with other projects!

And thank you for being so quick! I literally went to make a coffee, returned and refreshed and there it was. :)

pedja089
- 15th August 2012, 13:44
Glad I could help.