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!
Previous article:ATMega48 Bootloader Software Practical Method
Next article:AVR MCU EEPROM Learning
Recommended ReadingLatest update time:2024-11-16 15:29
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- C6678: How does the malloc function do byte alignment
- Detailed explanation of ADC of MSP430 microcontroller
- Realization of various wavelet transforms based on FPGA
- The world's first integrated 5G baseband processor Kirin 990 5G was released today
- Area Occupancy Detection Reference Design for mmWave Sensors
- Multi-axis drone airbag
- I bought an old power supply, and this method of cleaning dust is the most effective
- MSP430 MCU Development Record (27)
- Comparison of three RC oscillator circuits
- EEWORLD University ---- Live Replay: Keysight Oscilloscope Basic Training