ATmega64 watchdog issue

Publisher:快乐时刻Latest update time:2020-06-07 Source: eefocusKeywords:ATmega64 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Compiled by: Win AVR


Debugging: AVR Studio 4


Problem: The watchdog is set to interrupt for 2 seconds, but the actual interruption is obviously less than 2 seconds


Problem discovery process:


When using the on-chip eeprom, it is found that if more than 4 write statements are not fed to the watchdog, a watchdog reset will occur. However, the watchdog is set to reset in 2 seconds, and 4 write statements will not take 2 seconds anyway.


Using AVR Studio 4 to debug, I checked the value of WDTCR and it was 0x08, which was wrong. According to the initialization setting, it should be 0x0f. I suspected that the watchdog setting was wrong, so I checked the code:


WDTCR = 0x18;


WDTCR = 0x0f;


It seems like there are only two lines of code, written according to the manual, but after trying several times, the value of AWDTCR is always 0x08... ...


Finally, I checked the compiled assembly code in the Disassembler window and found that there were multiple codes after writing "1" to WDCE and WDS in the gray part of the assembly code, which made the writing of WDP exceed the 4 clock cycles required by the manual:


This is what the manual says, and here is security level 1:


I thought it would be reliable to use assembly language to initialize the watchdog, so I embedded the assembly language in C language:


This is the modified assembly code. You can see that the gray-font assembly code is consistent with the manual:


The actual test results are consistent with the expected ones.


Conclusion: When using C language to write code related to the microcontroller instruction cycle, if there is a problem, you can check whether the compiled assembly code meets the timing. Writing this part of the code in embedded assembly is a way to solve the problem!

Keywords:ATmega64 Reference address:ATmega64 watchdog issue

Previous article:ATMega48 Bootloader Software Practical Method
Next article:AVR MCU EEPROM Learning

Recommended ReadingLatest update time:2024-11-16 15:29

PIC 16f877a PORTB State Change Interrupt Simulation and Source Code
PORT Change Interrupt PIC 16f877A The microcontroller source program is as follows: #define      LED_1     PORTd.b0 #define      LED_2     PORTd.b1 void interrupt() { if(INTCON.RBIF)   {   INTCON.RBIF = 0;   if(!PORTB.B4)    {     LED_1 = 0;     LED_2 = 1;    }    if(!PORTB.B7 )    {     LED_1 = 1;     LED_2 = 0;  
[Microcontroller]
PIC 16f877a PORTB State Change Interrupt Simulation and Source Code
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号