Data storage method
By having the control unit acquire flow values at intervals from the flow sensor and store the data in flash memory when the dynamic random access memory reaches a certain threshold, the problem of data loss when the flow sensor is powered off is solved, resulting in more accurate data recording and extended memory life.
Patent Information
- Application Number
- CN202511696175.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-19
- Publication Date
- 2026-02-17
AI Technical Summary
Existing flow sensors are prone to data loss and recording errors when power is off, as the flow values in the dynamic random access memory are not written to the flash memory in a timely manner.
The control unit acquires and accumulates flow values at predetermined intervals. When a certain threshold is reached, the small cumulative cache value of the dynamic random access memory is used to store the data in the flash memory. When the flash memory reaches its capacity, a unary coding method is used to manage the storage space, thereby extending the memory life.
It reduces the loss of traffic data, improves the accuracy of data recording, and extends the lifespan of flash memory.
Smart Images

Figure CN121541830A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a data storage method, and more particularly to a data storage method that can reduce the cumulative loss of data. Background Technology
[0002] A flow sensor is a sensor used to detect cumulative flow. It can be used for detecting liquids and gases, such as in water meters and gas meters, and can also be used in any sensor requiring cumulative flow functionality, such as smart meters. Existing flow sensors record the flow rate per unit measurement time in a Dynamic Random Access Memory (RAM), and then write the flow rate value recorded in the RAM to a Flash Memory every 2 minutes or 5 minutes. This avoids writing data to the Flash Memory too frequently, which would shorten its lifespan. However, if a power outage occurs during this period, the flow rate value in the RAM will not have time to be written to the Flash Memory and will disappear, leading to an error between the flow rate value recorded in the Flash Memory and the actual flow rate value. Summary of the Invention
[0003] The purpose of this invention is to provide a data storage method for flow sensors that can reduce the loss of accumulated data.
[0004] The present invention provides a data storage method applicable to flow sensors, dynamic random access memory, flash memory, and control units, and implemented by the control unit, and includes steps S1 to S5.
[0005] In step S1, the flow rate value from the flow sensor is obtained at predetermined time intervals, and the flow rate value is multiplied by the predetermined time to obtain the value to be accumulated.
[0006] In step S2, the small cumulative cache value stored in the dynamic random access memory is added to the value to be accumulated.
[0007] In step S3, when it is determined that the small accumulated cache value is greater than a predetermined value, the predetermined value is subtracted from the small accumulated cache value stored in the dynamic random access memory, and the predetermined value is added to the actual accumulated value stored in the dynamic random access memory. The predetermined value is an integer, and the actual accumulated value is equal to the accumulated offset of the higher significant bit of the binary number plus the accumulated detailed offset of the lower significant bit of the binary number.
[0008] In step S4, after adding the predetermined value to the actual accumulated value, it is determined whether the value stored in the accumulated memory of the flash memory is full.
[0009] In step S5, when it is determined that the value stored in the cumulative memory is not full, the cumulative detailed offset value of the dynamic random access memory is stored in the cumulative memory of the flash memory.
[0010] In some embodiments, the data storage method further includes steps S6, S7, S9, and S10 between steps S4 and S5.
[0011] In step S6, when it is determined that the value stored in the cumulative memory is full, the cumulative offset value of the dynamic random access memory is added to the value stored in the cumulative memory.
[0012] In step S7, it is determined whether the data stored in the designated memory of the flash memory is full.
[0013] In step S9, when it is determined that the data stored in the designated memory of the flash memory is not full, the cumulative offset value of the dynamic random access memory is stored in the designated memory of the flash memory.
[0014] In step S10, the value stored in the cumulative memory of the flash memory is erased.
[0015] In some embodiments, the data storage method further includes step S8 between steps S7 and S9.
[0016] In step S8, when it is determined that the data stored in the designated memory of the flash memory is full, the data stored in the designated memory of the flash memory is erased, and then step S9 is executed.
[0017] In some implementations, in step S5, the cumulative memory of the flash memory stores the cumulative detailed offset value in a unary encoded manner.
[0018] In some implementations, the predetermined value in step S3 is 1.
[0019] The beneficial effect of the present invention is that: the value to be accumulated obtained at each predetermined time interval is stored in the small cumulative cache value of the dynamic random access memory, and the cumulative detailed offset value of the actual accumulated value of the dynamic random access memory is stored in the cumulative memory of the flash memory only when it is determined that the small cumulative cache value is greater than the predetermined value, thereby reducing the loss of accumulated data. Attached Figure Description
[0020] Figure 1This is a block diagram illustrating a flow sensor, a dynamic random access memory, a flash memory, and a control unit to which the data storage method of this invention applies; and
[0021] Figure 2 This is a flowchart illustrating one embodiment of the data storage method of the present invention. Detailed Implementation
[0022] See Figure 1 and Figure 2 One embodiment of the data storage method of the present invention is applicable to a flow sensor 2, a dynamic random access memory (RAM) 3, a flash memory (Flash) 4, and a control unit 1, and includes steps S1 to S10. The flow sensor 2 is used, for example, to detect water volume to obtain a flow rate value in liters per minute (LPM), but is not limited thereto. The control unit 1 is, for example, but not limited to, a microcontroller (MCU).
[0023] In step S1, the control unit 1 acquires the flow rate value from the flow sensor 2 at predetermined time intervals and multiplies the flow rate value by the predetermined time to obtain a value to be accumulated. In this embodiment, the predetermined time is 100 milliseconds, and the value to be accumulated is a floating-point number less than 1, such as 0.00833(L) = 5(LPM) * 100(ms). Next, step S2 is executed.
[0024] In step S2, the control unit 1 adds a small cumulative cache value stored in the dynamic random access memory 3 to the value to be accumulated. Then, step S3 is executed.
[0025] In step S3, when the control unit 1 determines that the small accumulated cache value is greater than a predetermined value, it subtracts the predetermined value from the small accumulated cache value stored in the dynamic random access memory 3, and adds the predetermined value to an actual accumulated value stored in the dynamic random access memory 3. The predetermined value is an integer. In this embodiment, the small accumulated cache value stored in the dynamic random access memory 3 is a 32-bit floating-point number, and the predetermined value is 1.
[0026] The actual accumulated value is equal to the accumulated offset of the more significant bit of the binary representation plus the accumulated fine offset of the less significant bit. For example, if the actual accumulated value ranges from 0 to 65535, that is, between 0x0000 0000 and 0x0000 FFFF, and the actual accumulated value is, for example, 0x0004 93E0, then the accumulated offset is equal to 0x0004, and the accumulated fine offset is equal to 0x93E0. Next, step S4 is executed.
[0027] In step S4, after adding the predetermined value to the actual accumulated value, the control unit 1 determines whether the value stored in one of the accumulation memories of the flash memory 4 is full. When the control unit 1 determines that the value stored in the accumulation memory is full, step S6 is executed; when the control unit 1 determines that the value stored in the accumulation memory is not full, step S5 is executed. For example, the accumulation memory has 65536 bytes, that is, the maximum value is 65535 (i.e., 0x0000 FFFF). Since the value is stored in unary coding, the value is full when the value in the accumulation memory is equal to 0x0000 FFFF.
[0028] In step S5, the control unit 1 stores the cumulative detailed offset value of the dynamic random access memory 3 into the cumulative memory of the flash memory 4. That is, the cumulative memory of the flash memory 4 stores the cumulative detailed offset value in a unary encoding manner.
[0029] In step S6, the control unit 1 adds the accumulated offset value of the dynamic random access memory 3 to the value stored in the accumulated memory. In this embodiment, the dynamic random access memory 3 also stores 256 bytes of setting data, which includes a setting value and the accumulated offset value. The setting data includes, for example, user-configurable data such as units, screen brightness, language, transmission speed, IP address, DHCP enable, etc. The accumulated offset value is, for example, a 32-bit signed integer. Next, step S7 is executed.
[0030] In step S7, the control unit 1 determines whether the data stored in a setting memory of the flash memory 4 is full. In this embodiment, the flash memory 4 has a setting memory of 16384 bytes, which includes 64 blocks of the same size, each block being used to store one piece of setting data. That is, when the setting memory is written to or written to 64 times, the data stored in the setting memory (i.e., the space) is full.
[0031] When the control unit 1 determines that the data stored in the setting memory is full (i.e., the space is full), it executes step S8; when the control unit 1 determines that the data stored in the setting memory is not full (i.e., the space is not full), it executes step S9.
[0032] In step S8, the control unit 1 erases (i.e. deletes) the data stored in the setting memory of the flash memory 4, that is, releases the corresponding space. Then, step S9 is executed.
[0033] In step S9, the control unit 1 stores the accumulated offset value of the dynamic random access memory 3 into the setting memory of the flash memory 4. In this embodiment, the control unit 1 stores the setting data of the dynamic random access memory 3 into one block of the setting memory of the flash memory 4. Next, step S10 is executed.
[0034] In step S10, the control unit 1 erases (i.e. deletes) the value stored in the cumulative memory of the flash memory 4, that is, releases the corresponding space. Then, step S5 is executed.
[0035] In this embodiment, steps S1 to S3 are executed every 0.1 seconds, while in the prior art, the flow rate value recorded in the dynamic random access memory is written to the flash memory every 2 to 5 minutes. Assuming the detected flow rate is 60 liters per minute, and the entire system is only powered on for one minute before being shut down, this invention can clearly record the flow rate value more accurately. On the other hand, since the setting memory of the flash memory 4 uses each block to record one setting data, the lifespan of the flash memory 4 can also be extended.
[0036] In summary, by storing the value to be accumulated at predetermined intervals in the small cumulative cache value of the dynamic random access memory 3, and storing the accumulated detailed offset value of the actual accumulated value of the dynamic random access memory 3 into the cumulative memory of the flash memory 4 when the small cumulative cache value is determined to be greater than the predetermined value, and storing the accumulated offset value of the actual accumulated value of the dynamic random access memory 3 into the setting memory of the flash memory 4, the loss of accumulated data can be reduced, and the purpose of the present invention can indeed be achieved.
[0037] The above description is merely an embodiment of the present invention and should not be construed as limiting the scope of the present invention. Any simple equivalent changes and modifications made in accordance with the claims and description of the present invention shall still fall within the scope of the present invention.
Claims
1. A data storage method, applicable to a flow sensor, dynamic random access memory, flash memory, and a control unit, and implemented through the control unit, characterized in that: The data storage method includes the following steps: Step S1: Obtain the flow rate value from the flow sensor at predetermined time intervals, and multiply the flow rate value by the predetermined time interval to obtain the value to be accumulated; Step S2: Add the small cumulative cache value stored in the dynamic random access memory to the value to be accumulated; Step S3: When it is determined that the small cumulative cache value is greater than a predetermined value, the small cumulative cache value stored in the dynamic random access memory is subtracted from the predetermined value, and the actual cumulative value stored in the dynamic random access memory is added to the predetermined value. The predetermined value is an integer, and the actual cumulative value is equal to the cumulative offset value of the higher significant bit of binary plus the cumulative detailed offset value of the lower significant bit of binary. Step S4: After adding the predetermined value to the actual accumulated value, determine whether the value stored in the accumulated memory of the flash memory is full. and Step S5: When it is determined that the value stored in the cumulative memory is not full, the cumulative detailed offset value of the dynamic random access memory is stored in the cumulative memory of the flash memory.
2. The data storage method according to claim 1, characterized in that: The data storage method further includes steps S6, S7, S9, and S10 between steps S4 and S5. In step S6, when it is determined that the value stored in the cumulative memory is full, the cumulative offset value of the dynamic random access memory is added to the value stored in the cumulative memory. In step S7, it is determined whether the data stored in the designated memory of the flash memory is full. In step S9, when it is determined that the data stored in the designated memory of the flash memory is not full, the cumulative offset value of the dynamic random access memory is stored in the designated memory of the flash memory, and In step S10, the values stored in the cumulative memory of the flash memory are erased.
3. The data storage method according to claim 2, characterized in that: The data storage method further includes step S8 between steps S7 and S9. In step S8, when it is determined that the data stored in the designated memory of the flash memory is full, the data stored in the designated memory of the flash memory is erased, and then step S9 is executed.
4. The data storage method according to claim 3, characterized in that: In step S5, the cumulative memory of the flash memory stores the cumulative detailed offset value in a unary encoded manner.
5. The data storage method according to claim 1, characterized in that: In step S3, the predetermined value is 1.