Objectives:: Watchdog Timers (WDTS) Are Particularly Useful Because They Detect If A Microcontroller Is in
Objectives:: Watchdog Timers (WDTS) Are Particularly Useful Because They Detect If A Microcontroller Is in
Implement a code in which watchdog timer is used and also perform the function
of pushbutton switch which glow the leds.
Discussion:
Six 16/32-bit and Six 32/64-bit Function timers.
Twelve 16/32-bit and Twelve 32/64-bit capture/compare/PWM pins
Timer modes:
One-shot
Periodic
Input edge count or time capture with 16-bit prescaler
PWM generation (separated only)
Real-Time Clock (concatenated only)
Count up or down
Simple PWM (no deadband generation)
Support for timer synchronization, daisy-chains, and stalling during debugging
May trigger ADC samples or DMA transfers
Watchdog timers (WDTs) are particularly useful because they detect if a microcontroller is in
an invalid software state and initiate a reset if needed. These invalid software states can be
caused by anything from a software bug to electromagnetic interference. In general, a WDT
resets the system when it does not receive a regular pulsed signal from the host processor.
In critical systems, such as smoke detectors and other industrial applications, an invalid software
state could be catastrophic. In these instances, an external WDT would be imperative. The
external WDT has a separate clock source providing redundancy and making the system more robust.
Included in all devices (newer ones have the enhanced watchdog timer+).
Its main function is to protect the system against malfunctions but it can instead be used
as an interval timer if this protection is not needed.
The main purpose of the watchdog timer is to protect the system against failure of the
software, such as the program becoming trapped in an unintended, infinite loop.
Left to itself, the watchdog counts up and resets the MSP430 when it reaches its limit.
The code must therefore keep clearing the counter before the limit is reached to prevent a
reset.
Code:
#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h" // for GPIO Port Base
#include "inc/hw_types.h" // needed for HWREG for locking HW
#include "driverlib/watchdog.h"
#include "driverlib/rom.h"
// ADC functionality
#include "driverlib/adc.h"
// PWM functionality
#include "driverlib/pwm.h"
#define LED_OFF 0
void WatchdogIntHandler(void)
{
// If we have been told to stop feeding the watchdog, return immediately
// without clearing the interrupt. This will cause the system to reset
// next time the watchdog interrupt fires.
//
if(!g_bFeedWatchdog)
{
return;
}}
ROM_WatchdogIntClear(WATCHDOG0_BASE);
uint32_t TIMER_0_Period;
int main(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//
//
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
IntMasterEnable();
ROM_IntEnable(INT_WATCHDOG);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|
SYSCTL_XTAL_16MHZ);
//
// Set the period of the watchdog timer.
//
ROM_WatchdogReloadSet(WATCHDOG0_BASE, ROM_SysCtlClockGet());
//
// Enable reset generation from the watchdog timer.
//
ROM_WatchdogResetEnable(WATCHDOG0_BASE);
//
// Enable the watchdog timer.
//
ROM_WatchdogEnable(WATCHDOG0_BASE);
TimerEnable(TIMER0_BASE, TIMER_A);
// Loop forever:
while(true)
{ while(true){
int curr_time=flag;
while(GPIOPinRead(GPIO_PORTJ_BASE,SW_1))
{
if(flag-curr_time>3)
flag2=true;
}
if (GPIOPinRead(GPIO_PORTJ_BASE,SW_1))
{
value++;
SysCtlDelay(2000);
}
SysCtlDelay(20000);
if(value==2||value==4|| value==6){
break;
}
else
{
value=0;
}
}
if(flag2){
GPIOPinWrite(GPIO_PORTN_BASE,LED_1,1);
SysCtlDelay(200000);
GPIOPinWrite(GPIO_PORTN_BASE,LED_1,0);
g_bFeedWatchdog=false;
}
if(value==2)
{
GPIOPinWrite(GPIO_PORTN_BASE,LED_1,1);
value=0;
}
else if (value==4)
{
GPIOPinWrite(GPIO_PORTN_BASE,LED_2,1);
value=0;
else if (value==6)
{
GPIOPinWrite(GPIO_PORTN_BASE,LED_3,1);
value=0;
}
TimerDisable(TIMER0_BASE, TIMER_A);
}
////////////////////////////////////////////////////////////////
//////////////////////
////////////////////////
///////////////////////////////////
////////////////////////////////////////////////////////////////////