Ultrasonic water meter crystal oscillator clock calibration method based on Internet of Things and ultrasonic water meter
The crystal oscillator clock of the ultrasonic water meter is dynamically calibrated through the Internet of Things technology, and the calibration coefficient is calculated using the deviation between network time and local time, which solves the stability and accuracy of the crystal oscillator clock, and realizes the stability and accuracy of flow measurement, avoiding the increase in hardware costs.
Patent Information
- Application Number
- CN202510484792.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-07-11
AI Technical Summary
During the use of ultrasonic water meter, the stability and accuracy of the crystal oscillator clock are difficult to ensure, resulting in large flow measurement errors and even exceeding the threshold specified by the national standard. The existing technology cannot effectively calibrate the crystal oscillator clock.
The deviation between network time and local time is obtained through the Internet of Things technology, the first calibration coefficient is calculated, the long-term accumulation error of the 32.768kHz crystal oscillator is dynamically corrected, and based on the calibrated 32.768kHz clock as the reference, the actual number of periods of the 4MHz crystal oscillator within the standard time is counted, and the second calibration coefficient is generated. Finally, the deviation between the low-speed reference clock and the high-speed measurement clock is compensated for during flow calculation, so as to achieve correction of flight time.
It improves the accuracy of the crystal oscillator clock in ultrasonic water meters, reduces flow measurement errors, ensures the stability and accuracy of flow measurement without increasing hardware costs.
Smart Images

