The MC9RS08KA1 & MC9RS08KA2 watchdog timer.

The watchdog timer (Freescale named it COP Computer Operate Properly)can only cause the System Reset of the device and it has not the interrupt generation capability.

The watchdog timer operates from an on chip oscillator running at 1 Khz. There are two possible timeout values short and long, that can be selected by COPT bit in the SOPT, (note that this register is write-once to ensure the safety of the system.) The possible timeout values are illustrated in the following table:

COPT

Cop Overflow (in cycle)

0

2^5 cycles (32 ms)

1

2^8 cycles (256 ms)

 

To enable the watchdog timer, the COPE bit of the SOPT (System Options Register) register needs to be set to a logical 1. During the reset initialization the user needs to write to the write-once SOPT register to lock the setting even if the default watchdog values are used. This initial write will reset the watchdog timer and will lock it (it’s not possible to disable the watchdog timer if it is enabled after a SOPT write).

The refresh operation is done writing any value to the SRS (System Reset Status Register). Any write operation in the SRS register doesn’t alter the SRS content, but only refresh the watchdog counter.

The watchdog counter is re-initialized to zero upon entry to stop mode and the counter begins from zero after the MCU exits stop mode.  In background mode the watchdog counter is suspended.

The operation used to enable/disable the watchdog counter and to set up one of the timeout values is the following one:

1- Set, in the same instruction, the COPE bit (a logical 1 to enable, a logical 0 to disable) and COPT bit (according to the timeout) of the SOPT register, to the proper values.

To identify if the last reset was due to the watchdog timer, at the startup check if the COP bit of the SRS register is set.

 

MC9RS08KA1/MC9RS08KA2 example

The following example shows how to use the watchdog timer of the KA1/KA2  devices.  The example was built using the CodeWarrior 6.1 C compiler.

The KA1/KA2 runs from internal clock and the PORTA pin 0  is connected to a led. At the startup the application checks if last system reset was due to watchdog. If the System reset was due to watchdog, the application turns on the led and wait forever otherwise the application turns on/off for 10 times the led resetting the watchdog timer. After the tenth refresh, the application stops to refresh the watchdog, so the microcontroller will reset. At the next startup the application turns on indefinitely the led .

 To change the watchdog timer long/short timeout setting change the COPT bit of the SOPT register value in the PeriphInit function.

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

// Init the K1 modules

void PeriphInit(void)

{

       /* Watchdog setting ( 256 ms) :

             1- long timeout COPT=1 (SOPT)

             2- enable the watchdog COPE = 1 (SOPT)

       */

       SOPT = SOPT_BKGDPE_MASK | SOPT_COPT_MASK | SOPT_COPE_MASK;

       // Configures PTA0 as output LED

       PTAD = 0x00;

       PTADD = 0x01;

       // Configures ICS clock.

       ICSC2 = 0x00;

       ICSC1 = 0x04;

       // Waits until output FLL is selected (CLKST=00)

       while (ICSSC & 0x0C)

       ;

}

void main(void)

{

       int i,j, iWatch = 0;

       /* disable interrupts

        */

       DisableInterrupts;

       if ( SRS & SRS_COP_MASK)

       {

             // Configures ICS clock.

             ICSC2 = 0x00;

             ICSC1 = 0x04;

             // disable the watchdog

             SOPT &= 0x7F;

             // Waits until output FLL is selected (CLKST=00)

             while (ICSSC & 0x0C);

             // Configures PTA0 as output LED

             PTAD = 0x00;

             PTADD = 0x01;

             // Toggles the LED (On)

             PTAD |= 0x01;

             for(;;)

             {

             };

       }

       /* Init the K1 modules

        */

       PeriphInit();

      

       EnableInterrupts;

       for(;;) // Forever

       {

             iWatch++;

             // refresh the watchdog timer until the iWatch counter is less than 10

             if (iWatch < 10)

                    __RESET_WATCHDOG();

             // Toggles the LED (On)

             PTAD |= 0x01;

             // Waits some times

             for (i=0; i<20000; i++)

                    j = -1+i+1;

             // Toggles the LED (Off)

             PTAD &= 0xFE;

             //Waits some times

             for (i=0; i<20000; i++)

             j = -1+i+1;

       }

/* please make sure that you never leave main */

}