Battery power detection method, electronic device and storage medium
By adopting sliding window technology and voltage correction compensation mechanism in low-power video surveillance equipment, the ADC module and SOC main control chip of embedded devices are used to solve the problem of inaccurate battery voltage detection, and a stable and cost-controllable battery management is achieved.
Patent Information
- Application Number
- CN202510479805.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-04-17
AI Technical Summary
Existing low-power video surveillance equipment has high cost and low stability in battery management. The battery voltage is susceptible to load changes and temperature fluctuations, resulting in inaccurate battery detection.
The battery power detection method based on the sliding window is adopted, and the battery voltage is read by the ADC module of the embedded device, and the power supply status of the SOC main control chip is used to correct and compensate. The average voltage value is calculated through the sliding window technology to determine the remaining battery power.
It reduces production costs, improves the stability and accuracy of battery power detection, and is suitable for applications of low-power video surveillance equipment.
Smart Images

Figure CN120103186B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of battery technology, and in particular to a battery power detection method based on a sliding window, an electronic device and a computer-readable storage medium. Background Art
[0002] In the low-power video surveillance industry, the performance requirements of battery management systems are increasing. With the widespread application of low-power video surveillance equipment, existing battery management methods have shown obvious shortcomings in terms of stability, accuracy and cost control.
[0003] First, most low-power video surveillance devices rely on a fuel gauge to read the battery voltage and communicate with a microcontroller (MCU) through an I2C interface. The MCU converts the voltage value read through a voltage and power percentage mapping table to calculate the power percentage and send it to the monitoring device to achieve battery power management. However, adding peripheral circuits such as a fuel gauge will significantly increase the production cost of the product and take up valuable hardware space.
[0004] Secondly, if the battery voltage is not read using a fuel gauge, and the battery voltage is sampled only by the ADC module built into the MCU, the battery voltage is easily affected by factors such as load changes and temperature fluctuations, resulting in inaccurate instantaneous voltage sampling values. This inaccuracy will directly affect the effectiveness of the battery management function, and further affect the performance and reliability of the entire low-power video surveillance system.
[0005] Therefore, there is an urgent need to develop more efficient, stable and cost-controlled battery management solutions to meet the stringent requirements of the low-power video surveillance industry for battery management. Summary of the invention
[0006] In view of this, the present invention proposes a battery power detection method based on a sliding window, an electronic device and a computer-readable storage medium, aiming to overcome the shortcomings of existing battery management methods such as high cost and low stability.
[0007] In order to solve the above problems, the present invention adopts the following technical solutions:
[0008] In a first aspect, the present invention proposes a battery power detection method based on a sliding window, which is applied to an embedded device, wherein the embedded device includes an ADC module, a SOC main control chip, an MCU micro control chip and a battery, and the battery power detection method includes:
[0009] The ADC module reads the original voltage value of the battery, and calculates the actual voltage value according to the original voltage value and a preset conversion formula;
[0010] Judge whether the battery is in a charging state according to the actual voltage value, obtain a corrected voltage value according to the judgment result, and obtain a compensation value according to the corrected voltage value and the power supply state of the SOC master chip;
[0011] Add the actual voltage value and the compensation value to calculate a compensated voltage value;
[0012] Use the compensated voltage value to update the sliding window, and calculate the average voltage value of the valid voltage values in the updated sliding window, so as to determine the remaining power of the battery according to the average voltage value; wherein, a preset number of voltage values arranged in chronological order are stored in the sliding window.
[0013] Further, the method for reading the original voltage value of the battery through the ADC module and calculating the actual voltage value according to the original voltage value and a preset conversion formula includes:
[0014] Turn on the ADC module, read the original voltage value of the battery through the ADC module, and turn off the ADC module;
[0015] Substitute the original voltage value into the preset conversion formula to calculate the actual voltage value, and update the current actual voltage value to the calculated actual voltage value; wherein, the preset conversion formula is: actual voltage value = (original voltage value × standard operating voltage value of the ADC module) / resolution of the ADC module.
[0016] Further, the method for judging whether the battery is in a charging state according to the actual voltage value and obtaining a corrected voltage value according to the judgment result includes:
[0017] If the actual voltage value is greater than or equal to a preset charger connection threshold, it is determined that the battery is in a charging state; if the actual voltage value is less than the preset charger connection threshold, it is determined that the battery is in a non-charging state;
[0018] When the battery is in a charging state, disconnect the connection with the charger, wait for a preset first duration, then obtain the actual voltage value again, re-establish the connection with the charger, and add the re-obtained actual voltage value and a preset corrected voltage drop value to calculate the corrected voltage value;
[0019] When the battery is in a non-charging state, obtain the actual voltage value and record the actual voltage value as the corrected voltage value.
[0020] Further, the method for obtaining a compensation value according to the corrected voltage value and the power supply state of the SOC master chip includes:
[0021] When it is confirmed that the SOC master chip is in the powered-on working state, obtain the static compensation value and the dynamic compensation value, and add the static compensation value and the dynamic compensation value to calculate the compensation value; wherein, the static compensation value = the average voltage value of all valid voltage values in the current sliding window - the corrected voltage value - the dynamic compensation value, and the dynamic compensation value is obtained when the SOC master chip performs self-check;
[0022] When it is confirmed that the SOC master chip is in the non-working state, set the compensation value to 0.
[0023] Further, the using the compensation voltage value to update the sliding window and calculating the average voltage value of the valid voltage values in the updated sliding window includes:
[0024] Insert the compensation voltage value into the head of the sliding window, discard the voltage value at the tail of the sliding window, and move the other voltage values in the sliding window backward in sequence to complete the update of the sliding window;
[0025] Count the number of valid voltage values in the updated sliding window, and calculate the average voltage value of all valid voltage values in the updated sliding window; wherein, the average voltage value = the sum of all valid voltage values in the updated sliding window / the number.
[0026] Further, the determining the remaining power of the battery according to the average voltage value includes:
[0027] Compare the average voltage value with a preset voltage-capacity table; wherein, the preset voltage-capacity table includes voltage values, power percentages, and the one-to-one correspondence between the voltage values and the power percentages. The power percentages include 100%, 20%, and 0%. The voltage value corresponding to the power percentage of 100% is denoted as the highest threshold, the voltage value corresponding to the power percentage of 20% is denoted as the intermediate threshold, and the voltage value corresponding to the power percentage of 0% is denoted as the lowest threshold. The remaining power of the battery is represented in the form of a power percentage;
[0028] If the average voltage value is greater than the highest threshold, then the power percentage is 100%;
[0029] If the average voltage value is less than or equal to the highest threshold and greater than the intermediate threshold, substitute the average voltage value into a preset linear interpolation formula to calculate the power percentage corresponding to the average voltage value; wherein, the preset linear interpolation formula is: power percentage = high power percentage - [(high voltage value - average voltage value) / interval voltage value step size] × interval power percentage step size;
[0030] If the average voltage value is less than or equal to the intermediate threshold and greater than or equal to the lowest threshold, query the percentage of the battery power corresponding to the average voltage value in the preset voltage-capacity table;
[0031] If the average voltage value is less than the lowest threshold, the percentage of the battery power is 0%.
[0032] Further, before reading the original voltage value of the battery through the ADC module, the following steps are also included:
[0033] Start the MCU microcontroller chip, and perform voltage value sampling for a preset number of times after entering the sleep state for a preset second duration to obtain the remaining power of the battery;
[0034] Update the current remaining power of the battery with the obtained remaining power, and judge whether the remaining power is greater than the preset safe power;
[0035] If so, update the sliding window with the voltage value corresponding to the obtained remaining power to complete the initialization of the sliding window;
[0036] If not, the MCU microcontroller chip sleeps for a preset third duration at intervals until the remaining power of the battery is greater than the preset safe power.
[0037] Further, the battery power detection method further includes:
[0038] Determine the working mode of the MCU microcontroller chip;
[0039] When the MCU microcontroller chip is in the normal working mode, judge the mode of the SOC main control chip; if the SOC main control chip is in the low-power mode, detect the remaining power of the battery every preset fourth duration after the SOC main control chip is powered off; if the SOC main control chip is in the constant-power mode, detect the remaining power of the battery every preset fourth duration;
[0040] When the MCU microcontroller chip is in the factory test mode, detect the remaining power of the battery every preset fifth duration; where the preset fifth duration is less than the preset fourth duration;
[0041] When the MCU microcontroller chip is in the system upgrade mode, judge whether the remaining power of the battery is greater than the preset power threshold; if so, perform system upgrade, if not, do not start the system upgrade.
[0042] In a second aspect, the present invention also proposes an electronic device, the electronic device is an embedded device, and the embedded device includes:
[0043] A memory for storing program instructions; and
[0044] A processor for executing the program instructions to implement the steps of the sliding window-based battery power detection method as described above.
[0045] In a third aspect, the present invention also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the sliding window-based battery power detection method as described above.
[0046] Compared with the prior art, the beneficial effects of the present invention are as follows: A sliding window-based battery power detection method, an electronic device, and a computer-readable storage medium are applied to an embedded device, which includes an ADC module, an SOC main control chip, an MCU micro control chip, and a battery. The battery power detection method includes: reading the original voltage value of the battery through the ADC module, and calculating the actual voltage value according to the original voltage value and a preset conversion formula; judging whether the battery is in a charging state according to the actual voltage value, and obtaining a corrected voltage value according to the judgment result, and obtaining a compensation value according to the corrected voltage value and the power supply state of the SOC main control chip; adding the actual voltage value and the compensation value to calculate a compensated voltage value; using the compensated voltage value to update the sliding window, and calculating the average voltage value of the valid voltage values in the updated sliding window, so as to determine the remaining power of the battery according to the average voltage value; wherein, the sliding window stores a preset number of voltage values arranged in chronological order. It can be seen that the sliding window-based battery power detection method, the electronic device, and the computer-readable storage medium make full use of the ADC module inside the embedded device to sample the battery voltage, without the need for an additional external power meter or other peripheral circuits, thus significantly reducing the production cost of the product. At the same time, by judging the charging state of the battery and obtaining a corrected voltage value, the influence of the battery being in a charging state on the voltage sampling value is effectively eliminated. Combining with the power supply state of the SOC main control chip to calculate the compensation value can effectively compensate for the voltage reading deviation caused by the SOC main control chip being in a working state. In addition, in order to further improve the stability of battery voltage detection, the battery power detection method also adopts a sliding window technology, which allows multiple samplings of the battery voltage and calculates the average voltage value, thereby effectively smoothing the fluctuations of the instantaneous voltage sampling value and reducing the errors caused by load changes and temperature fluctuations. By combining the voltage correction, compensation mechanism, and sliding window technology, the stability and accuracy of the remaining battery power detection can be ensured, which is very suitable for application in low-power video surveillance devices. Description of the Drawings
[0047] By reading the detailed description of the preferred embodiments below, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered a limitation of the present invention. Also, throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:
[0048] Figure 1 is a schematic flowchart of the first embodiment of the battery power detection method based on a sliding window according to the present invention;
[0049] Figure 2 is a schematic flowchart of the second embodiment of the battery power detection method based on a sliding window according to the present invention;
[0050] Figure 3 is a schematic flowchart of the third embodiment of the battery power detection method based on a sliding window according to the present invention;
[0051] Figure 4 is a schematic flowchart of the fourth embodiment of the battery power detection method based on a sliding window according to the present invention;
[0052] Figure 5 is a schematic flowchart of the fifth embodiment of the battery power detection method based on a sliding window according to the present invention;
[0053] Figure 6 is a schematic diagram of the structure of an electronic device in the hardware operating environment related to the embodiment solution of the present invention. Detailed Embodiments
[0054] Next, the solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, 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 invention.
[0055] It should be noted that if there are directional indications (such as up, down, left, right, front, back...) involved in the embodiments of the present invention, the directional indications are only used to explain the relative positional relationship and movement conditions between components in a specific posture (as shown in the drawings). If the specific posture changes, the directional indications will also change accordingly.
[0056] In addition, if the embodiments of the present invention involve descriptions such as "first" and "second", the descriptions of "first", "second", etc. are only for descriptive purposes and should not be construed as indicating or implying their relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In addition, the technical solutions between various embodiments may be combined with each other, but it must be based on the ability of those of ordinary skill in the art to implement. When the combination of technical solutions results in contradictions or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0057] It should be noted that embedded devices are widely used in various fields, and video surveillance devices are a typical application scenario among them. The SOC main control chip (System on Chip) integrates a complete and complex system and supports multiple complex task processing. In this article, it specifically refers to the video main control chip used in security surveillance cameras. The MCU micro control chip (Microcontroller Unit) is a microcomputer chip integrating a processor, a memory, and an I / O interface, and is specifically used for the control of embedded devices. The steps of the battery power detection method mentioned in this article are mainly executed by the MCU. The ADC module (Analog-to-Digital Converter) is used to convert analog signals (such as voltage, temperature, light intensity) into digital signals for processing by digital systems (such as MCU / SOC). In this article, the ADC module is mainly used to identify the charging state of the battery and read the supply voltage. I2C (Inter-Integrated Circuit) is a synchronous, half-duplex serial communication protocol, mainly used for communication between short-distance devices.
[0058] Please refer to Figure 1 as shown, which is a schematic flowchart of the first embodiment of the battery power detection method based on a sliding window according to the present invention.
[0059] In this embodiment, the battery power detection method based on a sliding window is applied to an embedded device, which includes an ADC module, an SOC main control chip, an MCU micro control chip, and a battery. The battery power detection method includes:
[0060] Step S100: Read the original voltage value of the battery through the ADC module, and calculate the actual voltage value according to the original voltage value and a preset conversion formula.
[0061] Specifically, the preset conversion formula is determined based on the operating characteristics and parameters of the ADC module, and these parameters determine the accuracy and range of the conversion of analog signals to digital signals. Since different ADC modules may have different operating characteristics and parameters, by converting the read raw voltage value through the preset conversion formula, the characteristics of various ADC modules can be adapted, so as to convert the sampled raw voltage value into a more accurate actual voltage value to ensure the accuracy of the detection result.
[0062] Step S200: Determine whether the battery is in a charging state according to the actual voltage value, obtain a corrected voltage value according to the judgment result, and obtain a compensation value according to the corrected voltage value and the power supply state of the SOC main control chip.
[0063] Specifically, when the battery is in a charging state, the internal chemical reaction will cause the voltage to increase, which may make the detection result on the high side, thus affecting the judgment of the actual state of the battery. Therefore, by judging whether the battery is charging and taking different countermeasures according to the judgment result, the actual state of the battery power can be reflected more accurately. At the same time, different power supply states of the SOC main control chip (such as the power-on state or the standby state) will also affect the power consumption and voltage requirements of its internal circuit. In different power supply states, the voltage of the SOC main control chip may change, which will directly affect the sampling size of the ADC module, and further affect the accuracy of the battery voltage. By judging the power supply state of the SOC main control chip, corresponding compensation measures can be flexibly applied to offset the battery voltage detection error caused by the difference in power supply states.
[0064] Step S300: Add the actual voltage value and the compensation value to calculate a compensated voltage value.
[0065] Specifically, by adding the actual voltage value and the compensation value, a compensated voltage value closer to the true state of the battery can be obtained. This process ensures that the detection result of the battery voltage is more reliable in different detection environments.
[0066] Step S400: Update the sliding window using the compensated voltage value, and calculate the average voltage value of the valid voltage values in the updated sliding window, so as to determine the remaining power of the battery according to the average voltage value.
[0067] Among them, a preset number of voltage values arranged in chronological order are stored in the sliding window.
[0068] Specifically, a sliding window is a data processing technique used to store multiple quantities of data, which can effectively smooth the data and reduce the impact of instantaneous fluctuations on the results. The sliding window in this embodiment is used to store a preset number of voltage values arranged in chronological order and can dynamically respond to voltage changes. As the battery state changes, new voltage values are introduced into the sliding window while old voltage values are removed, thus maintaining sensitivity to the current state of the battery. When updating the sliding window, using a compensated voltage value can ensure that the stored voltage value is closer to the true state of the battery. This is because the compensated voltage value has taken into account possible detection errors and external influences, thereby improving the reliability of the data. By calculating the average voltage value of the valid voltage values in the sliding window, a more stable and reliable voltage reference can be obtained to more accurately reflect the actual state of the battery, and then used to estimate the true remaining battery charge.
[0069] Compared with the prior art, the battery power detection method based on a sliding window in the embodiment of the present invention makes full use of the ADC module inside the embedded device to sample the battery voltage, without the need for an additional external fuel gauge or other peripheral circuits, thus significantly reducing the production cost of the product. At the same time, by judging the charging state of the battery and obtaining a corrected voltage value, the influence of the battery being in the charging state on the voltage sampling value is effectively eliminated. Combining with the power supply state of the SOC main control chip to calculate the compensation value can effectively compensate for the voltage reading deviation caused by the SOC main control chip being in the working state. In addition, in order to further improve the stability of battery voltage detection, this battery power detection method also adopts a sliding window technology, allowing multiple samplings of the battery voltage and calculating the average voltage value, thereby effectively smoothing the fluctuations of the instantaneous voltage sampling value and reducing the errors caused by load changes and temperature fluctuations. By combining the voltage correction, compensation mechanism and sliding window technology, the stability and accuracy of the remaining battery charge detection can be ensured, which is very suitable for application in low-power video surveillance devices.
[0070] Please refer to Figure 2 as shown, which is a schematic flowchart of the second embodiment of the battery power detection method based on a sliding window of the present invention.
[0071] Based on the first embodiment of the battery power detection method based on a sliding window, this embodiment details the steps of obtaining the actual voltage value, corrected voltage value, and compensation value respectively.
[0072] In this embodiment, steps S100 and S200 include:
[0073] Step S101: Turn on the ADC module, read the original voltage value of the battery through the ADC module, and turn off the ADC module.
[0074] Specifically, step S101 is as follows: Enable the ADC module and perform corresponding configurations, including setting the ADC channel and the division factor; Start the software-triggered ADC conversion, and obtain the original voltage value of the battery read by the ADC module through the query mode to complete data sampling. In order to save power, turn off the ADC module after data sampling is completed.
[0075] It should be noted that, in order to save power consumption, the ADC module is in the off state by default. Therefore, when performing ADC sampling, it needs to be explicitly enabled. After use, the ADC module will also be turned off in time to reduce energy consumption. In addition, the setting of the division factor needs to find a balance between the sampling speed and accuracy. An overly large division factor may reduce the anti-noise ability of the system.
[0076] Step S102: Substitute the original voltage value into a preset conversion formula to calculate the actual voltage value, and update the current actual voltage value to the calculated actual voltage value.
[0077] Among them, the preset conversion formula is: actual voltage value = (original voltage value × standard operating voltage value of the ADC module) / resolution of the ADC module.
[0078] Specifically, in this embodiment, the standard operating voltage value of the ADC module is 3300 mV, and the resolution of the ADC module is 4096. When the calculated actual voltage value exceeds 2500 mV, it is considered that the battery is connected to the charger and the battery is in the charging state. At this time, the charging state can be recorded for use in correcting and compensating the actual voltage value when reading the battery power subsequently.
[0079] Step S201: If the actual voltage value is greater than or equal to the preset charger connection threshold, determine that the battery is in the charging state; if the actual voltage value is less than the preset charger connection threshold, determine that the battery is in the non-charging state.
[0080] Specifically, in this embodiment, the preset charger connection threshold is 2500 mV. If the actual voltage value is greater than or equal to 2500 mV, determine that the battery is in the charging state and return the charging state as 1 (1 indicates charging, 0 indicates non-charging); if the actual voltage value is less than 2500 mV, determine that the battery is in the non-charging state and return the charging state as 0.
[0081] Step S202a: When the battery is in the charging state, disconnect the connection with the charger, wait for a preset first duration, then obtain the actual voltage value again, re-establish the connection with the charger, and add the re-obtained actual voltage value and the preset correction voltage drop value to calculate the corrected voltage value.
[0082] Specifically, when the battery is in the charging state, the charging power supply is turned off and waiting for the voltage to stabilize, usually waiting for about 10 seconds (i.e., the preset first duration is 10 seconds). Then, the actual voltage value is obtained through the ADC module and corrected. Finally, the charging power supply is turned on again, and the corrected voltage value is returned.
[0083] Step S202b: When the battery is in the non - charging state, the actual voltage value is obtained, and the actual voltage value is recorded as the corrected voltage value.
[0084] Specifically, when the battery is in the non - charging state, there is no interference from the charging current, and the voltage of the battery is relatively stable. Therefore, the relatively accurate actual voltage value obtained through the ADC module can be directly used as the corrected voltage value.
[0085] It should be noted that the core objective of this correction process is to eliminate the interference of the charging circuit on the actual voltage value of the battery to ensure that the accurate actual voltage value can still be obtained in the charging state. This process includes two correction steps.
[0086] First, regarding the charging interference problem, when the battery is in the charging state, the current and voltage fluctuations in the circuit may cause the voltage value of the battery to be falsely high. If the voltage value is directly sampled, the battery charge may be misjudged. To solve this problem, the measure of temporarily turning off the charging power supply is taken, and sampling is carried out after the voltage stabilizes to obtain the true voltage value of the battery.
[0087] Second, regarding the voltage drop problem during disconnection, a slight voltage drop (such as 10 mV) may occur when the charging power supply is turned off. If the voltage value is directly sampled, the battery charge may be misjudged. To solve this problem, a fixed - value correction mechanism is adopted, that is, a preset correction voltage drop value of 10 mV is used for correction. This preset correction voltage drop value needs to be calibrated according to the battery type and hardware to ensure its accuracy, but an error of ±5 mV may be introduced during the calibration process.
[0088] It should be noted that there is no sequence requirement between step S202a and step S202b, and either one can be implemented.
[0089] Step S203a: When it is confirmed that the SOC main control chip is in the powered - on working state, the static compensation value and the dynamic compensation value are obtained, and the static compensation value and the dynamic compensation value are added together to calculate the compensation value.
[0090] Among them, the static compensation value = the average voltage value of all valid voltage values in the current sliding window - the corrected voltage value - the dynamic compensation value, and the dynamic compensation value is obtained when the SOC main control chip performs self - inspection.
[0091] Specifically, when the SOC main control chip is in the powered state (i.e., in the powered-on working state), the MCU micro control chip calculates the static compensation value and the dynamic compensation value of the battery voltage. The static compensation value is mainly used to eliminate the inherent deviation of the hardware, such as the error of the voltage dividing resistor. Since the voltage of the SOC main control chip is relatively stable when it is powered on for the first time, the static compensation value is generated only when the battery power is detected for the first time and remains unchanged in subsequent use until the SOC main control chip is powered on again. This design can reduce the computational complexity and improve the response speed of the system. The dynamic compensation value is provided to the MCU micro control chip by the SOC main control chip after self-checking the voltage, and is mainly used to eliminate the battery voltage ADC detection error that may occur during the operation of the SOC main control chip. This dynamic compensation is real-time and can adapt to the changes in the battery state. By combining the static compensation and the dynamic compensation, the compensation mechanism can effectively improve the accuracy of the battery voltage detection.
[0092] Step S203b: When it is confirmed that the SOC main control chip is in the non-working state, the compensation value is set to 0.
[0093] Specifically, when the SOC main control chip is in the unpowered state (i.e., in the non-working state), the power supply circuit of the SOC main control chip does not affect the battery voltage detection, and the MCU micro control chip clears the previous compensation value to avoid the influence of errors. This process ensures that when the SOC main control chip is in the unpowered state, the MCU micro control chip does not use the outdated compensation value.
[0094] It should be noted that there is no sequence requirement between step S203a and step S203b, and either one can be implemented.
[0095] Generally speaking, different processing methods are adopted for the powered and unpowered states of the SOC main control chip, ensuring reliable battery voltage information can be obtained under various working conditions, thereby providing an accurate basis for the battery management system to estimate the battery power.
[0096] The battery power detection method based on the sliding window in this embodiment relies on the ADC module inside the embedded device to sample the battery voltage without the need for peripheral circuits such as an external battery charger. This means that no additional hardware components are required in the product design, thus significantly reducing the production cost of the product and saving valuable hardware space. This integrated design makes the device more compact and suitable for the application scenario of low-power video surveillance devices. By judging the charging state of the battery and obtaining the corrected voltage value, the accuracy of the voltage detection is further improved. By calculating the compensation value according to the powered state of the SOC main control chip and adding it to the actual voltage value, the voltage detection error caused by load changes or other factors can be effectively compensated. This dynamic correction mechanism ensures the effectiveness of the battery power management, thereby improving the performance and reliability of the entire battery power management system.
[0097] Please refer to Figure 3 as shown, which is a schematic flowchart of the third embodiment of the battery power detection method based on a sliding window according to the present invention.
[0098] In this embodiment, compared with other embodiments of the battery power detection method based on a sliding window, the steps of obtaining the average voltage value and the remaining power of the battery are described in detail respectively.
[0099] In this embodiment, step S400 includes:
[0100] Step S401: Insert the compensation voltage value into the head of the sliding window, discard the voltage value at the tail of the sliding window, and move the other voltage values in the sliding window backward in sequence to complete the update of the sliding window.
[0101] Specifically, the sliding window adopts a dynamic window filling mechanism. During initialization, the valid data gradually increases, thus avoiding mutation errors caused by insufficient data in the initial stage. In addition, this mechanism has good fault tolerance and can ignore invalid data (such as the initial value with a voltage value of 0), thereby improving the robustness of the system. By setting the size of the sliding window to 20 samples (i.e., the preset number is 20), the sliding window can effectively suppress high-frequency noise (such as load mutation), while retaining the low-frequency trend (such as the slow decline of the power). Experimental data shows that when the size of the sliding window is 20, the standard deviation of the voltage fluctuation is reduced by about 40%. At the same time, the calculation overhead of the sliding window is low, and the time complexity is O(n), which is very suitable for use with low-computing-power MCU micro-control chips (such as 8-bit MCUs). In addition, the array size of the sliding window is fixed (the default is 20 uint16_t, occupying 40 bytes), ensuring controllable resource consumption. It can be seen that the design of the sliding window shows significant advantages in aspects such as dynamic filling, anti-noise, and low calculation overhead.
[0102] Step S402: Count the number of valid voltage values in the updated sliding window, and calculate the average voltage value of all valid voltage values in the updated sliding window.
[0103] Wherein, the average voltage value = the sum of all valid voltage values in the updated sliding window / the number.
[0104] Specifically, the sliding window statistical method is used to smooth the continuously sampled voltage values, thereby effectively suppressing the influence of instantaneous noise on the battery power detection and realizing the core function of battery voltage filtering. This statistical method mainly includes two aspects: on the one hand, by averaging the historical data, the fluctuations are reduced, and the noise that may occur in a single sampling (such as load mutation and temperature drift) is reduced; on the other hand, the sliding window data is updated in real time to dynamically correct the voltage value to adapt to the long-term voltage change trend. This design ensures the accuracy and stability of the battery power detection.
[0105] It should be noted that by using the sliding window technology, the battery voltage can be sampled multiple times and the average value can be calculated, effectively smoothing the fluctuations of the instantaneous sampling values and reducing the errors caused by factors such as load changes and temperature fluctuations. The voltage values stored in the sliding window are arranged in chronological order, which can better reflect the change trend of the battery voltage, thereby improving the stability and accuracy of the voltage detection. At the same time, the real-time update mechanism of the sliding window enables the battery power detection to quickly respond to the battery voltage change, ensuring that the detection of the remaining battery power is more timely and accurate. This real-time feedback ability is crucial for the long-term stable operation of low-power video surveillance devices.
[0106] Step S403: Compare the average voltage value with the preset voltage-capacity table.
[0107] Among them, the preset voltage-capacity table includes voltage values, power percentage, and the one-to-one correspondence between voltage values and power percentage. The power percentage includes 100%, 20%, and 0%. The voltage value corresponding to the power percentage of 100% is recorded as the highest threshold, the voltage value corresponding to the power percentage of 20% is recorded as the middle threshold, and the voltage value corresponding to the power percentage of 0% is recorded as the lowest threshold. The remaining battery power of the battery is expressed in the form of power percentage.
[0108] Specifically, the preset voltage-capacity table of the battery is formulated according to the battery discharge curve. The following is an example of this table:
[0109] Table 1 Preset Voltage-Capacity Table
[0110]
[0111] It can be seen from Table 1 that in the range of power percentage from 100% to 20%, the step of power percentage is equal, both being 20%. In the range of power percentage from 20% to 10%, the step of power percentage is 10%. In the range of power percentage from 10% to 0%, the step of power percentage is equal, both being 2%.
[0112] Step S404a: If the average voltage value is greater than the highest threshold, then the power percentage is 100%.
[0113] Specifically, if the average voltage value is higher than the highest threshold value (4130 mV) in the preset voltage capacity table, the percentage of the remaining battery power corresponding to the current battery is 100%.
[0114] Step S404b: If the average voltage value is less than or equal to the highest threshold value and greater than the intermediate threshold value, substitute the average voltage value into the preset linear interpolation formula to calculate the percentage of the power corresponding to the average voltage value.
[0115] Among them, the preset linear interpolation formula is: percentage of power = high-level percentage of power - [(high-level voltage value - average voltage value) / step size of interval voltage value] × step size of interval percentage of power.
[0116] Specifically, if the average voltage value is in the range of 4130 mV to 3784 mV (excluding 3784 mV), it is necessary to use the preset linear interpolation formula to calculate the percentage of the power. The following is an example to illustrate the specific calculation process:
[0117] Assume that the average voltage value is 3900 mV. Then it can be determined that this average voltage value is between the percentage of power of 80% (4020 mV) and 60% (3962 mV). Then,
[0118] High-level percentage of power = 80%; high-level voltage value = 4020 mV;
[0119] Low-level percentage of power = 60%; low-level voltage value = 3962 mV;
[0120] Step size of interval voltage value = high-level voltage value - low-level voltage value = 4020 mV - 3962 mV = 58 mV;
[0121] Step size of interval percentage of power = high-level percentage of power - low-level percentage of power = 80% - 60% = 20%;
[0122] Substitute the above values into the preset linear interpolation formula:
[0123] Percentage of power = 80% - [(4020 mV - 3900 mV) / 58 mV] × 20% ≈ 38.6%.
[0124] Then, substitute the average voltage value of 3900 mV into the preset linear interpolation formula to calculate the percentage of the power as 38.6%.
[0125] Step S404c: If the average voltage value is less than or equal to the intermediate threshold value and greater than or equal to the lowest threshold value, query the percentage of the power corresponding to the average voltage value in the preset voltage capacity table.
[0126] Specifically, if the average voltage value is in the range of 3784 mV to 3050 mV, directly return the corresponding percentage of battery capacity in the preset voltage-capacity table to effectively avoid interpolation errors. Because in this voltage range, the relationship between the percentage of battery capacity and the voltage value is relatively stable and linear. By directly looking up the table, the percentage of battery capacity corresponding to the average voltage value can be obtained to ensure the accuracy of the detection result and avoid errors introduced by interpolation calculations.
[0127] Step S404d: If the average voltage value is less than the lowest threshold, the percentage of battery capacity is 0%.
[0128] Specifically, if the average voltage value is lower than the lowest threshold (3050 mV) in the preset voltage-capacity table, the percentage of battery capacity corresponding to the current remaining battery power is 0%.
[0129] It should be noted that there is no order among Step S404a, Step S404b, Step S404c, and Step S404d, and any one of them can be implemented.
[0130] The battery power detection method based on a sliding window in this embodiment can accurately map the battery voltage value to the percentage of battery capacity. This mapping method mainly relies on the preset voltage-capacity table formulated based on the battery discharge curve for accurate mapping, enabling users to intuitively understand the remaining battery power. At the same time, this method supports the battery discharge curves of different battery models to ensure applicability in various application scenarios. In addition, this method also has a boundary protection function, which can effectively handle voltage over-limit scenarios (such as overvoltage and undervoltage) to ensure that the output value is always within a reasonable range. This method of mapping the percentage of battery capacity not only improves the accuracy of battery power estimation but also enhances the safety and reliability of the system, providing a better user experience for users.
[0131] Please refer to Figure 4 as shown, which is a schematic flowchart of the fourth embodiment of the battery power detection method based on a sliding window of the present invention.
[0132] This embodiment adds the step of initializing the sliding window compared with other embodiments of the battery power detection method based on a sliding window.
[0133] In this embodiment, before Step S100, it further includes:
[0134] Step S501: Start the MCU microcontroller chip, and perform voltage value sampling a preset number of times after entering the sleep state for a preset second duration to obtain the remaining battery power.
[0135] Specifically, the specific process of sliding window initialization is as follows: First, start the MCU microcontroller chip and initialize the MCU ports, including functions such as the ADC module and charge control. Then, configure the software timer (SWT) to implement the sleep and wake-up function. Subsequently, enter the sleep state for 50 milliseconds (i.e., the preset second duration is 50 milliseconds) to wait for the system of the MCU microcontroller chip to stabilize. Finally, update the battery capacity information and perform voltage value sampling 3 times initially (i.e., the preset number of times is 3 times) to avoid the influence of instantaneous errors. Through these operations, the accuracy and stability of sliding window initialization can be ensured.
[0136] Step S502: Update the current remaining power of the battery using the obtained remaining power, and determine whether the remaining power is greater than the preset safe power.
[0137] Specifically, sliding window initialization is performed when the system of the MCU microcontroller chip starts, aiming to ensure that the battery has sufficient power to support the normal operation of the embedded device. When the remaining power is less than 10% (i.e., the preset safe power is 10%), the system will enter the sleep and wait state to avoid abnormal startup or data errors caused by insufficient power.
[0138] Step S503a: If so, update the sliding window using the voltage value corresponding to the obtained remaining power to complete the initialization of the sliding window.
[0139] Specifically, if the remaining power is greater than 10%, it means that the battery power is normal, and the system will fill the historical data of the sliding window, thus completing the sliding window initialization.
[0140] Step S503b: If not, the MCU microcontroller chip will sleep for a preset third duration every preset period until the remaining power of the battery is greater than the preset safe power.
[0141] Specifically, if the remaining power is less than or equal to 10%, it means that the battery power is insufficient. The system will sleep for 3 minutes every preset period (i.e., the preset third duration is 3 minutes), and update the battery capacity information again after the battery power is restored (only single sampling is required at this time).
[0142] It should be noted that there is no order of precedence between Step S503a and Step S503b, and either one can be implemented.
[0143] The core logic of initializing the sliding window for the battery power detection method in this embodiment includes: First, perform hardware initialization, configuring key modules such as the ADC module and the charging control pin. Second, verify the battery voltage through multiple samplings to exclude the influence of instantaneous fluctuations. If the power is insufficient, the system will periodically go into sleep and retry until the battery power is restored or the timeout condition is reached. Finally, fill the historical voltage data to complete the initialization of the sliding window, providing a stable benchmark for subsequent battery power detection. This series of steps ensures that the system of the MCU microcontroller chip can not only achieve fast response and efficient operation when the power is sufficient, but also maintain reliability and stability under low power conditions.
[0144] Please refer to Figure 5 as shown, which is a schematic flowchart of the fifth embodiment of the battery power detection method based on a sliding window according to the present invention.
[0145] Compared with other embodiments of the battery power detection method based on a sliding window, this embodiment adds steps for multi-mode power management.
[0146] In this embodiment, the battery power detection method further includes:
[0147] Step S601: Determine the working mode of the MCU microcontroller chip.
[0148] Specifically, the working modes of the MCU microcontroller chip include the normal working mode, the factory test mode, and the system upgrade mode.
[0149] Step S602a: When the MCU microcontroller chip is in the normal working mode, determine the mode of the SOC main control chip; if the SOC main control chip is in the low-power mode, detect the remaining power of the battery at intervals of a preset fourth time period after the SOC main control chip is powered down; if the SOC main control chip is in the constant-power mode, detect the remaining power of the battery at intervals of a preset fourth time period.
[0150] Specifically, the size of the preset fourth time period can be set by the SOC main control chip. In this embodiment, the preset fourth time period is set to 3 minutes.
[0151] Step S602b: When the MCU microcontroller chip is in the factory test mode, detect the remaining power of the battery at intervals of a preset fifth time period.
[0152] Among them, the preset fifth time period is less than the preset fourth time period.
[0153] Specifically, the preset fifth duration can be set to 3 seconds, so that the battery power is detected every 3 seconds. On the premise of ignoring factors such as power consumption, it is ensured that the latest battery power and charging status can be obtained during the factory measurement and test process.
[0154] Step S602c: When the MCU microcontroller chip is in the system upgrade mode, it is determined whether the remaining power of the battery is greater than a preset power threshold; if so, the system is upgraded, otherwise the system upgrade is not started.
[0155] Specifically, during the system upgrade process, the software needs to be closed and the program needs to be reflashed. To prevent sudden power-off, it is necessary to confirm that the battery power is above 20% (i.e., the preset power threshold is 20%) before the system upgrade operation can be performed. That is to say, after the MCU microcontroller chip is in the system upgrade mode, it is necessary to confirm that the remaining power of the battery is greater than the preset power threshold before starting the system upgrade operation.
[0156] It should be noted that there is no sequence requirement among step S602a, step S602b, and step S602c, and any one of them can be implemented.
[0157] The battery power detection method based on a sliding window in this embodiment adopts a multi-mode power management mechanism, and adapts to the requirements of different scenarios by dynamically adjusting the detection frequency, peripheral control strategy, and power consumption optimization. In terms of dynamic power consumption optimization, the system detects the battery power as needed in the normal working mode, while in the factory test mode, high-frequency sampling is performed, and in the system upgrade mode, the peripherals are completely turned off, thus reducing the overall power consumption by 20% to 30%. In addition, this battery power detection method also has an abnormal recovery mechanism. Through the automatic reset of the SOC main control chip heartbeat timeout, combined with the watchdog and software timer (SWT) interrupts, it is ensured that the system deadlock recovery time does not exceed 10 seconds. In terms of flexible configuration, users can also dynamically set the detection time interval and compensation parameters through UART instructions to adapt to different types of batteries. And this battery power detection method uses a modular design, making the hardware have good compatibility and being convenient to be transplanted to different MCU platforms.
[0158] It should be noted that there are multiple defects in the existing battery management methods. First, there is a voltage fluctuation error. The battery voltage is easily affected by factors such as load changes and temperature fluctuations, resulting in inaccurate instantaneous sampling values. Second, due to the interference of the charging state, the accuracy of the power calculation is significantly affected during the charging process. In addition, the existing systems have poor adaptability and lack dynamic adjustment detection strategies in different working modes (such as low-power and normal-power modes). Moreover, it will require additional costs. Peripheral circuits such as the fuel gauge not only increase the production cost of the product, but also lead to unstable detection results and occupy the hardware circuit space.
[0159] Therefore, the battery power detection method based on the sliding window proposed in this embodiment mainly needs to solve the following problems:
[0160] 1. How to remove the external circuit of the fuel gauge and use the ADC circuit built in the microcontroller to complete the battery power detection, saving production costs;
[0161] 2. How to reduce the interference of voltage fluctuations on power calculation through a dynamic smoothing algorithm;
[0162] 3. How to eliminate the influence of the charging state on voltage sampling;
[0163] 4. How to dynamically adjust the power detection strategy according to different working modes to reduce power consumption.
[0164] To solve the above problems, a battery power detection method based on the sliding window proposed in this embodiment is as follows:
[0165] 1. Use a fixed-length sliding window to store historical voltage data and use the calculated valid data as the actual battery voltage;
[0166] 2. If charging, turn off the charging power supply and then delay to read the voltage value to eliminate the interference of the charging circuit;
[0167] 3. If charging, it is also necessary to correct the voltage drop of the collected values during charging;
[0168] 4. Compensate the voltage value according to the operating state (power on / power off) of the SOC master chip and the compensation parameters;
[0169] 5. Adopt a multi-mode detection strategy and select the most suitable power detection frequency for different modes to balance real-time performance and power consumption optimization.
[0170] By executing the above steps, the battery power detection method can achieve the following technical effects:
[0171] 1. High-precision power calculation: The sliding window average algorithm significantly reduces the error caused by voltage fluctuations and improves the stability of power detection (the measured fluctuation is reduced by about 30%);
[0172] 2. Enhanced anti-interference ability: The dynamic compensation mechanism eliminates the interference of the charging state on voltage sampling, and the error is controlled within ±3% in the charging scenario. The sliding window + dynamic compensation dual mechanism takes into account long-term smoothing and instantaneous correction.
[0173] 3. Dynamic power consumption optimization: The multi-mode detection strategy reduces the sampling frequency in the low-power mode (such as from 3 minutes to 30 minutes), and the overall power consumption is reduced by 15% - 20%. The multi-mode strategy dynamically balances real-time performance and power consumption and adapts to the requirements of IoT terminals.
[0174] 4. Flexible adaptability: It doesn't need to interface with a fuel gauge, saving production costs and the input costs of developers. It only needs to support different battery types and application scenarios by configuring parameters (window size, detection time interval). Moreover, the parameters (window size, detection time interval) can be configured to be compatible with different battery types and application scenarios.
[0175] In summary, the battery power detection method based on a sliding window in this embodiment effectively solves problems such as production costs, hardware space, and sampling accuracy through an integrated design, a dynamic correction and compensation mechanism, and a real-time update strategy, providing an efficient, stable, and cost-controllable battery management solution for the low-power video surveillance industry.
[0176] The following is an embodiment of the electronic device provided by the present invention. The embodiment of the electronic device and the embodiment of the above-mentioned battery power detection method based on a sliding window belong to the same concept. For the details not described in detail in the embodiment of the electronic device, reference can be made to the embodiment of the battery power detection method based on a sliding window.
[0177] Please refer to Figure 6 as shown, which is a schematic structural diagram of an electronic device in the hardware operating environment related to the solution of the embodiment of the present invention.
[0178] In this embodiment, an electronic device, the electronic device is an embedded device, and the embedded device includes:
[0179] A memory 1005 for storing program instructions; and
[0180] A processor 1001 for executing the program instructions to implement the steps of the battery power detection method based on a sliding window as described above.
[0181] The electronic device of the embodiment of the present invention can be a computing device such as a desktop computer, a notebook, a palm computer, and a server. As Figure 6 shown, the electronic device may include: a processor 1001 (such as a CPU), a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to implement connection communication between these components. The user interface 1003 may include a display screen (Display) and an input unit, such as a keyboard (Keyboard). Optionally, the user interface 1003 may further include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0182] Those skilled in the art can understand that Figure 6 the structure of the electronic device shown in does not constitute a limitation on the electronic device, and it may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0183] As Figure 6 shown, in the memory 1005 as a computer storage medium, an operating system, a network communication module, a user interface module, and a computer program may be included.
[0184] In Figure 6 the electronic device shown, the network interface 1004 is mainly used to connect to the background server and communicate with the background server for data; the user interface 1003 is mainly used to connect to the client (user side) and communicate with the client for data; and the processor 1001 can be used to call the computer program stored in the memory 1005, and when the computer program is called and executed by the processor 1001, the steps of the above-mentioned battery power detection method based on the sliding window are implemented.
[0185] The following is an embodiment of the computer-readable storage medium provided by the present invention. The embodiment of the computer-readable storage medium and the embodiments of the above-mentioned battery power detection method based on the sliding window and the electronic device belong to the same concept. For the details not described in detail in the embodiment of the computer-readable storage medium, reference can be made to the embodiments of the above-mentioned battery power detection method based on the sliding window and the electronic device.
[0186] In this embodiment, a computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the above-mentioned battery power detection method based on the sliding window are implemented.
[0187] For the electronic device and the computer-readable storage medium of the present invention, since they can both implement the steps of the above-mentioned battery power detection method based on the sliding window, they at least have all the beneficial effects brought by the technical solutions of the embodiments of the steps of the above-mentioned battery power detection method based on the sliding window, and will not be elaborated herein one by one.
[0188] The above are only partial or preferred embodiments of the present invention. Whether in terms of text or drawings, the scope of protection of the present invention cannot be limited thereby. Any equivalent structural transformation made by using the content of the specification and drawings of the present invention under the concept of a whole of the present invention, or any direct / indirect application in other related technical fields is included in the scope of protection of the present invention.
[0189] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0190] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of flows and / or blocks in the flowchart and / or block diagram can also be implemented. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0191] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including instruction means, and the instruction means implement the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0192] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0193] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that: the specific implementation manners of the present invention can still be modified or equivalently replaced, and any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered by the protection scope of the claims of the present invention.
Claims
1. A battery power detection method based on a sliding window, applied to an embedded device, the embedded device comprising an ADC module, an SOC main control chip, an MCU micro control chip, and a battery, characterized in that, The battery power detection method includes: Reading the original voltage value of the battery through the ADC module, and calculating the actual voltage value according to the original voltage value and a preset conversion formula; Judging whether the battery is in a charging state according to the actual voltage value, obtaining a corrected voltage value according to the judgment result, and obtaining a compensation value according to the corrected voltage value and the power supply state of the SOC main control chip; Adding the actual voltage value and the compensation value to calculate a compensated voltage value; Updating the sliding window with the compensated voltage value, and calculating the average voltage value of the valid voltage values in the updated sliding window, so as to determine the remaining power of the battery according to the average voltage value; wherein, a preset number of voltage values arranged in chronological order are stored in the sliding window.
2. The battery power detection method based on a sliding window according to claim 1, wherein, The step of reading the original voltage value of the battery through the ADC module and calculating the actual voltage value according to the original voltage value and a preset conversion formula includes: Turning on the ADC module, reading the original voltage value of the battery through the ADC module, and turning off the ADC module; Substituting the original voltage value into a preset conversion formula to calculate the actual voltage value, and updating the current actual voltage value to the calculated actual voltage value; wherein, the preset conversion formula is: actual voltage value = (original voltage value × standard operating voltage value of the ADC module) / resolution of the ADC module.
3. The battery power detection method based on a sliding window according to claim 1, characterized in that The step of judging whether the battery is in a charging state according to the actual voltage value and obtaining a corrected voltage value according to the judgment result includes: If the actual voltage value is greater than or equal to a preset charger connection threshold, it is determined that the battery is in a charging state; if the actual voltage value is less than the preset charger connection threshold, it is determined that the battery is in a non-charging state; When the battery is in a charging state, disconnect the connection with the charger, wait for a preset first duration, then re-obtain the actual voltage value, re-establish the connection with the charger, and add the re-obtained actual voltage value and a preset corrected voltage drop value to calculate the corrected voltage value; When the battery is in a non-charging state, obtain the actual voltage value and record the actual voltage value as the corrected voltage value.
4. The battery power detection method based on a sliding window according to claim 1, wherein, The step of obtaining a compensation value according to the corrected voltage value and the power supply state of the SOC main control chip includes: When it is confirmed that the SOC main control chip is in the powered-on working state, obtain a static compensation value and a dynamic compensation value, and add the static compensation value and the dynamic compensation value to calculate the compensation value; wherein, the static compensation value = average voltage value of all valid voltage values in the current sliding window - the corrected voltage value - the dynamic compensation value, and the dynamic compensation value is obtained when the SOC main control chip performs self-check; When it is confirmed that the SOC main control chip is in a non-working state, set the compensation value to 0.
5. The battery power detection method based on a sliding window according to claim 1, wherein The step of updating the sliding window with the compensated voltage value and calculating the average voltage value of the valid voltage values in the updated sliding window includes: Insert the compensation voltage value into the head of the sliding window, discard the voltage value at the tail of the sliding window, and shift the other voltage values in the sliding window backward in sequence to complete the update of the sliding window; Count the number of valid voltage values in the updated sliding window, and calculate the average voltage value of all valid voltage values in the updated sliding window; wherein, the average voltage value = the sum of all valid voltage values in the updated sliding window / the number.
6. The battery power detection method based on a sliding window according to claim 1, wherein The determining the remaining power of the battery according to the average voltage value includes: Compare the average voltage value with a preset voltage-capacity table; wherein, the preset voltage-capacity table includes voltage values, power percentages, and the one-to-one correspondence between voltage values and power percentages. The power percentages include 100%, 20%, and 0%. The voltage value corresponding to the power percentage of 100% is denoted as the highest threshold, the voltage value corresponding to the power percentage of 20% is denoted as the middle threshold, and the voltage value corresponding to the power percentage of 0% is denoted as the lowest threshold. The remaining power of the battery is expressed in the form of a power percentage; If the average voltage value is greater than the highest threshold, then the power percentage is 100%; If the average voltage value is less than or equal to the highest threshold and greater than the middle threshold, substitute the average voltage value into a preset linear interpolation formula to calculate the power percentage corresponding to the average voltage value; wherein, the preset linear interpolation formula is: power percentage = high power percentage - [(high voltage value - average voltage value) / interval voltage value step size] × interval power percentage step size; If the average voltage value is less than or equal to the middle threshold and greater than or equal to the lowest threshold, query the power percentage corresponding to the average voltage value in the preset voltage-capacity table; If the average voltage value is less than the lowest threshold, then the power percentage is 0%.
7. The battery power detection method based on a sliding window according to claim 1, characterized in that Before reading the original voltage value of the battery through the ADC module, it further includes: Start the MCU micro-control chip, perform voltage value sampling a preset number of times after entering the sleep state for a preset second duration to obtain the remaining power of the battery; Update the current remaining power of the battery with the obtained remaining power, and judge whether the remaining power is greater than a preset safe power; If so, update the sliding window with the voltage value corresponding to the obtained remaining power to complete the initialization of the sliding window; If not, the MCU micro-control chip sleeps for a preset third duration every preset period until the remaining power of the battery is greater than the preset safe power.
8. The battery power detection method based on a sliding window according to claim 1, wherein The battery power detection method further includes: Determine the working mode of the MCU micro-control chip; When the MCU micro-control chip is in the normal working mode, judge the mode of the SOC main control chip; if the SOC main control chip is in the low-power mode, detect the remaining power of the battery every preset fourth duration after the SOC main control chip is powered off; if the SOC main control chip is in the constant power mode, detect the remaining power of the battery every preset fourth duration; When the MCU microcontroller chip is in the factory test mode, the remaining power of the battery is detected every preset fifth time period; wherein, the preset fifth time period is less than the preset fourth time period; When the MCU microcontroller chip is in the system upgrade mode, it is determined whether the remaining power of the battery is greater than a preset power threshold; if so, the system is upgraded, and if not, the system upgrade is not started.
9. An electronic device, characterized in that, The electronic device is an embedded device, and the embedded device includes: a memory for storing program instructions; and a processor for executing the program instructions to implement the steps of the sliding window-based battery power detection method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the sliding window-based battery power detection method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Method utilizing battery voltage to display electric quantity
CN102520364A
Method for measuring and calculating system battery electricity quantity
CN103792490A