Bird
Raised Fist0
Embedded Cprogramming~10 mins

Watchdog timer operation in Embedded C - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start the watchdog timer.

Embedded C
WDTCTL = [1];  // Start watchdog timer with password and interval
Drag options to blanks, or click blank then click option'
AWDTPW | WDTCNTCL | WDT_MRST_32
BWDTPW | WDTHOLD | WDT_MRST_32
CWDTPW | WDTCNTCL | WDT_MRST_64
DWDTPW | WDTHOLD
Attempts:
3 left
💡 Hint
Common Mistakes
Using WDTHOLD stops the watchdog timer instead of starting it.
Forgetting to include the password WDTPW causes the write to fail.
2fill in blank
medium

Complete the code to reset (kick) the watchdog timer inside the main loop.

Embedded C
while(1) {
    // Your code here
    [1];  // Reset watchdog timer
}
Drag options to blanks, or click blank then click option'
AWDTCTL = WDTPW | WDTHOLD | WDT_MRST_32
BWDTCTL = WDTPW | WDTHOLD
CWDTCTL = WDTPW | WDTCNTCL | WDT_MRST_64
DWDTCTL = WDTPW | WDTCNTCL | WDT_MRST_32
Attempts:
3 left
💡 Hint
Common Mistakes
Using WDTHOLD stops the watchdog timer instead of resetting it.
Not including the password WDTPW causes the reset to fail.
3fill in blank
hard

Fix the error in the watchdog timer stop code.

Embedded C
void stop_watchdog() {
    WDTCTL = [1];  // Stop watchdog timer
}
Drag options to blanks, or click blank then click option'
AWDTPW | WDTCNTCL
BWDTPW | WDTHOLD
CWDTPW | WDT_MRST_32
DWDTHOLD | WDTCNTCL
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the password WDTPW causes the stop command to be ignored.
Using WDTCNTCL clears the counter but does not stop the timer.
4fill in blank
hard

Fill both blanks to configure the watchdog timer interval and mode.

Embedded C
WDTCTL = WDTPW | [1] | [2];  // Configure watchdog timer
Drag options to blanks, or click blank then click option'
AWDTCNTCL
BWDTHOLD
CWDT_MRST_64
DWDT_MRST_128
Attempts:
3 left
💡 Hint
Common Mistakes
Using WDTHOLD stops the timer instead of configuring it.
Choosing the wrong interval bits causes unexpected timer behavior.
5fill in blank
hard

Fill all three blanks to create a safe watchdog reset function with stop and start.

Embedded C
void reset_watchdog() {
    WDTCTL = WDTPW | [1];  // Stop watchdog
    // Some critical code here
    WDTCTL = WDTPW | [2] | [3];  // Restart watchdog
}
Drag options to blanks, or click blank then click option'
AWDTHOLD
BWDTCNTCL
CWDT_MRST_32
DWDT_MRST_128
Attempts:
3 left
💡 Hint
Common Mistakes
Not stopping the watchdog before critical code can cause unwanted resets.
Forgetting to clear the counter when restarting causes immediate reset.

Practice

(1/5)
1. What is the main purpose of a watchdog timer in embedded systems?
easy
A. To provide power to the microcontroller
B. To increase the processing speed of the CPU
C. To reset the system if the program stops responding
D. To store data temporarily during program execution

Solution

  1. Step 1: Understand watchdog timer function

    A watchdog timer monitors the program to detect if it stops responding or freezes.
  2. Step 2: Identify watchdog timer action

    If the program fails to reset the watchdog timer in time, the watchdog resets the system to recover from the freeze.
  3. Final Answer:

    To reset the system if the program stops responding -> Option C
  4. Quick Check:

    Watchdog timer resets system on freeze = D [OK]
Hint: Watchdog resets system if program hangs [OK]
Common Mistakes:
  • Thinking watchdog speeds up CPU
  • Confusing watchdog with memory storage
  • Assuming watchdog provides power
2. Which of the following is the correct way to reset (kick) a watchdog timer in embedded C?
easy
A. watchdog_reset();
B. reset_watchdog();
C. kick_watchdog();
D. wdt_reset();

