
Watchdog Timer Functionality in Microcontrollers
Explore the significance of the watchdog timer in microcontrollers, its role in preventing infinite loops, and how to initialize or disable it effectively. Dive into practical implementation and observe its behavior in action.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
ECE 3567 ECE 3567 Lab 9 Lab 9 The Watchdog Timer The Watchdog Timer Mustafa Ridvan Cantas Dr. Gregg J Chapman Autumn 2020 1
Lab Overview Activate default Watchdog Timer. Use Watchdog Timer as watchdog timer. Use the Watchdog Timer as interval timer.
Disabling The Watchdog Timer // Disable Watchdog counter WDT_A_hold(WDT_A_BASE); WDTCTL = WDTPW|WDTHOLD; WDTCTL =0x5A80;
The Watchdog Timer Watchdog timer is a safety feature to reset microcontroller if the program stuck in an infinite loop. When we enable watchdog, it can be used in two different ways: 1. Watchdog timer 2. Interval timer To set watchdog timer we need to set WDTCTL register. Family User's Guide, page 634
Checkpoint 1: Checkpoint 1: Download & Run the Code Download & Run the Code Download Lab9A from the web site. Create a new project Lab9A & copy the downloaded starter .c and .h files into your project. Run the code. What to expect: When you run the code you will see the green LED is lid for 5 seconds. Then red and green LEDs will alternate continuously.
Checkpoint 2: Checkpoint 2: Observe the default setting of the WDT Observe the default setting of the WDT Until this lab the watchdog timer was disabled by: WDT_A_hold(__MSP430_BASEADDRESS_WDT_A__); Comment out or delete this code line to observe behavior of WDT. What to expect: When you run the code you should see the green LED is lid continuously. Because WDT is not cleared, it will restart the code periodically until it is cleared.
Watchdog Timer Initialization To initialize watchdog timer you are going to set the WDTCTL register: Set password by changing WDTPW fields (Bit 15-8) 5Ah in WDTCTL register. Stop Watchdog Timer by setting WDTHOLD field. Choose the clock source as ACLK by changing WDTSSEL field. Select watchdog mode by changing WDTTMSEL field. Clear watchdog timer counter by setting WDTCNTCL. Select clock divider as Watchdog clock source/219 by setting WDTIS field properly. This will set the watchdog timer interval as 16 seconds.
Start Watchdog Timer To start the watchdog timer you need to clear WDTHOLD field in WDTCTL register. This can be done by using TI macro: WDT_A_start(WDT_A_BASE);
Reset Watchdog Timer To start the watchdog timer you need to clear WDTCNTCL field in WDTCTL register. This can be done by using TI macro: WDT_A_resetTimer(WDT_A_BASE);
Checkpoint 3 Checkpoint 3 Use the Watchdog Timer in Watchdog Timer Mode Use the Watchdog Timer in Watchdog Timer Mode Here are the steps: Initialize watchdog timer with ACLK and clock divider 219 in watchdog timer mode. You are expected to calculate a single hex number for WDTCTL register. Start the watchdog timer before the main while loop. Reset the watchdog timer every second. What to expect: For 5 seconds green LED will stay lid. Then, LEDs will alternate between red and green continuously. Observe the LEDs at least 30 seconds.
Watchdog Timer Initialization for Interval Timer Mode To initialize watchdog timer you are going to set the WDTCTL register: Set password by changing WDTPW fields (Bit 15-8) 5Ah in WDTCTL register. Do not stop the Watchdog Timer by setting WDTHOLD field to 0. Choose the clock source as ACLK(32.768kHz) by changing WDTSSEL field. Select interval timer mode by changing WDTTMSEL field. Clear watchdog timer counter by setting WDTCNTCL. Select clock divider as Watchdog clock source/215 by setting WDTIS field properly to achieve 1 second intervals.
Checkpoint 4 Checkpoint 4 Use the Watchdog Timer in Interval Timer Mode Use the Watchdog Timer in Interval Timer Mode Download Lab9B from the web site. Create a new project Lab9B & copy the downloaded starter .c and .h files into your project. Implement the alternating LEDs with WDT Interval Timer Mode: Initialize the watchdog timer with ACLK and clock divider 215 in interval timer mode. You are expected to calculate a single hex number for WDTCTL register. Enable WDT Interrupt. Write WDT Interrupt service routine. As a function name use watchdog_timer . In the WDT ISR set ISR_Flag_WDT to 1 . What to expect: Red and green LEDs will alternate continuously with 1 second interval.
Submission Code Submission: Copy main.c files for Checkpoint 3 and Checkpoint 4 into a single docx file. Checkpoint Submission (for Online Section): Compress both Lab9A and Lab9B projects into a single zip file.