Oscillation stop processing method for clock crystal oscillator and metering instrument
By detecting the shutdown of the external clock crystal oscillator in the meter and switching to the internal high-frequency RC oscillator, the problem of the clock stopping after power failure is solved, and the low-power operation of the clock and the long-term use of the backup battery are achieved. .
Patent Information
- Application Number
- CN202411277184.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2044-09-12
AI Technical Summary
Existing meters cannot effectively maintain the low-power operation of the clock after power failure, resulting in the external clock crystal oscillator stopping, affecting the timing accuracy and the service life of the backup battery.
Through embedded software, periodically detect whether the external clock crystal oscillator is in a shutdown state, and when the shutdown is detected, the system clock source is switched to the internal high-frequency RC oscillator, write the calibration value of the high-frequency RC oscillator, and adjust its segments frequency ratio to reduce power consumption.
When the external clock crystal oscillator is stopped, the clock operation is maintained through the internal high-frequency RC oscillator to ensure timing accuracy and extend the use time of the backup battery by reducing power consumption.
Smart Images

Figure CN119440168A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of measuring instruments, and in particular to a clock crystal oscillator stop processing method and a measuring instrument. Background Art
[0002] All kinds of existing metering products require accurate timing functions. Real-time clock circuits are set inside the products, and high-precision clock oscillators are the heart of real-time clock circuits. Due to technical and cost limitations, high-precision clock oscillators are generally not integrated into the chip, but external clock oscillators are selected. However, metering products generally have the requirement to maintain low-power operation of the clock after power failure. The driving power of the oscillator circuit is generally designed to be very small, and the external clock crystal oscillator and matching resistors and capacitors are arranged on the circuit board, which has very high requirements for the cleanliness of the circuit board. For example, the increase in environmental humidity causes the internal humidity of the product to rise, and the ion residue on the circuit board will reduce the surface resistance of the circuit board, resulting in the driving power of the oscillator circuit being consumed by the circuit board. In severe cases, the external clock crystal oscillator cannot obtain sufficient driving power and stops oscillating, affecting the accuracy of timing. Metering products running on the network may even affect key metering data such as freezing, causing abnormal rates. Improper handling of the external clock crystal oscillator stop oscillation will also affect the power consumption of the MCU in the power-off state. If the crystal oscillator stops oscillating when the product is still in transportation or storage, the backup battery powered by the MCU will quickly consume power due to excessive discharge current, making the product a defective product. At present, when the clock crystal oscillator stops oscillating in the power-on state of the product, the RTC will be inaccurate or stopped, affecting the daily freezing function of the meter. When the clock crystal oscillator stops oscillating in the power-off state, the product operating current will increase abnormally. The typical consequence is that the current consumption of the backup battery increases sharply. The 1400mAh backup battery is exhausted in about ten days, while the battery can maintain low power consumption for more than 3 years under normal use. Therefore, it is urgent to propose a clock crystal oscillator stop processing method and a meter to solve the technical problem of how to determine whether the external clock crystal oscillator is in a stopped state and adjust the clock crystal oscillator in real time. Summary of the invention
[0003] The main purpose of the present invention is to provide a clock crystal oscillator stop processing method and a measuring instrument, aiming to solve the technical problem of how to judge whether an external clock crystal oscillator is in a stop state and adjust the clock crystal oscillator in real time.
[0004] To achieve the above object, the present invention provides a clock crystal oscillator stop processing method, wherein the clock crystal oscillator stop processing method comprises the following steps:
[0005] S1, initialize the system, and the embedded software periodically detects whether the external clock crystal oscillator is in a stopped state;
[0006] S2. Configure the system's internal high-frequency RC oscillator as the system clock source and write the calibration value of the high-frequency RC oscillator;
[0007] S3, determining whether the system is in a power-on state;
[0008] If it is in the power-on state, execute step S4, if it is in the power-off state, execute step S5;
[0009] S4, configure the value of the system clock frequency division setting register to make the system clock work at the first frequency, and use the first frequency as the working frequency of the function register of the timer in the system, modify the clock source of the function register to the system clock source, and execute step S6;
[0010] S5, configure the value of the system clock frequency division setting register to make the system clock work at the second frequency, and use the second frequency as the working frequency of the function register of the timer in the system, modify the clock source of the function register to the system clock source, and execute step S6;
[0011] S6. The timer in the system is re-timing, the software clock of the embedded software accumulates the clock, and the RTC accumulates the clock synchronously.
[0012] In one of the preferred solutions, the periodic detection of whether the external clock crystal oscillator is in a stopped state in step S1 includes:
[0013] Read the flag bit of the stop status register and determine whether it is in the stop state based on the flag bit.
[0014] In one of the preferred solutions, the periodic detection of whether the external clock crystal oscillator is in a stopped state in step S1 includes:
[0015] Check whether there is a watchdog reset flag in the reset flag register, and determine whether it is in the oscillation stop state based on the watchdog reset flag.
[0016] One of the preferred solutions, after step S4, further includes:
[0017] A timing period T is preset, and the timer performs timing operation according to the timing period T.
[0018] One of the preferred solutions, after step S5, further includes:
[0019] A timing period T is preset, and the timer performs timing operation according to the timing period T.
[0020] In one of the preferred solutions, the function registers of the timer include a control register, a period register, a counter register, an interrupt enable register and an interrupt flag register.
[0021] In one preferred embodiment, the second frequency is the lowest frequency of the high frequency RC oscillator.
[0022] One of the preferred solutions is that in step S5, if the system is in a power-off state and the external clock crystal oscillator stops oscillating, it is determined whether the embedded software is in a sleep mode. If so, the operation of the embedded software is restored by a watchdog reset, and the process returns to step S3.
[0023] A measuring instrument comprises the clock crystal oscillator stop processing method.
[0024] In the above technical solution of the present invention, the clock crystal oscillator stop processing method includes the following steps: initializing the system, the embedded software periodically detects whether the external clock crystal oscillator is in a stop state; configuring the system internal high-frequency RC oscillator as the system clock source, and writing the calibration value of the high-frequency RC oscillator; judging whether the system is in a power-on state; configuring the value of the system clock frequency division setting register, so that the system clock works at a first frequency, and uses the first frequency as the working frequency of the function register of the timer in the system, and the clock source of the function register is modified to the system clock source; configuring the value of the system clock frequency division setting register, so that the system clock works at a second frequency, and uses the second frequency as the working frequency of the function register of the timer in the system, and the clock source of the function register is modified to the system clock source; the timer in the system is re-timing, the software clock of the embedded software performs clock accumulation, and synchronously performs clock accumulation on the RTC. The present invention solves the technical problem of how to judge whether the external clock crystal oscillator is in a stop state and adjust the clock crystal oscillator in real time.
[0025] In the present invention, by detecting that the clock crystal oscillator is in a stopped state and switching the RTC clock source from the external clock crystal oscillator to the internal high-frequency RC oscillator to continue running, it is ensured that the clock accuracy can meet the timing requirements within a certain period of time and maintain the clock operation of the metering product on the network or after power failure.
[0026] In the present invention, when the system clock source is switched to the internal high-frequency RC oscillator to continue running, the accuracy of the high-frequency RC oscillator is improved by writing the high-frequency RC oscillator calibration value, and the power consumption can be reduced by adjusting the division ratio of the internal high-frequency RC oscillator, thereby extending the operating time of the backup battery and ensuring the correct clock after the clock crystal oscillator stops oscillating during transportation and storage. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0028] Figure 1 A first schematic diagram of a clock crystal oscillator stop processing method according to an embodiment of the present invention;
[0029] Figure 2 The second schematic diagram of a clock crystal oscillator stop processing method according to an embodiment of the present invention.
[0030] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with the implementation methods and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] It should be noted that all directional indications (such as up, down, etc.) in the embodiments of the present invention are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0033] In addition, in the present invention, the descriptions such as "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include at least one of the features.
[0034] Furthermore, the technical solutions between the various embodiments of the present invention may be combined with each other, but this must be based on the fact that they can be implemented by ordinary technicians in the field. When the combination of technical solutions is mutually contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0035] See also Figure 1-Figure 2 According to one aspect of the present invention, the present invention provides a clock crystal oscillator stop processing method, wherein the clock crystal oscillator stop processing method comprises the following steps:
[0036] S1, the embedded software starts running and performs initialization operations. The embedded software periodically detects whether the external clock crystal oscillator is in a stopped state; if the external clock crystal oscillator is in a stopped state, step S2 is executed; if the external clock crystal oscillator is not in a stopped state, the detection is repeated;
[0037] S2. Configure the system's internal high-frequency RC oscillator as the system clock source and write the calibration value of the high-frequency RC oscillator;
[0038] S3, determining whether the system is in a power-on state;
[0039] If it is in the power-on state, execute step S4, if it is in the power-off state, execute step S5;
[0040] S4, configure the value of the system clock frequency division setting register to make the system clock work at the first frequency, and use the first frequency as the working frequency of the function register of the timer in the system, modify the clock source of the function register to the system clock source, and execute step S6;
[0041] S5, configure the value of the system clock frequency division setting register to make the system clock work at the second frequency, and use the second frequency as the working frequency of the function register of the timer in the system, modify the clock source of the function register to the system clock source, and execute step S6;
[0042] S6. The timer in the system is re-timing, the software clock of the embedded software accumulates the clock, and the RTC accumulates the clock synchronously.
[0043] Specifically, in this embodiment, the periodic detection of whether the external clock crystal oscillator is in a stopped state in step S1 includes: reading a flag bit of a stopped state register, and determining whether it is in a stopped state according to the flag bit.
[0044] Specifically, in this embodiment, the periodic detection of whether the external clock crystal oscillator is in a stopped state in step S1 includes: detecting whether a reset flag register has a watchdog reset flag, and determining whether it is in a stopped state according to the watchdog reset flag.
[0045] Specifically, in this embodiment, the step S4 is specifically as follows: if the system is in a power-on state, the value of the system clock division setting register is configured to make the system clock work at a first frequency, and the function register of the timing in the system is configured with the first frequency, and the clock source of the function register is modified to the system clock source, and a timing period T is preset. The timer in the system performs timing operations according to the timing period T; wherein the function register includes a system control register and a wake-up flag register; in the present invention, the timing period T is 1s, which is not specifically limited in the present invention and can be set as needed.
[0046] Specifically, in the present embodiment, the step S5 is specifically as follows: if the system is in a power-off state, the value of the system clock frequency division setting register is configured to make the system clock work at a second frequency, wherein the second frequency is the lowest frequency of the high-frequency RC oscillator. The embedded software is made to work at the lowest frequency through the second frequency, and the operating power consumption of the system microcontroller is reduced to an extremely low level, and the system no longer enters the sleep mode; and the second frequency is used as the operating frequency of the function register of the timer in the system, and the clock source of the function register is modified to the system clock source. The function register of the timer includes a control register, a period register, a counter register, an interrupt enable register and an interrupt flag register; at the same time, a timing period T is preset, and the timer performs timing operations according to the timing period T; in the present invention, the timing period T is 1s, which is not specifically limited in the present invention and can be set as needed.
[0047] Specifically, in this embodiment, if the system is in a power-off state and the external clock crystal oscillator stops oscillating in step S5, it is determined whether the embedded software is in sleep mode. If so, the operation of the embedded software is restored by a watchdog reset, and the process returns to step S3.
[0048] Specifically, in this embodiment, the timing period T of the timer in the system triggers a timer interrupt, the timer is reset, the software clock of the embedded software accumulates the clock, and synchronously accumulates the clock of the RTC, so that the RTC performs a timing operation.
[0049] According to another aspect of the present invention, a metering instrument is provided, wherein the metering instrument includes the clock crystal oscillator stop processing method. If the external clock crystal oscillator stops, the metering instrument can maintain the clock operation by switching to an internal high-frequency RC oscillator. Especially in a power-off state, by switching to the lowest frequency based on the high-frequency RC oscillator, the operating power consumption of the system microcontroller is reduced to an extremely low level, thereby greatly extending the service life of the backup battery.
[0050] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. All equivalent structural changes made using the contents of the present invention's specification and drawings, or directly / indirectly applied in other related technical fields, are included in the patent protection scope of the present invention.
Claims
1. A method for processing a clock crystal oscillator stopping oscillation, characterized in that: The following steps are involved: S1, initialize the system, and the embedded software periodically detects whether the external clock crystal oscillator is in a stopped state; S2. Configure the system's internal high-frequency RC oscillator as the system clock source and write the calibration value of the high-frequency RC oscillator; S3, determining whether the system is in a power-on state; If it is in the power-on state, execute step S4, if it is in the power-off state, execute step S5; S4, configure the value of the system clock frequency division setting register to make the system clock work at the first frequency, and use the first frequency as the working frequency of the function register of the timer in the system, modify the clock source of the function register to the system clock source, and execute step S6; S5, configure the value of the system clock frequency division setting register to make the system clock work at the second frequency, and use the second frequency as the working frequency of the function register of the timer in the system, modify the clock source of the function register to the system clock source, and execute step S6; S6. The timer in the system is re-timing, the software clock of the embedded software accumulates the clock, and the RTC accumulates the clock synchronously.
2. A clock crystal oscillator stop processing method according to claim 1, characterized in that: The step S1 of periodically detecting whether the external clock crystal oscillator is in a stopped state includes: Read the flag bit of the stop status register and determine whether it is in the stop state based on the flag bit.
3. A clock crystal oscillator stop processing method according to any one of claims 1-2, characterized in that: The step S1 of periodically detecting whether the external clock crystal oscillator is in a stopped state includes: Check whether there is a watchdog reset flag in the reset flag register, and determine whether it is in the oscillation stop state based on the watchdog reset flag.
4. A clock crystal oscillator stop processing method according to any one of claims 1-2, characterized in that: After step S4, the method further includes: A timing period T is preset, and the timer performs timing operation according to the timing period T.
5. A clock crystal oscillator stop processing method according to any one of claims 1-2, characterized in that: After step S5, the method further includes: A timing period T is preset, and the timer performs timing operation according to the timing period T.
6. A clock crystal oscillator stop processing method according to any one of claims 1-2, characterized in that: The function registers of the timer include a control register, a period register, a counter register, an interrupt enable register and an interrupt flag register.
7. A clock crystal oscillator stop processing method according to any one of claims 1-2, characterized in that: The second frequency is the lowest frequency of the high frequency RC oscillator.
8. A clock crystal oscillator stop processing method according to any one of claims 1-2, characterized in that: In step S5, if the system is in a power-off state and the external clock crystal oscillator stops oscillating, it is determined whether the embedded software is in a sleep mode. If so, the operation of the embedded software is restored by a watchdog reset, and the process returns to step S3.
9. A measuring instrument, characterized in that: The measuring instrument includes a clock crystal oscillator stop processing method as described in any one of claims 1-8.
Citation Information
Patent Citations
Radio frequency device and wireless sensor network system
CN106452647A
On-chip clock calibration device and calibration method
CN109067394A
Clock oscillation stop detection circuit
CN109412581A
Clock correction method and device based on external crystal oscillator and electric energy meter
CN116192101A
Clock oscillation stop monitoring circuit, monitoring method, chip system and storage medium
CN116204040A