A few days ago, I made an electronic clock using STC89C52 microcontroller. After a period of experiments, I found that there is an error in the time accuracy, and one minute is about 4 seconds slower.
This is amazing. Ten minutes will be 40 seconds slower. In one day, it will be no less than half 96 minutes! ! !
The crystal oscillator frequency of this microcontroller is 11.0592mhz, which is the same as the crystal oscillator frequency of most clocks, so there should be no problem.
Consider the source code the day after tomorrow:
In the timer interrupt function:
void t0(void) interrupt 1 using 0
{
tcount++;
if(tcount==4000)
{tcount=0;
second++;
if(second==60)
{second=0;
minute++;
if(minute==60)
{minute=0;
hour++;
if(hour==24)
{hour=0;
}
}
}
P1=~P1;
}
}
The number after interrupt is simply the code name of the interrupt service function.
0 represents external interrupt 0
1 represents the timer counter 0 interrupt
2 represents external interrupt 1
3 represents the timer counter 1 interrupt
4 represents serial port interrupt
So interrupt 1 means that after the timer counter generates an interrupt, it will be executed in this function.
The code is actually quite simple, every 4000 interrupts will occur for 1 second.
etc...
The interruption every 4000 times is 1 second, so the reason is probably here.
Try comparing tcount==3600 with the stopwatch and find that every minute is about 1 second faster.
Bingo! The problem does lie in the value of tcount. Change the value of tcount to 3700. Comparing it with the stopwatch, we find that there is no error in seconds, and the error should be in milliseconds.
void t0(void) interrupt 1 using 0
{
tcount++;
if(tcount==3700)
{tcount=0;
second++;
if(second==60)
{second=0;
minute++;
if(minute==60)
{minute=0;
hour++;
if(hour==24)
{hour=0;
}
}
}
P1=~P1;
}
}
This solves the problem of clock accuracy.
Previous article:Design of aircraft engine intelligent measurement and display system using AT89S51 microcontroller
Next article:Solution to 51 microcontroller clock accuracy error
Recommended ReadingLatest update time:2024-11-16 09:43
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
- Sharing a carefully adjusted hysteresis comparator
- The simulation result of LC parallel resonance frequency is inconsistent with the calculation. Is it because the component model is not selected correctly?
- Using Bluetooth module for fast IoT circuit design
- Using the Ginkgo USB-I2C adapter and the BMP180/BMP085 sensor to implement an atmospheric pressure detector
- High-speed plate actual application case
- What is the difference between TMS320C6416 and TMS320C6416T?
- Disassembling the x990
- Greenhouse automatic spraying system ---- H743 water lamp
- Design of wireless serial port hub using ARM microprocessor and ZigBee module
- [TI recommended course] #Live replay: TI mmWave millimeter wave radar application in automobiles#