Figure CN120293247A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of clock calibration, and particularly to an ultrasonic water meter crystal oscillator clock calibration method and an ultrasonic water meter based on the Internet of Things. Background Art
[0002] During the normal use of an ultrasonic water meter, there are many factors affecting its flow accuracy and stability. Among them, the stability of the crystal oscillator clock is an important factor. The ultrasonic water meter generally uses a TDC-GP22 chip, and through the high-speed clock generated by an externally connected 4MHz crystal oscillator, it completes tasks such as ultrasonic pulse emission, echo reception, and flight time measurement. For the low-speed clock of the TDC-GP22 chip, it is generally connected to the output IO port of the 32.768kHz crystal oscillator clock of the MCU. In this way, the TDC-GP22 chip and the MCU chip share a 32.768kHz crystal oscillator clock, which can reduce costs. For the 4MHz crystal oscillator externally connected to the TDC-GP22 chip, it is only turned on during the ultrasonic time measurement process and is in the off state at other times. Generally, a ceramic crystal oscillator is used. The main reason is that the start-up time of the ceramic crystal oscillator (typical value 100µs) is short, so the power consumption is very low, but the accuracy of the ceramic crystal oscillator is relatively low.
[0003] Related technologies periodically correct the clock of the 4MHz ceramic crystal oscillator through a 32.768kHz quartz crystal oscillator to reduce measurement errors. However, this method also has defects. This method is based on the 32.768kHz quartz crystal oscillator clock. Although the stability of this type of crystal oscillator is good, over time, the crystal oscillator will also slowly deviate, and the capacitance of the load capacitors at both ends of the crystal oscillator will also slowly change. Moreover, in an environment where the temperature changes greatly between winter and summer, the deviation of the crystal oscillator clock will become larger. In addition, sometimes there are defects in a certain batch of this crystal oscillator or load capacitors. Although the factory inspection is normal, a relatively large deviation will quickly occur during the subsequent operation, etc. All these will cause an unknown deviation of the 32.768kHz crystal oscillator, resulting in an increase in flow error, and even exceeding the error threshold specified by the national standard (after using for a period of time, the flow error becomes larger and the re-inspection is unqualified). That is, during normal use, the ultrasonic water meter cannot determine the accuracy and stability of the 32.768kHz crystal oscillator and cannot be calibrated. Summary of the Invention
[0004] In order to improve the accuracy of the crystal oscillator clock in the ultrasonic water meter, this application provides an ultrasonic water meter crystal oscillator clock calibration method and an ultrasonic water meter based on the Internet of Things.
[0005] In the first aspect, this application provides an ultrasonic water meter crystal oscillator clock calibration method based on the Internet of Things, adopting the following technical solution: A method for calibrating the crystal oscillator clock of an ultrasonic water meter based on the Internet of Things, which is executed by the micro control unit of the ultrasonic water meter. The method includes: Obtain the current network time, the current local time, and the start time of the current calibration period, and determine the first calibration coefficient of the 32.768 kHz crystal oscillator clock based on the current network time, the current local time, and the start time; Obtain the number of calibration periods of the 32.768 kHz crystal oscillator clock, and determine the standard duration and the actual test duration for calibrating the 4 MHz crystal oscillator clock based on the number of calibration periods; Determine the second calibration coefficient of the 4 MHz crystal oscillator clock based on the standard duration and the actual test duration; During the actual flow measurement process, correct the flight time of the ultrasonic water meter based on the first calibration coefficient and the second calibration coefficient.
[0006] By adopting the above technical solution, the first calibration coefficient is calculated using the deviation between the network time and the local RTC time to dynamically correct the long-term cumulative error of the 32.768 kHz crystal oscillator. Based on the calibrated 32.768 kHz clock, the actual number of cycles of the 4 MHz crystal oscillator within the standard duration is counted to generate the second calibration coefficient, eliminating the short-term frequency fluctuation of the high-speed crystal oscillator. Finally, during flow calculation, the deviation between the low-speed reference clock and the high-speed measurement clock is compensated simultaneously to obtain the corrected flight time, improving the accuracy of the crystal oscillator clock in the ultrasonic water meter without increasing the hardware cost.
[0007] In a preferred example of the present application, it can be further configured that: determining the first calibration coefficient of the 32.768 kHz crystal oscillator clock based on the current network time, the current local time, and the start time includes: Judge whether the calibration identifier of the 32.768 kHz crystal oscillator clock is valid; If the calibration identifier is valid, calculate the first time interval between the current network time and the start time, and the second time interval between the current local time and the start time; Calculate the ratio of the first time interval and the second time interval as the first intermediate variable; Judge whether the first intermediate variable is within the calibration coefficient standard range. If the first intermediate variable is within the calibration coefficient standard range, use the first intermediate variable as the first calibration coefficient of the 32.768 kHz crystal oscillator clock.
[0008] By adopting the above technical solution, the validity of the calibration identifier is checked to ensure the reliability of the calibration data. The clock drift ratio (the first intermediate variable) is calculated by comparing the cumulative difference between the network time and the local time within the same start and end time periods. The calibration coefficient is updated only when the ratio is within a reasonable range through threshold judgment, improving the accuracy of the calibration coefficient.
[0009] In a preferred example of the present application, it can be further configured that: if the calibration identifier is invalid, or, the first intermediate variable is not within the standard range of the calibration coefficient, the method further includes: Calibrating the 32.768 kHz crystal oscillator clock using the current network time; The current network time is used as the start time of the next calibration cycle; Mark the calibration identifier of the 32.768 kHz crystal oscillator clock as valid.
[0010] By adopting the above technical solution, when the calibration identifier is invalid or the calibration deviation exceeds the limit, the forced calibration process is automatically triggered, directly using the high-precision network time to overwrite the local RTC time, which can eliminate the cumulative error of the crystal oscillator, update the start timestamp of the calibration cycle, ensure that the subsequent interval calculation is based on the new benchmark, and mark the calibration valid state, which helps to restore the normal operation of the system.
[0011] In a preferred example of the present application, it can be further configured that: the determining the standard duration and the actual test duration for calibrating the 4 MHz crystal oscillator clock based on the number of calibration cycles includes: Determining the standard duration for calibrating the 4 MHz crystal oscillator clock based on the number of calibration cycles; Sending a calibration instruction including the standard duration to the TDC-GP22 chip and receiving an interrupt signal including the actual number of clock cycles returned by the TDC-GP22 chip after calibration is completed; Calculating the actual test duration of the 4 MHz crystal oscillator clock based on the actual number of clock cycles.
[0012] By adopting the above technical solution, the theoretical standard duration is calculated according to the number of 32.768 kHz calibration cycles (such as 4 cycles), triggering the TDC-GP22 chip to accurately count the actual number of cycles of the 4 MHz clock within this time window, converting the actual number of cycles into the test duration, and accurately calculating the time deviation of the 4 MHz ceramic crystal oscillator.
[0013] In a preferred example of the present application, it can be further configured that: the determining the second calibration coefficient of the 4 MHz crystal oscillator clock based on the standard duration and the actual test duration includes: Calculating the ratio of the standard duration and the actual test duration as the second intermediate variable; Determine whether the second intermediate variable is within the calibration coefficient standard range. If the second intermediate variable is within the calibration coefficient standard range, use the second intermediate variable as the second calibration coefficient for the 4MHz crystal oscillator clock.
[0014] By adopting the above technical solution, the deviation between the theoretical standard duration and the actual test duration is quantitatively compared to generate the second calibration coefficient, achieving precise compensation for the 4MHz crystal oscillator. When the ratio is within the reasonable range of the calibration coefficient standard range, this coefficient is adopted to correct the frequency error, improving the accuracy of the second calibration coefficient.
[0015] In a preferred example of the present application, it can be further configured as follows: Based on the first calibration coefficient and the second calibration coefficient, correcting the flight time of the ultrasonic water meter includes: Obtain the measured flight time of the ultrasonic water meter; Calculate the product of the first calibration coefficient and the second calibration coefficient as the final calibration coefficient; Use the product of the measured flight time and the final calibration coefficient as the corrected flight time to calculate the flow rate using the corrected flight time.
[0016] By adopting the above technical solution, the measured flight time is compensated compoundly through the combined action of two-stage calibration coefficients. The first calibration coefficient corrects the long-term systematic deviation of the 32.768kHz crystal oscillator clock, and the second calibration coefficient eliminates the short-term random fluctuation of the 4MHz crystal oscillator clock. After multiplying the product of the two as the final calibration coefficient by the original flight time, full-range error compensation can be achieved, enabling the flow measurement result to have both long-term stability and instantaneous accuracy.
[0017] In a preferred example of the present application, it can be further configured as follows: The method further includes: Receive parameter settings for register 0 of the TDC-GP22 chip; Determine the calibration cycle number of the 32.768kHz crystal oscillator clock based on the parameter settings.
[0018] By adopting the above technical solution, the parameters of register 0 of the TDC-GP22 chip are dynamically configured, and the calibration cycle number of the 32.768kHz crystal oscillator is flexibly adjusted, achieving an intelligent balance between calibration accuracy and power consumption.
[0019] In a preferred example of the present application, it can be further configured as follows: The lower limit of the calibration coefficient standard range is 0.9, and the upper limit of the calibration coefficient standard range is 1.1.
[0020] By adopting the above technical solution, coefficient errors caused by unexpected situations are avoided.
[0021] Second aspect, the present application provides an ultrasonic water meter, adopting the following technical solution: An ultrasonic water meter, comprising: a micro control unit, a TDC-GP22 chip, a 32.768 kHz crystal oscillator clock, and a 4 MHz crystal oscillator clock; The 32.768 kHz crystal oscillator clock is connected to the micro control unit, and is used to provide a real-time local clock signal and calibrate the 4 MHz crystal oscillator clock; The TDC-GP22 chip is connected to the micro control unit, and is used to control the emission and echo reception of ultrasonic pulses and measure the flight time of ultrasonic waves; The 4 MHz crystal oscillator clock is connected to the TDC-GP22 chip, and is used to provide a high-frequency clock for the TDC-GP22 chip.
[0022] In summary, the present application includes the following beneficial technical effects: The present application calculates a first calibration coefficient based on the deviation between the network time and the local RTC time, dynamically corrects the long-term cumulative error of the 32.768 kHz crystal oscillator, takes the calibrated 32.768 kHz clock as a reference, counts the actual number of cycles of the 4 MHz crystal oscillator within a standard time duration, generates a second calibration coefficient, eliminates the short-term frequency fluctuation of the high-speed crystal oscillator, and finally compensates for the deviation of both the low-speed reference clock and the high-speed measurement clock during flow calculation to obtain a corrected flight time, improving the accuracy of the crystal oscillator clock in the ultrasonic water meter without increasing the hardware cost. Description of the Drawings
[0023] Figure 1 is a schematic flowchart of a method for calibrating a crystal oscillator clock of an ultrasonic water meter based on the Internet of Things provided by an embodiment of the present application; Figure 2 is a schematic flowchart of calibrating a 32.768 kHz crystal oscillator clock based on the current network time provided by an embodiment of the present application; Figure 3 is a schematic flowchart of calibrating a 4 MHz crystal oscillator clock based on the 32.768 kHz crystal oscillator clock provided by an embodiment of the present application; Figure 4 is a schematic flowchart of correcting the flight time difference within a complete flow measurement cycle provided by an embodiment of the present application. Detailed Embodiments
[0024] The following will further describe the present application in detail with reference to the appended Figure 1 - appended Figure 4 drawings.
[0025] This specific embodiment is only an interpretation of the present application and does not limit the present application. After reading this specification, those skilled in the art can make modifications to this embodiment without creative contributions as needed, but as long as it is within the scope of the claims of the present application, it is protected by the patent law.
[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative efforts belong to the scope of protection of the present application.
[0027] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this article generally represents an "or" relationship between the associated objects before and after, unless otherwise specified.
[0028] It should be noted that in the optional embodiments of the present application, for relevant data such as object information, when the embodiments in the present application are applied to specific products or technologies, object permission or consent is required, and the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of the relevant countries and regions. That is to say, if the embodiments of the present application involve data related to objects, it needs to be obtained under the authorization and consent of the objects, the authorization and consent of the relevant departments, and in compliance with the relevant laws, regulations, and standards of the relevant countries and regions. If personal information is involved in the embodiments, the acquisition of all personal information requires the consent of the individual. If sensitive information is involved, the separate consent of the information subject needs to be obtained, and the embodiments also need to be implemented under the authorization and consent of the objects.
[0029] Since the microcontroller unit (MCU) of the ultrasonic water meter integrates a real-time clock peripheral (RTC), which can be used to display and record the time of the water meter, the clock source of the RTC comes from the 32.768 kHz crystal oscillator clock connected to the microcontroller unit. If the 32.768 kHz crystal oscillator clock deviates, it will also cause the RTC to deviate. Specifically, after the ultrasonic water meter runs for a period of time, the time in the meter deviates from the standard time.
[0030] With the development of the Internet of Things, Internet of Things-based (NB-IOT, 4G, etc.) ultrasonic water meters have become a new development trend, supporting the function of network connection and upload. After successful network connection, the accurate time of the network (including year, month, day, hour, minute, and second) can be read through the micro-control unit, and then the RTC real-time time of the local area can be read. Through the deviation between the two times, the dynamic deviation of the 32.768kHz crystal oscillator clock can be calculated, and a calibration coefficient for the 32.768kHz crystal oscillator clock can be added. After each successful network connection, this calibration coefficient is dynamically calculated, and finally, this calibration coefficient is associated with the correction process of the 4MHz crystal oscillator clock to calculate the calibration coefficient of the 4MHz crystal oscillator clock. The product of the calibration coefficient of the 32.768kHz crystal oscillator clock and the calibration coefficient of the 4MHz crystal oscillator clock is used as the final calibration coefficient of the 4MHz crystal oscillator clock to achieve the dynamic correction function of the 4MHZ crystal oscillator. Finally, the final calibration coefficient is associated with the calculation of the time difference of flight time between the upstream and downstream of the ultrasonic wave, thereby reducing the deviation of ultrasonic time measurement, reducing the flow error of the ultrasonic water meter, and improving the stability and reliability of the ultrasonic water meter.
[0031] The embodiment of the present application provides a method for calibrating the crystal oscillator clock of an ultrasonic water meter based on the Internet of Things, as Figure 1 shown. In the method provided in the embodiment of the present application, it is executed by the micro-control unit of the ultrasonic water meter. The method includes steps S101 - step S104, where: S101. Obtain the current network time, the current local time, and the start time of the current calibration period, and determine the first calibration coefficient of the 32.768kHz crystal oscillator clock based on the current network time, the current local time, and the start time.
[0032] Specifically, the calibration period can be preset manually according to actual experience, and the duration of the calibration period is not limited in this embodiment. The start time of the current calibration period is the end time of the previous calibration period, which is stored in the memory of the ultrasonic water meter at the end of the previous calibration period.
[0033] After the Internet of Things ultrasonic water meter determines that the upload time has arrived, it starts to connect to the network and upload. After successful network connection, it reads the current network time and the current local time (RTC local time). Furthermore, it judges whether the calibration flag of the 32.768kHz crystal oscillator clock is valid. When the calibration flag of the 32.768kHz crystal oscillator clock is valid, it calculates the first time interval between the current network time and the start time, and the second time interval between the current local time and the start time, and then determines the first calibration coefficient of the 32.768kHz crystal oscillator clock based on the first time interval and the second time interval.
[0034] S102. Obtain the calibration cycle number of the 32.768kHz crystal oscillator clock, and determine the standard duration and the actual test duration for calibrating the 4MHz crystal oscillator clock based on the calibration cycle number.
[0035] Specifically, represent the calibration period as N, that is, use the periods of N 32.768 kHz crystal oscillator clocks to calibrate the 4 MHz crystal oscillator clock. Determine the standard duration for calibrating the 4 MHz crystal oscillator clock based on the calibration period, send a calibration instruction containing the standard duration to the TDC-GP22 chip, and receive the interrupt signal containing the actual number of clock cycles returned after the TDC-GP22 chip completes calibration. Calculate the actual test duration of the 4 MHz crystal oscillator clock based on the actual number of clock cycles.
[0036] S103. Determine the second calibration coefficient of the 4 MHz crystal oscillator clock based on the standard duration and the actual test duration.
[0037] Specifically, calculate the ratio of the standard duration to the actual test duration as the second intermediate variable. Determine whether the second intermediate variable is within the standard range of the calibration coefficient. If the second intermediate variable is within the standard range of the calibration coefficient, then use the second intermediate variable as the second calibration coefficient of the 4 MHz crystal oscillator clock.
[0038] In a possible implementation manner of the embodiment of the present application, the lower limit of the standard range of the calibration coefficient is 0.9, and the upper limit of the standard range of the calibration coefficient is 1.1.
[0039] Among them, the standard range of the calibration coefficient can be preset manually. The purpose of setting the standard range of the calibration coefficient is to prevent an abnormal calibration once, resulting in the calibration coefficient exceeding the reasonable range, and avoid the coefficient error caused by unexpected situations.
[0040] S104. During the actual flow measurement process, correct the flight time of the ultrasonic water meter based on the first calibration coefficient and the second calibration coefficient.
[0041] In the ultrasonic water meter, the flight time refers to the time experienced by the ultrasonic signal from being emitted by the transmitting sensor, passing through the fluid propagation, and being captured by the receiving sensor. The flight time is used to calculate the flow rate.
[0042] Take the flight time measured by the ultrasonic water meter as the measured flight time, and then calibrate the measured flight time, including: calculate the product of the first calibration coefficient and the second calibration coefficient as the final calibration coefficient, correct the measured flight time based on the final calibration coefficient, and the obtained result is used as the flight time.
[0043] In this embodiment, the deviation between the network time and the local RTC time is used to calculate the first calibration coefficient, dynamically correct the long-term cumulative error of the 32.768 kHz crystal oscillator. Based on the calibrated 32.768 kHz clock, the actual number of cycles of the 4 MHz crystal oscillator within the standard duration is counted to generate the second calibration coefficient, eliminating the short-term frequency fluctuation of the high-speed crystal oscillator. Finally, when calculating the flow rate, the deviation of both the low-speed reference clock and the high-speed measurement clock is compensated to obtain the corrected flight time, improving the accuracy of the crystal oscillator clock in the ultrasonic water meter without increasing the hardware cost.
[0044] A possible implementation of the embodiment of the present application determines the first calibration coefficient of the 32.768 kHz crystal oscillator clock based on the current network time, the current local time, and the starting time, including: Determine whether the calibration flag of the 32.768 kHz crystal oscillator clock is valid; If the calibration flag is valid, calculate the first time interval between the current network time and the starting time, and the second time interval between the current local time and the starting time; Calculate the ratio of the first time interval and the second time interval as the first intermediate variable; Determine whether the first intermediate variable is within the calibration coefficient standard range. If the first intermediate variable is within the calibration coefficient standard range, use the first intermediate variable as the first calibration coefficient of the 32.768 kHz crystal oscillator clock.
[0045] See Figure 2 , which shows a schematic flowchart of calibrating the 32.768 kHz crystal oscillator clock based on the current network time. The starting time of the current calibration period, that is, the last read network time / last read local time, the first time interval represents the time interval between the current read network time and the last read network time, and the second time interval represents the time interval between the current read local time and the last read local time. The units of the first time interval and the second time interval are the same. Optionally, the units of both the first time interval and the second time interval are s. Calculating both the first time interval and the second time interval can be implemented through built-in function programs, and the type of function is not limited in this embodiment.
[0046] If the first intermediate variable is not within the calibration coefficient standard range, it means that the coefficient calibration fails this time, and the value of the first intermediate variable is discarded.
[0047] In this embodiment, by checking the validity of the calibration flag, the reliability of the calibration data is ensured. By comparing the cumulative difference between the network time and the local time within the same start and end periods, the clock drift ratio (the first intermediate variable) is calculated. Through threshold judgment, the calibration coefficient is updated only when the ratio is within a reasonable range, improving the accuracy of the calibration coefficient.
[0048] In a possible implementation manner of the embodiment of the present application, if the calibration flag is invalid, or the first intermediate variable is not within the standard range of the calibration coefficient, the method further includes: Calibrate the 32.768 kHz crystal oscillator clock using the current network time; Use the current network time as the start time of the next calibration period; Mark the calibration flag of the 32.768 kHz crystal oscillator clock as valid.
[0049] In this embodiment, substitute the current network time into the function RTC_SetTime(datetime_strwritetime) to calibrate the RTC real-time clock of the microcontroller unit, so that the local time is synchronized with the network time. The calibration flag of the 32.768 kHz crystal oscillator clock can be represented by a variable, and the variable is True / False. True indicates that the calibration flag is valid, and False indicates that the calibration flag is invalid. Marking the calibration flag of the 32.768 kHz crystal oscillator clock as valid is to mark the next calibration period as valid.
[0050] At any stage of the operation of the Internet of Things ultrasonic water meter program, if there are other non-network time calibration operations (such as time calibration through RS485, MBUS or infrared interface), or the ultrasonic water meter has a reset and restart operation, the calibration flag of the 32.768 kHz crystal oscillator clock will be set to False (because these operations will cause changes in the RTC real-time clock, affecting the accuracy of calculating the time interval between the current local time read by the variable and the local time read last time. The first calibration coefficient is not calculated in this calibration period, that is, the calibration of this period is invalid).
[0051] In this embodiment, when the calibration flag is invalid or the calibration deviation exceeds the limit, the forced calibration process is automatically triggered, and the high-precision network time is directly used to overwrite the local RTC time, which can eliminate the cumulative error of the crystal oscillator, update the start timestamp of the calibration period, ensure that the subsequent interval calculation is based on the new benchmark, and mark the calibration valid state, which helps to restore the normal operation of the system.
[0052] In a possible implementation manner of the embodiment of the present application, the method further includes: Receive the parameter setting for register 0 of the TDC-GP22 chip; Determine the calibration period number of the 32.768 kHz crystal oscillator clock based on the parameter setting.
[0053] In this embodiment, the TDC-GP22 chip itself supports the automatic calibration function for the 4MHz crystal oscillator clock. The parameter setting of register 0 (denoted by n) is used to determine the calibration cycle number N of the 32.768kHz crystal oscillator clock, that is, the 4MHz crystal oscillator clock is calibrated with N cycles of the 32.768kHz crystal oscillator clock. When the microcontroller powers on and initializes the TDC-GP22 chip, the parameters of register 0 can be set manually. Refer to Figure 3 , which shows a schematic flow chart for calibrating the 4MHz crystal oscillator clock based on the 32.768kHz crystal oscillator clock.
[0054] The frequency of the 32.768kHz crystal oscillator clock is 32768, that is, the crystal vibrates 32768 times per second. Correspondingly, the period of the 32.768kHz crystal oscillator clock = 1 / 32768 s = 30.5175 µs. N = 2 n+1 , that is, when the parameter setting n of register 0 is 0, N = 2, and 2 cycles = 61.035 µs; when the parameter setting n of register 0 is 1, N = 4, and 4 cycles = 122.07 µs; when the parameter setting n of register 0 is 2, N = 8, and 8 cycles = 244.14 µs; when the parameter setting n of register 0 is 3, N = 16, and 16 cycles = 488.281 µs.
[0055] Optionally, in this embodiment, the parameter setting of register 0 is 1, and the corresponding calibration cycle number N = 4. The 4MHz crystal oscillator clock is calibrated with 4 cycles of the 32.768kHz crystal oscillator clock.
[0056] In this embodiment, by dynamically configuring the parameters of register 0 of the TDC-GP22 chip and flexibly adjusting the calibration cycle number of the 32.768kHz crystal oscillator, an intelligent balance between calibration accuracy and power consumption is achieved.
[0057] A possible implementation manner of the embodiment of the present application is to determine the standard duration and the actual test duration for calibrating the 4MHz crystal oscillator clock based on the calibration cycle number, including: Determining the standard duration for calibrating the 4MHz crystal oscillator clock based on the calibration cycle number; Sending a calibration instruction including the standard duration to the TDC-GP22 chip, and receiving an interrupt signal including the actual clock cycle number returned by the TDC-GP22 chip after calibration is completed; Calculating the actual test duration of the 4MHz crystal oscillator clock based on the actual clock cycle number.
[0058] In this embodiment, the calibration period N = 4. Four cycles of the 32.768 kHz crystal oscillator clock are 122.07 μs, that is, the standard duration is 122.07 μs. The microcontroller unit sends a calibration instruction containing the standard duration. After receiving the calibration instruction, the TDC-GP22 chip starts automatic calibration and counts the actual clock cycles of the 4 MHz crystal oscillator clock within a fixed time window (within the standard duration). After calibration is completed, an interrupt signal is sent to the microcontroller unit. After receiving the interrupt signal, the microcontroller unit reads the value of register 0 of the TDC-GP22 chip to obtain the actual clock cycle count. The period of the 4 MHz crystal oscillator clock is 0.25 μs, and the product of the actual clock cycle count and 0.25 μs is used as the actual test duration.
[0059] In this embodiment, the theoretical standard duration is calculated based on the number of calibration cycles of 32.768 kHz (such as 4 cycles), triggering the TDC-GP22 chip to accurately count the actual cycles of the 4 MHz clock within this time window, converting the actual cycle count into the test duration, and accurately calculating the time deviation of the 4 MHz ceramic crystal oscillator.
[0060] A possible implementation manner of the embodiment of the present application determines a second calibration coefficient of the 4 MHz crystal oscillator clock based on the standard duration and the actual test duration, including: Calculating the ratio of the standard duration to the actual test duration as a second intermediate variable; Determining whether the second intermediate variable is within the calibration coefficient standard range. If the second intermediate variable is within the calibration coefficient standard range, the second intermediate variable is used as the second calibration coefficient of the 4 MHz crystal oscillator clock.
[0061] If the second intermediate variable is not within the calibration coefficient standard range, the second intermediate variable is discarded, indicating that the coefficient calibration fails this time.
[0062] In this embodiment, the deviation between the theoretical standard duration and the actual test duration is quantified and compared to generate a second calibration coefficient, realizing precise compensation for the 4 MHz crystal oscillator. When the ratio is within the reasonable range of the calibration coefficient standard range, this coefficient is adopted to correct the frequency error, improving the accuracy of the second calibration coefficient.
[0063] A possible implementation manner of the embodiment of the present application corrects the flight time of the ultrasonic water meter based on the first calibration coefficient and the second calibration coefficient, including: Obtaining the measured flight time of the ultrasonic water meter; Calculating the product of the first calibration coefficient and the second calibration coefficient as the final calibration coefficient; Taking the product of the measured flight time and the final calibration coefficient as the corrected flight time for calculating the flow rate using the corrected flight time.
[0064] Specifically, refer toFigure 4 , which shows a schematic flow chart for correcting the difference in flight time within a complete flow measurement cycle. Substitute the corrected flight time into the relevant flow calculation formula to obtain the instantaneous flow rate and the cumulative flow rate, thus completing the flow measurement process.
[0065] In this embodiment, the measured flight time is subjected to composite compensation through the combined action of two-level calibration coefficients. The first calibration coefficient corrects the long-term systematic deviation of the 32.768 kHz crystal oscillator clock, and the second calibration coefficient eliminates the short-term random fluctuation of the 4 MHz crystal oscillator clock. Multiply the product of the two as the final calibration coefficient by the original flight time to achieve full-scale error compensation, enabling the flow measurement result to have both long-term stability and instantaneous accuracy.
[0066] The above are only partial embodiments of the present application. It should be noted that for those of ordinary skill in the art of this technology, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. An ultrasonic water meter crystal oscillator clock calibration method based on the Internet of Things, characterized in that The method is executed by a micro control unit of an ultrasonic water meter, and the method includes: Obtaining the current network time, the current local time, and the start time of the current calibration period, and determining a first calibration coefficient of a 32.768 kHz crystal oscillator clock based on the current network time, the current local time, and the start time; Obtaining the number of calibration periods of the 32.768 kHz crystal oscillator clock, and determining a standard duration and an actual test duration for calibrating a 4 MHz crystal oscillator clock based on the number of calibration periods; Determining a second calibration coefficient of the 4 MHz crystal oscillator clock based on the standard duration and the actual test duration; During the actual flow measurement process, correcting the flight time of the ultrasonic water meter based on the first calibration coefficient and the second calibration coefficient.
2. The method for calibrating the crystal oscillator clock of the ultrasonic water meter based on the Internet of Things according to claim 1, wherein The determining a first calibration coefficient of a 32.768 kHz crystal oscillator clock based on the current network time, the current local time, and the start time includes: Judging whether a calibration identifier of the 32.768 kHz crystal oscillator clock is valid; If the calibration identifier is valid, calculating a first time interval between the current network time and the start time, and a second time interval between the current local time and the start time; Calculating a ratio of the first time interval and the second time interval as a first intermediate variable; Judging whether the first intermediate variable is within a calibration coefficient standard range, and if the first intermediate variable is within the calibration coefficient standard range, using the first intermediate variable as the first calibration coefficient of the 32.768 kHz crystal oscillator clock.
3. The crystal oscillator clock calibration method for an ultrasonic water meter based on the Internet of Things according to claim 2, characterized in that, If the calibration identifier is invalid, or the first intermediate variable is not within the calibration coefficient standard range, the method further includes: Calibrating the 32.768 kHz crystal oscillator clock by using the current network time; Using the current network time as the start time of the next calibration period; Marking the calibration identifier of the 32.768 kHz crystal oscillator clock as valid.
4. The method for calibrating the crystal oscillator clock of the ultrasonic water meter based on the Internet of Things according to claim 1, characterized in that The determining a standard duration and an actual test duration for calibrating a 4 MHz crystal oscillator clock based on the number of calibration periods includes: Determining a standard duration for calibrating the 4 MHz crystal oscillator clock based on the number of calibration periods; Sending a calibration instruction including the standard duration to a TDC-GP22 chip, and receiving an interrupt signal including the actual number of clock cycles returned by the TDC-GP22 chip after calibration is completed; Calculating an actual test duration of the 4 MHz crystal oscillator clock based on the actual number of clock cycles.
5. The method for calibrating the crystal oscillator clock of the ultrasonic water meter based on the Internet of Things according to claim 1, wherein The determining a second calibration coefficient of the 4 MHz crystal oscillator clock based on the standard duration and the actual test duration includes: Calculating a ratio of the standard duration and the actual test duration as a second intermediate variable; Judging whether the second intermediate variable is within a calibration coefficient standard range, and if the second intermediate variable is within the calibration coefficient standard range, using the second intermediate variable as the second calibration coefficient of the 4 MHz crystal oscillator clock.
6. The method for calibrating the crystal oscillator clock of an ultrasonic water meter based on the Internet of Things according to claim 1, wherein The correcting the flight time of the ultrasonic water meter based on the first calibration coefficient and the second calibration coefficient includes: Obtaining the measured flight time of the ultrasonic water meter; Calculate the product of the first calibration coefficient and the second calibration coefficient as the final calibration coefficient; Use the product of the measured flight time and the final calibration coefficient as the corrected flight time to calculate the flow rate using the corrected flight time.
7. The crystal oscillator clock calibration method for an ultrasonic water meter based on the Internet of Things according to claim 1, characterized in that, The method further includes: Receiving a parameter setting for register 0 of the TDC-GP22 chip; Determining the calibration cycle number of the 32.768 kHz crystal oscillator clock based on the parameter setting.
8. The method for calibrating the crystal oscillator clock of the ultrasonic water meter based on the Internet of Things according to claim 1, wherein, The lower limit of the standard range of the calibration coefficient is 0.9, and the upper limit of the standard range of the calibration coefficient is 1.
1.
9. An ultrasonic water meter, characterized in that, including: A microcontroller unit, a TDC-GP22 chip, a 32.768 kHz crystal oscillator clock, and a 4 MHz crystal oscillator clock; The 32.768 kHz crystal oscillator clock is connected to the microcontroller unit to provide a real-time local clock signal and calibrate the 4 MHz crystal oscillator clock; The TDC-GP22 chip is connected to the microcontroller unit to control the emission and echo reception of ultrasonic pulses and measure the flight time of ultrasonic waves; The 4 MHz crystal oscillator clock is connected to the TDC-GP22 chip to provide a high-frequency clock for the TDC-GP22 chip.