Solution

  1. Step 1: Recall standard watchdog reset function

    In many embedded C libraries, the function to reset the watchdog timer is wdt_reset().
  2. Step 2: Check other options

    Other options like watchdog_reset(), reset_watchdog(), and kick_watchdog() are not standard function names and will cause errors.
  3. Final Answer:

    wdt_reset(); -> Option D
  4. Quick Check:

    Standard watchdog reset function = wdt_reset() [OK]
Hint: Use wdt_reset() to reset watchdog in embedded C [OK]
Common Mistakes:
  • Using non-standard function names
  • Forgetting parentheses in function call
  • Confusing reset with initialization
3. What will be the output of the following code snippet if the watchdog is not reset within 5 seconds?
void main() {
  setup_watchdog(5); // 5 seconds timeout
  while(1) {
    // No watchdog reset here
  }
  printf("Running");
}
medium
A. The program prints 'Running' continuously
B. The program resets after 5 seconds and never prints 'Running'
C. The program prints 'Running' once and stops
D. Compilation error due to missing watchdog reset

Solution

  1. Step 1: Analyze watchdog setup and loop

    The watchdog is set with a 5-second timeout, but inside the infinite loop, the watchdog reset function is never called.
  2. Step 2: Understand watchdog behavior on timeout

    Since the watchdog is not reset, after 5 seconds it triggers a system reset. The printf statement is never reached.
  3. Final Answer:

    The program resets after 5 seconds and never prints 'Running' -> Option B
  4. Quick Check:

    No watchdog reset causes reset before printf = A [OK]
Hint: No watchdog reset means system resets before print [OK]
Common Mistakes:
  • Assuming printf runs before reset
  • Thinking program runs normally without reset
  • Confusing compile error with runtime reset
4. Identify the error in this watchdog usage code snippet:
void main() {
  setup_watchdog(10);
  while(1) {
    if (some_condition) {
      wdt_reset();
    }
  }
}
medium
A. Watchdog is reset only conditionally, may cause unexpected reset
B. Watchdog timeout is too long for embedded systems
C. Missing initialization of watchdog timer
D. Incorrect function name for watchdog reset

Solution

  1. Step 1: Review watchdog reset condition

    The watchdog reset wdt_reset() is called only if some_condition is true, so it may not be called regularly.
  2. Step 2: Understand watchdog requirement

    Watchdog must be reset regularly regardless of conditions to prevent system reset. Conditional reset risks unexpected resets.
  3. Final Answer:

    Watchdog is reset only conditionally, may cause unexpected reset -> Option A
  4. Quick Check:

    Conditional watchdog reset risks reset = C [OK]
Hint: Always reset watchdog regularly, not conditionally [OK]
Common Mistakes:
  • Ignoring conditional reset risk
  • Thinking timeout length is error
  • Assuming missing initialization
5. You want to use a watchdog timer to reset your embedded system if it freezes, but only after 3 seconds of no reset. Which approach correctly implements this behavior?
hard
A. Initialize watchdog with 3 seconds timeout and call wdt_reset() regularly within 3 seconds
B. Initialize watchdog with 10 seconds timeout and call wdt_reset() every 5 seconds
C. Initialize watchdog with 1 second timeout and call wdt_reset() every 4 seconds
D. Do not initialize watchdog and reset system manually every 3 seconds

Solution

  1. Step 1: Set watchdog timeout to desired reset delay

    To reset after 3 seconds of no reset, watchdog timeout must be set to 3 seconds.
  2. Step 2: Reset watchdog regularly within timeout

    Call wdt_reset() regularly before 3 seconds elapse to prevent reset during normal operation.
  3. Final Answer:

    Initialize watchdog with 3 seconds timeout and call wdt_reset() regularly within 3 seconds -> Option A
  4. Quick Check:

    Timeout = 3s and regular reset = B [OK]
Hint: Timeout matches reset interval; reset watchdog before timeout [OK]
Common Mistakes:
  • Setting timeout longer than reset interval
  • Resetting watchdog less frequently than timeout
  • Not initializing watchdog at all
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard