Solution for adjusting the clock accuracy of microcontroller

Publisher:SerendipityDawnLatest update time:2014-09-22 Source: dzscKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  In the application of single-chip microcomputers, this situation often occurs. When using a single-chip microcomputer to make an electronic clock or a control system that requires clock-based control, you will suddenly find that the time of the originally calibrated electronic clock has become faster or slower.

  So, we tried various methods to adjust its timekeeping accuracy, but the final effect was still unsatisfactory, so we had to adjust it manually every once in a while. So, is it possible to make the clock more accurate? Now let's explore as follows:

  1. Error Cause Analysis

  1. The timing pulse reference of the single-chip microcomputer electronic clock is provided by the frequency of the external crystal oscillator after 12 divisions, and the internal timing and counter are used to realize the timing function. Therefore, the accuracy of the external crystal oscillator frequency directly affects the accuracy of the electronic clock timing.

  2. The microcontroller electronic clock uses internal timing, counter overflow to generate an interrupt (12MHz crystal oscillator is generally 50ms) and then multiplies it by the corresponding multiple to achieve the conversion of seconds, minutes and hours. As we all know, it takes 3-8 machine cycles from the timing and counter generating an interrupt request to responding to the interrupt. The data stack in the timing interrupt subroutine and the initial value of the timing and counter also take several machine cycles. In addition, it also takes a certain machine cycle to switch from the interrupt population to the interrupt subroutine. For example:

  From the above program, it can be seen that it takes 2+2+2=6 machine cycles to load the lower 8 bits from the interrupt population to the initial value of the timer/counter. Therefore, these 6 machine cycles are generally added to the initial value of the timer/counter during programming. However, it takes several machine cycles (3~8 machine cycles) from the timer/counter overflow interrupt request to the execution of the interrupt. It is difficult to determine the exact value, which is the reason why the electronic clock timing is inaccurate.

  2. Solution

  1. Use high-precision crystal oscillator solution

  Although the use of high-precision crystal oscillators can slightly improve the accuracy of electronic clock timing, the crystal oscillator is not the main factor causing inaccurate timing of electronic clocks, and high-precision crystal oscillators are more expensive, so there is no need to adopt this solution.

  2. Dynamic synchronization correction scheme

  From the programmer, the dynamic synchronization correction method is used to assign an initial value to the timing counter. The dynamic synchronization correction method is as follows: Since the timing counter will automatically add numbers from 0 after overflow, before assigning a value to the timing counter again, first add the value in the timing counter low position (TLO) and the initial value, and then send it to the timing counter. At this time, the value in the timing counter is the accurate value after dynamic synchronization correction. The specific procedure is as follows:

  After adopting this method, I believe the accuracy of the electronic clock has been improved. [page]

  3. Automatic adjustment plan

  After adopting the synchronous correction scheme, the accuracy of the electronic clock has been greatly improved, but due to the deviation of the crystal frequency and the influence of some other unknown factors (the same circuit board, the same program, after changing a single-chip microcomputer, the running error is different, and the reason is unknown), there will still be accumulated errors over time. For this reason, an automatic adjustment scheme can be adopted. In fact, it is a fault-tolerant technology. The principle of its automatic adjustment is: the time required for the error Is is measured, and then the seconds are adjusted by adding "1" or subtracting "1" every such period of time. For example: the electronic clock is 1 second slower every 50 hours, and its automatic adjustment procedure is as follows:

  Here is a complete example:

  Conclusion

  This method takes time to adjust, but the effect is very good. Through experiments, one adjustment can control the monthly error to about Is. If the number of days required for the error Is is measured again according to this method and a second adjustment is made, the accuracy will be higher.

Keywords:MCU Reference address:Solution for adjusting the clock accuracy of microcontroller

Previous article:Research on Intelligent Infrared Thermometer
Next article:"Eleven Golden Rules" help you easily design DC/DC power conversion circuits

Recommended ReadingLatest update time:2024-11-16 18:10

Design of infrared remote controller decoder using single chip microcomputer
TC9012F is a universal CMOS large-scale integrated circuit for infrared remote control signal transmission, suitable for remote control of TV, VTR, laser player and other equipment. In the market, 9012 infrared remote control with TC9012F as the core is widely used and cheap. The designed 9012 infrared remote contro
[Microcontroller]
Design of infrared remote controller decoder using single chip microcomputer
SinoWing Electronics: AMOLED display driver chip production capacity is guaranteed, MCU business growth is limited
Recently, Zhongying Electronics stated in an institutional survey that the company's MCU products are mainly in 8-inch wafer fabs, which are the main affected areas of tight production capacity. Due to limited production capacity, the growth of MCUs is limited. However, SinoWing has taken measures since last year to
[Mobile phone portable]
51 MCU 8255 driver C program
/*--------------------------------------------------------------------------------------------------------------------------------  Library file name: driver8155.h  Function description: Driver 8155, no need to understand the working principle of 8255, transparently operate the three input and output ports PA, PB, PC
[Microcontroller]
How to connect a rotary encoder using a PIC microcontroller
A Rotary Encoder is an input device that helps the user interact with a system. It looks more like a radio potentiometer, but it outputs a series of pulses, making its applications unique. When the encoder's knob is turned, it rotates in small steps, which helps it be used for stepper/servo motor control, navigating m
[Microcontroller]
How to connect a rotary encoder using a PIC microcontroller
Software Anti-interference Technology in Single-Chip Microcomputer System
In recent years, the application of single-chip microcomputer systems in the field of industrial measurement and control has become more and more extensive. For industrial sites with harsh environments, the reliability and safety of this new type of microcontroller has become a big problem. Programs that run normall
[Microcontroller]
Realizing Low-cost and High-precision A/D and D/A Conversion Using Single-chip Microcomputer
At present, single-chip microcomputers have been widely used in electronic products. Many types of single-chip microcomputers have internal A/D conversion circuits, but the price of such single-chip microcomputers is several yuan or even much higher than that of single-chip microcomputers without A/D conversi
[Microcontroller]
Realizing Low-cost and High-precision A/D and D/A Conversion Using Single-chip Microcomputer
51 MCU internal control register
I saw F0 used in the program and thought it was a printing error. But I found that F0 actually existed and it was in both the B register and the PSW. I searched online and made a note of it.  51 MCU internal control register Through the previous courses, we have learned that the microcontroller has ROM, RAM, and p
[Microcontroller]
Software and hardware implementation of serial communication between PIC16 series microcontroller and PC
Abstract This paper introduces a method of using PIC16F84 microcontroller to realize serial communication with PC, and gives its hardware interface circuit and communication source program. 1 Introduction The PIC16 series microcontroller of Microchip Company of the United States is a new type of 8-bit microcont
[Microcontroller]
Software and hardware implementation of serial communication between PIC16 series microcontroller and PC
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号