CN102176112B - Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit) - Google Patents
Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit) Download PDFInfo
- Publication number
- CN102176112B CN102176112B CN 201110044232 CN201110044232A CN102176112B CN 102176112 B CN102176112 B CN 102176112B CN 201110044232 CN201110044232 CN 201110044232 CN 201110044232 A CN201110044232 A CN 201110044232A CN 102176112 B CN102176112 B CN 102176112B
- Authority
- CN
- China
- Prior art keywords
- temperature
- value
- rtc
- frequency
- frequency deviation
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Landscapes
- Electric Clocks (AREA)
- Stabilization Of Oscillater, Synchronisation, Frequency Synthesizers (AREA)
Abstract
The invention discloses a method for achieving accurate clock timing by arranging an RTC (real time clock) in an MCU (micro control unit). The method comprises the following steps: (1) adjustment of a prescaler: setting the default value of the prescaler as (k-1) when a kHZ crystal oscillator is utilized, and generating one second pulse interruption when the counting of the prescaler is k; (2) adjustment of a clock calibration register: utilizing a temperature sensor to collect the external temperature in a fixed time window, looking for the value of frequency offset according to the temperature, calculating the number of the actual frequency offset PPM (percent per million), and calculating the value of the calibration register; (3) utilizing the temperature sensor to sample the temperature, measuring the frequency output at the corresponding temperature, calculating the frequency offset acc according to a reference frequency, fitting the k value of a function of the temperature and the frequency offset based on the large amount of data so as to a temperature-frequency offset table, and looking for the table to obtain the accurate frequency offset PPM value through software; and (4) writing the corresponding value to the prescaler register and calibration register of the RTC during the service program interruption of the RTC.
Description
Technical field
The present invention relates to the method that the built-in RTC of various single-phase, three-phases and multifunctional electric energy meter realizes the cycle accurate timing.
Background technology
At present traditional clock of power meter adopts the RTC mode of free band temperature compensation usually, uses this mode, needs other wiring topology, takies the MUC resource, and investment is large.And the built-in RTC of MUC has larger advantage in performance and price, but produces frequency deviation because it uses the easy temperature influence of external crystal, causes the error of the built-in RTC of MCU much larger than the error of the RTC of free band temperature compensation, thereby causes clock of power meter inaccurate.Therefore, how according to crystal oscillation characteristic and temperature relation, the pre-divider register of the built-in RTC of MCU and clock alignment register are adjusted to reach accurately clock output seem particularly important.
Summary of the invention
The objective of the invention is: overcome the shortcoming of prior art, when the software school of a kind of RTC is provided, utilize external crystal-controlled oscillation and external temperature sensor, utilize certain algorithm to make the reliable and stable work of inner RTC.
For achieving the above object, the technical solution used in the present invention is: the built-in RTC of MCU realizes the method for cycle accurate timing, may further comprise the steps:
(1) adjustment of pre-divider: in the situation of using the kHZ crystal oscillator, the pre-divider default value is k-1, and pre-divider count down to the k value and produces 1 pulse per second (PPS) interruption.Therefore, for pre-frequency counter, one of every adjustment " bit ", the corresponding error of adjusting is: 1/k*1000,000 ppm, this adjustment can by software control, be adjusted in 1 second and come into force.
(2) adjustment of clock alignment register: under the window, temperature sensor gathers outside temperature at a fixed time, and the numerical evaluation of utilizing temperature to check in frequency deviation goes out actual frequency deviation PPM number, thereby calculates the value of calibration register.
(3) by the temperature sensor sampling temperature, and the frequency of measuring under relevant temperature is exported, calculate frequency deviation acc with reference frequency, k value by the function of these mass data match temperature and frequency deviation, thereby produce the table of a temperature and frequency deviation, software can obtain accurately frequency deviation PPM value by tabling look-up, and this function is as follows:
(4) in the middle of the RTC interrupt service routine, write corresponding value to the pre-frequency division register of RTC and calibration register.
The invention has the beneficial effects as follows: obtain accurately frequency deviation PPM by external temperature sensor, can budget obtain the actual value that writes calibration register, accurate calibration clock by this PPM.
Description of drawings
Below in conjunction with the drawings and specific embodiments the present invention is described in further detail.
Fig. 1 is the graph of a relation of crystal frequency deviation value of the present invention and temperature.
Embodiment
As shown in Figure 1, the present invention, the built-in RTC of MCU realize the method for cycle accurate timing, may further comprise the steps:
(1) adjustment of pre-divider: in the situation of using the kHZ crystal oscillator, the pre-divider default value is k-1, and pre-divider count down to the k value and produces 1 pulse per second (PPS) interruption.Therefore, for pre-frequency counter, one of every adjustment " bit ", the corresponding error of adjusting is: 1/k*1000,000 ppm, this adjustment can by software control, be adjusted in 1 second and come into force;
(2) adjustment of clock alignment register: under the window, temperature sensor gathers outside temperature at a fixed time, and the numerical evaluation of utilizing temperature to check in frequency deviation goes out actual frequency deviation PPM number, thereby calculates the value of calibration register;
(3) by the temperature sensor sampling temperature, and the frequency of measuring under relevant temperature is exported, calculate frequency deviation acc with reference frequency, k value by the function of these mass data match temperature and frequency deviation, thereby produce the table of a temperature and frequency deviation, software can obtain accurately frequency deviation PPM value by tabling look-up, and this function is as follows:
(4) in the middle of the RTC interrupt service routine, write corresponding value to the pre-frequency division register of RTC and calibration register.
The technical solution used in the present invention, write initial value to the pre-frequency division register of RTC and clock alignment register, by host computer to RTC to the time, read the value of RTC pre-divider under the data of collecting temperature sensor and the corresponding temperature, consist of a tables of data, adopt data to process the mathematical model of setting up frequency deviation and temperature; Make corresponding parameter as temperature of this batch crystal oscillator and the tables of data of frequency deviation according to model; Process as the upset of pulse per second (PPS) with a timer, be used for test from IO mouth output pulse per second (PPS), enter simultaneously the value of timer interruption read-out counter, this value is average for the umber of pulse that strides across at set time window calculation RTC, be used for calculating the value that writes the timer pre-divider, reach pulse per second (PPS) output accurately;
Read the value of external temperature sensor at the set time window, utilization is tabled look-up to such an extent that method draws frequency deviation value, calculate (can be obtained by corresponding MCU databook) by data and obtain actual frequency deviation value and pre-frequency division value, calculate again the value of calibration register according to the PPM of a quantity, the value of so pre-frequency division value and calibration register has all obtained, and writes corresponding value to the pre-frequency division register of RTC and calibration register in the RTC interrupt service routine.
The invention has the beneficial effects as follows: obtain accurately frequency deviation PPM by external temperature sensor, can budget obtain the actual value that writes calibration register, accurate calibration clock by this PPM.
Claims (1)
1.MCU built-in RTC realizes the method for cycle accurate timing, it is characterized in that, may further comprise the steps:
(1) adjustment of pre-divider: in the situation of using the kHZ crystal oscillator, the pre-divider default value is k-1, pre-divider count down to the k value and produces 1 pulse per second (PPS) interruption, for pre-frequency counter, one of every adjustment " bit ", the corresponding error of adjusting is: 1/k*1000,000 ppm, this adjustment can by software control, be adjusted in 1 second and come into force;
(2) adjustment of clock alignment register: under the window, temperature sensor gathers outside temperature at a fixed time, and the numerical evaluation of utilizing temperature to check in frequency deviation goes out actual frequency deviation PPM number, thereby calculates the value of calibration register;
(3) by the temperature sensor sampling temperature, and the frequency of measuring under relevant temperature is exported, calculate frequency deviation acc with reference frequency, k value by the function of these mass data match temperature and frequency deviation, thereby produce the table of a temperature and frequency deviation, software can obtain accurately frequency deviation PPM value by tabling look-up, and this function is as follows:
(4) in the middle of the RTC interrupt service routine, write corresponding value to the pre-frequency division register of RTC and calibration register.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN 201110044232 CN102176112B (en) | 2010-11-29 | 2011-02-24 | Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit) |
Applications Claiming Priority (3)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010563599.1 | 2010-11-29 | ||
CN201010563599 | 2010-11-29 | ||
CN 201110044232 CN102176112B (en) | 2010-11-29 | 2011-02-24 | Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit) |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102176112A CN102176112A (en) | 2011-09-07 |
CN102176112B true CN102176112B (en) | 2013-04-24 |
Family
ID=44519304
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN 201110044232 Active CN102176112B (en) | 2010-11-29 | 2011-02-24 | Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit) |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102176112B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP3022538B1 (en) * | 2013-07-18 | 2020-09-09 | A4P Technologies S.A. | A method of temperature measurement and recording as a function of time |
Families Citing this family (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102435975B (en) * | 2011-11-07 | 2015-01-21 | 中国电力科学研究院 | Clock calibration method of intelligent cost control electric energy meter |
CN102932084B (en) * | 2012-10-17 | 2015-11-11 | 航天科工深圳(集团)有限公司 | The method and system that sampling clock is synchronous |
CN103176400B (en) * | 2013-01-14 | 2015-08-26 | 杭州海兴电力科技股份有限公司 | Intelligent ammeter clock calibration method |
CN103116385B (en) | 2013-03-01 | 2015-11-25 | 华为技术有限公司 | Correcting circuit and real time clock circuit |
CN104898474B (en) * | 2015-04-01 | 2017-12-01 | 华南理工大学 | A kind of Multichannel uniform servo pulse generation method based on MCU |
CN106556724B (en) * | 2015-09-28 | 2019-04-12 | 华立科技股份有限公司 | Ammeter clock correcting method |
CN107884608B (en) * | 2017-11-02 | 2020-10-23 | 钜泉光电科技(上海)股份有限公司 | Electric energy meter control system and clock correction method |
CN110519356B (en) * | 2019-08-20 | 2022-02-01 | 杭州先锋电子技术股份有限公司 | Method and device for calibrating reporting success rate of gas meter |
CN110401499A (en) * | 2019-08-29 | 2019-11-01 | 杭州博联智能科技股份有限公司 | For Fast Frequency Offset calibration method, device, equipment and the medium of radio-frequency module |
CN113009899B (en) * | 2019-12-20 | 2023-05-16 | 金卡智能集团股份有限公司 | RTC clock calibration method for high-precision timing of metering instrument |
CN112073264B (en) * | 2020-08-31 | 2022-09-02 | 新华三信息安全技术有限公司 | Protocol detection method, device and network equipment |
CN112737507B (en) * | 2021-02-01 | 2022-07-08 | 山东新港电子科技有限公司 | Method for realizing RTC high precision based on temperature sensor |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1573354A (en) * | 2003-06-10 | 2005-02-02 | 日本电气株式会社 | Portable terminal and GPS time keeping method |
CN1909375A (en) * | 2005-08-03 | 2007-02-07 | 乐金电子(中国)研究开发中心有限公司 | Real-time clock device and current time compensating method |
CN101170349A (en) * | 2006-10-23 | 2008-04-30 | 大唐移动通信设备有限公司 | Real time clock calibration circuit |
-
2011
- 2011-02-24 CN CN 201110044232 patent/CN102176112B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1573354A (en) * | 2003-06-10 | 2005-02-02 | 日本电气株式会社 | Portable terminal and GPS time keeping method |
CN1909375A (en) * | 2005-08-03 | 2007-02-07 | 乐金电子(中国)研究开发中心有限公司 | Real-time clock device and current time compensating method |
CN101170349A (en) * | 2006-10-23 | 2008-04-30 | 大唐移动通信设备有限公司 | Real time clock calibration circuit |
Non-Patent Citations (2)
Title |
---|
孙雪梅等.实时时钟芯片在单片机系统中的应用.《沈阳教育学院学报》.2005,第7卷(第2期),132-134. * |
李浩等.实时时钟芯片RTC4553原理及应用.《电测与仪表》.2003,第40卷(第452期),38-41. * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP3022538B1 (en) * | 2013-07-18 | 2020-09-09 | A4P Technologies S.A. | A method of temperature measurement and recording as a function of time |
Also Published As
Publication number | Publication date |
---|---|
CN102176112A (en) | 2011-09-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102176112B (en) | Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit) | |
CN105573106B (en) | To the amendment circuit and its method of RTC accuracy of timekeeping in a kind of intelligent electric meter | |
CN103176400B (en) | Intelligent ammeter clock calibration method | |
CN201886034U (en) | Flow velocity and rate measurement instrument | |
CN103248356B (en) | A kind of counter and implementation method based on adopting phase-locked loop pulse interpolation technology | |
CN202256438U (en) | Hardware real time clock (RTC) error compensation system of intelligent electric energy meter | |
CN103116385B (en) | Correcting circuit and real time clock circuit | |
CN108063617A (en) | The clock frequency calibration method and system of a kind of low frequency RC oscillators | |
CN104937504B (en) | The punctual method of quartz watch high accuracy | |
CN104154987A (en) | Vibration wire type sensor reader measuring meter | |
CN102163040B (en) | Built-in hardware clock module with temperature compensation function | |
CN200993665Y (en) | Small digitalized prase-comparing measuring device | |
CN203858351U (en) | High-precision detection device of magnetic resonance signal of cesium optical pump | |
CN205333219U (en) | Multichannel temperature measuring circuit based on quartz crystal temperature sensor | |
CN201569873U (en) | LED digital electronic clock | |
CN201796428U (en) | Single-phase cost control intelligent electric energy meter with temperature compensation clock module | |
CN102882672A (en) | Method and device for calibrating dynamic token clock | |
CN101556325A (en) | Method for quickly verifying electric energy error | |
CN202434049U (en) | Water meter data acquirer | |
CN202393904U (en) | Error verifying device used for electric energy metering device | |
CN201387481Y (en) | Error detecting device for digital watt-hour meter | |
CN205229298U (en) | Frequency measuring device based on FPGA | |
CN201397233Y (en) | Three-line pendulum oscillatory cycle measuring instrument | |
CN101136627B (en) | Method for automatically setting high-stability constant temperature crystal oscillator parameter | |
CN203069677U (en) | Digital inductance measuring meter |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
C56 | Change in the name or address of the patentee | ||
CP03 | Change of name, title or address |
Address after: 226200 Jiangsu city of Nantong province Qidong Economic Development Zone No. 666 Lin Yang Lu Patentee after: JIANGSU LINYANG ENERGY CO., LTD. Address before: Qidong City, Jiangsu province 226200 Nantong City Lin Yang Lu No. 666 Patentee before: Jiangsu Linyang Electronics Co., Ltd. |