11966 views|5 replies

20

Posts

0

Resources
The OP
 

AVR's experience in dog training [Copy link]

The new AVR series (for example, ATMEGA168, etc.) uses an enhanced watchdog timer. Compared with the original watchdog, it has the same reset function and an interrupt function. The interrupt function of the watchdog can wake up the CPU from the Power Down state. In addition, it can use the interrupt and reset functions at the same time. When an error occurs in the system, it can first enter the interrupt state, save key data to the EEPROM, and then reset the system. Compared with the old watchdog (for example, ATMEGA16, etc.), the new AVR watchdog has added new functions and its temperament has also changed a lot. You should understand its temperament when designing to prevent being bitten by the dog. The following is a simple comparison between ATMEGA16 and ATMEGA168 to briefly explain the key points: Watchdog Timer Control Register – WDTCR: Atmega16: Atmega168: 1. Since A1tmega168 has interrupt function, WDTCR adds two extra bits WDIF and WDIE. 2. WDP3 is added, and the overflow period can be up to 8 seconds. 3. When the new watchdog is initialized, the value of WDT is no longer necessarily 0. As long as WDRF on the MCUSR register is set, WDT will also be forced to set. At this time, if WDE is to be cleared, WDRF must be cleared first. 4. Even if WDT is not used during design, it may be enabled unintentionally, such as in the runaway pointer and power-on condition. Therefore, even if WDT is not used, the reset flag must be checked in the initial code, and processing steps must be taken if a WDT system reset occurs. I recently redesigned a project, updating from the original ATMEGA16 to ATMEGA168. After converting the original code, the test results were abnormal. After more than a day of testing, I found that the new watchdog was the cause of the problem. In the past, when using ATMEGA16, the watchdog was fed after initialization, but with the new AVR series (such as ATMEGA168, etc.), when a system reset occurs (except for power-on reset), the WDT may continue to run and use the minimum overflow period (about 15mS), causing the system to reset continuously. According to the datasheet, everything returns to normal after turning off the watchdog at the beginning of the program: #include
#include
uint8_t mcusr_mirror; void get_mcusr(void) \ __attribute__((naked)) \ __attribute__((section(".init3"))); void get_mcusr(void) { mcusr_mirror = MCUSR; MCUSR = 0; wdt_disable(); }
5. When using the watchdog interrupt, when WDIF and WDIE are set, an interrupt will be generated. After entering the corresponding interrupt program, the system automatically clears WDIF and WDIE. The next time you want to use the watchdog interrupt, you must set WDIE again.
This post is from Microchip MCU

Latest reply

Mark it for a moment.  Details Published on 2012-9-1 08:36

赞赏

1

查看全部赞赏

 

75

Posts

0

Resources
2
 
This post is from Microchip MCU
 
 
 

391

Posts

0

Resources
3
 
I haven't developed avr yet, I'm learning
This post is from Microchip MCU
 
 
 

1

Posts

0

Resources
4
 
I haven’t touched it yet, so I’ll save it and study it later!
This post is from Microchip MCU
 
 
 

5

Posts

0

Resources
5
 
I'm just getting started, hope for some advice
This post is from Microchip MCU
 
 
 

28

Posts

0

Resources
6
 
Mark it for a moment.
This post is from Microchip MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list