ATmega168 Watchdog Timer

Publisher:Amy啊111111Latest update time:2020-07-18 Source: eefocusKeywords:ATmega168 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The watchdog timer is driven by an independent 128 kHz on-chip oscillator. The watchdog reset time interval can be adjusted by setting the prescaler of the watchdog timer, as shown in P44Table26. The watchdog reset instruction WDR is used to reset the watchdog timer. In addition, the watchdog timer is also reset when it is disabled or reset occurs. There are 10 options for the reset time. If the timer is not reset in time, once the time exceeds the reset period, the ATmega168 resets and executes the program pointed to by the reset vector. The specific watchdog reset timing is described in P44Table26.


The watchdog timer can also be used to generate an interrupt. This is very useful when using the watchdog to wake up the system from a power-down state.

To prevent the watchdog timer from being accidentally disabled or the reset time being changed, the fuse bit WDTON provides two different protection levels, as shown in Table 24. See P47 "Changing the timing sequence of the watchdog timer configuration".

ATmega168 WDTON fuse setting WDT configuration table

ATmega168 Watchdog Timer

Watchdog Timer Control Register - WDTCSR

ATmega168 Watchdog Timer Control Register - WDTCSR

· Bit 7 – WDIF: Watchdog Timeout Interrupt Flag
This bit is set when the watchdog timer times out and the timer is used as an interrupt. WDIF is cleared by hardware when the corresponding interrupt handler is executed. WDIF can also be cleared by writing "1" to the flag bit. When the I bit in the SREG register and WDIE are also set, the MCU executes a watchdog timeout interrupt.


Bit 6 – WDIE: Watchdog Timeout Interrupt Enable
When WDIE is set to "1", WDE is cleared, the I bit in the status register is set, and the watchdog timeout interrupt is enabled. When the watchdog timer times out, the corresponding interrupt routine is executed.

If WDE is set, WDIE is automatically cleared by hardware when a timeout occurs. This is very effective in ensuring the safety of watchdog reset when using interrupts. After the WDIE bit is cleared, the next timeout will cause a system reset. To avoid a watchdog reset, WDIE must be set after each interrupt.

ATmega168 Watchdog Timer Configuration

Bit 4 – WDCE: Watchdog Modification Enable
WDCE must be set when WDE is cleared, otherwise the watchdog cannot be disabled. Once set, the hardware will clear it after the next 4 clock cycles. Please refer to the description of WDE to disable the watchdog. WDCE must also be set when modifying the prescaler, as shown in P47 "Time Sequence for Changing the Watchdog Timer Configuration".


· Bit 3 – WDE: Enable Watchdog
When WDE is “1”, the watchdog is enabled, otherwise the watchdog is disabled. WDE can only be cleared when WDCE is “1”. The following are the steps to disable the watchdog:
1. Write “1” to WDCE and WDE in the same instruction, even if WDE is already “1”.
2. Write “0” to WDE within the next 4 clock cycles. This will disable the watchdog.


When operating at safety level 2, the watchdog timer cannot be disabled even if the above algorithm is used. See “Time sequence for changing the watchdog timer configuration” on page 47.

When operating at safety level 1, WDE is replaced by the WDRF function of the MCUSR, see the description of WDRF in “MCU Status Register – MCUSR” on page 41. This means that when WDRF is set, WDE is also set. To clear WDE, WDRF must be cleared before disabling the watchdog using the above procedure. This feature ensures that there are multiple resets in the event of a fault and that it is safe to start after the fault is resolved.

Note: If the watchdog timer is not required in the application, the watchdog disabling procedure should be run during device initialization. If the watchdog is accidentally enabled, such as a program runaway or BOD, the device will reset and the WDRF flag will be set when the reset is exited. This will automatically activate the watchdog, causing a new watchdog reset. To avoid this situation, the application should clear the WDRF flag and the WDE control bit during the initialization process.

· Bits 5, 2..0 – WDP3..0: Watchdog Timer Prescaler 3, 2, 1, and 0
When the watchdog timer is enabled, WDP3..0 determines the watchdog timer prescaler as shown in Table 26.

The following examples implement the operation of turning off the WDT in assembly and C respectively. It is assumed that the interrupt is under user control (for example, the x global interrupt has been disabled), so the interrupt will not occur when executing the following program. 

Assembly code routine
WDT_off:
; Clear WDRF in MCUSR
ldi r16, ( 0<< WDRF ) 
out MCUSR, r16 ; Set WDCE and WDE 
ldi r16, (1<< WDCE )|( 1<< WDE ) ; Turn off WDT 
ldi r16, (0<< WDE ) 
out WDTCSR, r16
ret

C code routine
void WDT_off(void)
{
/* Clear WDRF in MCUSR */
MCUSR = 0x00
/* Set WDCE and WDE */
WDTCSR = (1<< WDCE) | (1<< WDE);
/* Turn off WDT */
WDTCSR = 0x00;
}


Keywords:ATmega168 Reference address:ATmega168 Watchdog Timer

Previous article:ATmega168 Interrupt Vectors
Next article:ATmega168 reference voltage enable signal and startup time

Recommended ReadingLatest update time:2024-11-16 20:45

S3C2440 bare metal experiment (3) ----watchdog
The watchdog is similar to other timer functions, except that it has an additional reset function when the time is up. If WTCON is set to 0, it becomes a normal interrupt and enters the interrupt processing program. If it is set to 1, it will be reset. In this way, we can use the watchdog to monitor the program, feed
[Microcontroller]
Differences and similarities between Timer_B and Timer_A of MSP430 microcontroller
Common features of Timer_B and Timer_A 1 4 working modes 2 with optional, configurable counter input clock source 3. Multiple independent configurable capture/compare modules 4 There are multiple configurable output units with 8 output modes 5 DMA Enable 6 The interrupt function is
[Microcontroller]
N76E003 watchdog configuration
illustrate This example is only used to reset the system when the software is abnormal. It does not need to be used as a timer or wake-up, so the watchdog interrupt does not need to be enabled. It should be noted that if the watchdog reset was enabled during the last startup and you want to disable it, you must clear
[Microcontroller]
N76E003 watchdog configuration
Mega328p watchdog invalid solution
I used to use mega2560, and finally solved the watchdog problem, and the watchdog works normally. In the new project, the boss required that Mega328P also support watchdog. I thought it should be easy, after all, there is a description of watchdog in the official AVR documentation. Write a watchdog test program: #i
[Microcontroller]
Using low-cost MCU's UART to drive smart cards
The growing need for security and enhanced functionality in the banking, identification and telecommunications markets has increased the use of smart cards worldwide, while at the same time reducing the use of less secure magnetic stripe cards. However, the hardware and firmware development of appropriate communicat
[Microcontroller]
Using low-cost MCU's UART to drive smart cards
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号