Tutorial 5: Watchdog Timeout and Wakeup from sleep

The watchdog timer is a an onboard timer which when it overflows will cause the processor to reset. The watchdog timer is configured as enabled or disabled in the properties of the PICMICRO. The Watch Dog Timer needs to be enabled because by default it is disabled. In this tutorial, both modes of WatchDog timer are demonstrated. When first run, the powerUp reset will set the /PD Powerdown STATUS<3> bit. This causes PORTB to be set, the watchdog timer is then configured without a prescalar and the processor falls asleep. After 18 milliseconds of simulated real-time (which can take several seconds of real real time) the processor(s) wake up. This time because a wakeup from sleep has occured the /PD Powerdown STATUS<3> bit is cleared. This is detected and a port incrementor routine starts which increments PORTB every millisecond. When entering the incrementor routine the Watchdog timer is configured to use a 1:2 prescalor. Thus after 36 milliseconds of simulated real time the watch dog timer times out causing a reset. When a reset occurs due to a watchdog timeout in normal operation the /PD Powerdown STATUS<3> bit is set which causes the sleep routine to be called restarting the loop.

Download FEATURE5X_Tutorial5.zip and unzip into folder <your path>\Tutorial 5

Filename Version Description
tut5.pjt 1.0 MPLAB Project
tut5.asm 1.0 PIC16C5X Assembler code
tut5.hex 1.0 Precompiled HEX
tut5.lst 1.0 Precompiled LST
tut5.vbb 1.0 Virtual Breadboard simulation

Running the Simulation

Open tut5.vbb and press RUN.

Code Walk Through

 

Note(V1.1): The asm file is compiled only for the pic16C54 but will run on any of the PIC16C5X devices. However when loading the file, Virtual Breadboard will detect the list = p16C54 line in the .lst source code and will warn that there is a processor mismatch. The warning does not effect the execution of the code.

Features Demonstrated

TRISB/PORTB

Watchdog Timer

Watchdog Timer Prescalar

Watchdog Timer reset on timeout

Watchdog Timer wakeup from sleep

Components Used

PIC16C54

PIC16C55

PIC16C56

PIC16C57

LED8