Method for realizing current gradual change in high-power charger
By employing a dual-task asynchronous parallel architecture and closed-loop feedback control, the PWM duty cycle is dynamically adjusted, solving the current regulation balance problem in high-power charging systems. This achieves precise current control and smooth transition, extending battery life and improving charging efficiency and safety.
Patent Information
- Application Number
- CN202511130157.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-13
- Publication Date
- 2025-11-11
AI Technical Summary
In high-power charging systems, how can we ensure the accuracy of current adjustment while avoiding the waste of system resources caused by frequent minor adjustments, achieve a balance between fast response and smooth transition, and achieve precise control of analog current with limited digital resolution?
The embedded software architecture adopts a dual-task asynchronous parallel approach. The foreground task reads the target current value from the charging parameter mapping table and writes it into the global variable dac_current. The background task is woken up by a programmable timer and samples the actual current value in real time through the ADC interface. Combined with closed-loop feedback control, the PWM duty cycle is dynamically adjusted to achieve gradual current change and staged constant current and constant voltage charging.
It achieves precise current control and smooth transition, extending battery life and improving charging efficiency and safety.
Smart Images

Figure CN120934140A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of high-power chargers, and more particularly to a method for achieving gradual current change in a high-power charger. Background Technology
[0002] In a complex battery charging system, precisely controlling the charging current is a technical challenge. The system needs to dynamically adjust the target current value according to different charging stages, a process involving the coordinated work of foreground tasks, background tasks, timers, and digital-to-analog converters.
[0003] The foreground task is responsible for setting the target current value based on the charging stage (such as battery activation, pre-charge, constant current, and constant voltage) and storing it in the `dac_current` variable. The background task, triggered periodically by a timer, compares the actual output current value (represented by `dac_data`) with the target value. This comparison mechanism raises a delicate balance issue: how to ensure the accuracy of current adjustment while avoiding the waste of system resources caused by frequent minor adjustments.
[0004] A more significant challenge is that the rate of current adjustment needs to be controllable. By changing the trigger period of the timer, the slope of the current change can be affected. Therefore, striking a balance between rapid response and smooth transition is a core technical challenge. Adjusting too quickly may lead to instability in the battery or charging system, while adjusting too slowly may affect charging efficiency.
[0005] Furthermore, as a critical hardware interface, the accuracy and linearity of the digital-to-analog converter directly affect the performance of the entire control system. Achieving precise control of analog current with limited digital resolution has become another technical challenge requiring in-depth consideration.
[0006] These interrelated factors constitute a complex control problem, requiring the finding of the optimal balance between software algorithm design and hardware capabilities. Summary of the Invention
[0007] This invention provides a method for achieving current gradient in a high-power charger, mainly including: Based on the battery's charge and discharge characteristic curve, target charging current values and upper and lower voltage thresholds are preset for different charging stages and stored in the charging parameter mapping table. An embedded software architecture with dual-task asynchronous parallelism is adopted, in which the foreground task is responsible for reading the target charging current value of the current charging stage from the charging parameter mapping table and writing it into the global variable dac_current; The background task is woken up periodically by a programmable timer. The wake-up period is dynamically adjusted according to the current charging stage. After waking up, the target current value of the current charging stage is obtained by reading the dac_current variable. The background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data as the basis for feedback control. Compare the values of dac_current and adc_data. If they are equal, the actual current has reached the target value and no adjustment is needed. Exit the background task and wait for the next timer wake-up. If adc_data is less than dac_current, the PWM duty cycle is increased by a preset adjustment step, which represents an increase of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited. If adc_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited. During the charging process, when the battery voltage reaches the upper limit threshold of the current charging stage, the foreground task reads the target charging current value for the next charging stage from the charging parameter mapping table and updates the dac_current variable. If the updated dac_current is not equal to adc_data, the background task will adjust the PWM duty cycle multiple times to eventually make adc_data converge to dac_current, smoothly transitioning to the next charging stage and avoiding sudden changes in charging current. Throughout the charging process, dac_current carries the target current for the current charging stage, while adc_data reflects the actual current at all times. The two work together through closed-loop feedback control to ultimately achieve staged constant current and constant voltage charging, thus extending battery life.
[0008] Optionally, the step of presetting target charging current values and upper and lower voltage thresholds for different charging stages based on the battery's charge-discharge characteristic curve and storing them in a charging parameter mapping table includes: Step A1: Based on the battery's charge and discharge characteristic curve, preset the target charging current value and voltage upper and lower limit thresholds for different charging stages and store them in the charging parameter mapping table. Step A2: The foreground task retrieves the corresponding target charging current value from the charging parameter mapping table according to the charging stage and sets it to the variable dac_current. Step A3: The background task is called periodically through a background task timer. The background task compares the values of variables dac_data and dac_current. Step A4: If dac_data equals dac_current, then maintain the current charging current and exit the background task. Step A5: If dac_data is less than dac_current, then dac_data is incremented by 1, the function for setting the current is called, the value of dac_data is converted into the corresponding current value, and output to the charging circuit to control the charging current. Then the background task is exited. Step A6: If dac_data is greater than dac_current, then dac_data is decremented by 1, the function for setting the current is called to convert the value of dac_data into the corresponding current value, output it to the charging circuit to control the charging current, and then the background task is exited. The slope of the charging current change can be adjusted by changing the period of the background task timer. The shorter the timer period, the greater the slope of the charging current change, and the faster the current changes. The longer the timer period, the smaller the slope of the charging current change and the slower the current change. Step A7: During the charging process, the foreground task collects the battery voltage value in real time and determines whether it exceeds the upper and lower voltage thresholds of the current charging stage. Step A8: If the threshold is exceeded, switch to the next charging stage or the previous charging stage depending on whether the upper or lower limit is exceeded, and obtain the target charging current value corresponding to the new charging stage from the charging parameter mapping table and set it to the variable dac_current. Step A9: Repeat steps A2 to A8 until charging is complete; The conditions for ending charging are: the charging current drops below a certain value and the battery voltage reaches the full charge voltage value. After a certain period of time, the charging is considered to be finished and charging is stopped.
[0009] Optionally, the embedded software architecture employing dual-task asynchronous parallelism is described, wherein the foreground task is responsible for reading the target charging current value for the current charging stage from the charging parameter mapping table and writing it into the global variable dac_current, including: Based on the charging stage, the target charging current value for the current stage is obtained from the charging parameter mapping table and written into the global variable `dac_current`. A background task periodically calls this function via a timer to retrieve the value of `dac_current`. The background task then retrieves the current actual charging current value `dac_data` and checks if `dac_data` equals `dac_current`. If they are equal, the background task exits. If `dac_data` is less than `dac_current`, `dac_data` is incremented by 1, and the charging current is set according to its value. If `dac_data` is greater than `dac_current`, `dac_data` is decremented by 1, and the charging current is set according to its value. After completing this round of processing, the background task waits for the timer to trigger again. The timer's period determines the slope of the charging current change; dynamic control of the charging current slope is achieved by adjusting the timer period.
[0010] Optionally, the background task is woken up periodically by a programmable timer, and the wake-up period is dynamically adjusted according to the current charging stage; after waking up, the target current value of the current charging stage is obtained by reading the dac_current variable, including: Step B1: Based on the charging stage of the charger, obtain the timer wake-up period corresponding to that stage, and set the wake-up period of the programmable timer to that value. Step B2: After the timer wakes up, read the value of the dac_current variable to obtain the target current value for the current charging stage; Step B3: Obtain the value of the dac_data variable to determine the current actual charging current value; Step B4: Determine if dac_data is equal to dac_current. If they are equal, there is no need to adjust the charging current, and the background task can be exited directly. Step B5: If dac_data is less than dac_current, increment the value of dac_data by 1, set the charging current according to the new dac_data value, and then exit the background task. Step B6: If dac_data is greater than dac_current, decrement the value of dac_data by 1, set the charging current according to the new dac_data value, and then exit the background task. Step B7: After setting the charging current, the value of dac_data is converted into an analog current signal by a DA converter and output to the charging circuit to control the actual charging current. Step B8: Dynamically adjust the wake-up period of the programmable timer according to the status of the charger and the charging status of the battery to adapt to the requirements of the current slope at different charging stages. Step B9: After the background task completes one current adjustment, wait for the next timer wake-up and repeat steps B2 to B8 until the charging process is finished.
[0011] Optionally, the background task samples the actual charging current of the battery in real time through the ADC interface, assigns the sampled value to the global variable adc_data, and uses it as the basis for feedback control, including: Step C1: Based on the charging stage, the foreground task sets the target charging current value dac_current, while the background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data. Step C2: Determine if adc_data is equal to dac_current. Step C3: If the current values are equal, maintain the current charging current and proceed to step C7. Step C4: If adc_data is less than dac_current, increment dac_data by 1 to obtain a new dac_data value. Use this new dac_data value to set the charging current, causing the actual current to gradually transition towards the target current. In step C5, if adc_data is greater than dac_current, then dac_data is decremented by 1 to obtain a new dac_data value. This new dac_data value is then used to set the charging current, causing the actual current to gradually transition towards the target current. Step C6: Based on the timer period, jump to step C2 to continue current sampling and adjustment. Step C7: Determine that the current charging current has reached the target value, maintain a constant charging current, and wait to enter the next charging stage.
[0012] Optionally, comparing the magnitudes of dac_current and adc_data, and determining if they are equal, indicates that the actual current has reached the target value, requiring no adjustment. The background task can then be exited and the process awaits the next timer wake-up. This includes: Step D1: Based on the target current value dac_current set in the foreground task, obtain the current actual current value dac_data. Step D2: Compare the sizes of dac_current and dac_data. Step D3: Determine if the two are equal. In step D4, if dac_current equals dac_data, the actual current has reached the target value and no adjustment is needed. Exit the background task and wait for the next timer wake-up. In step D5, if dac_current is greater than dac_data, then increment dac_data by 1 to obtain a new dac_data value. Use this new dac_data value to set the charging current, then exit the background task and wait for the next timer wake-up. Step D6: If dac_current is less than dac_data, then dac_data is decremented by 1 to obtain a new dac_data value. The charging current is set using the new dac_data value, and the background task is exited, waiting for the next timer wake-up. By changing the timer's period, the slope of the current change can be adjusted; the shorter the period, the steeper the slope, and the faster the current changes. D7 continuously executes steps D1-D6 until dac_current equals dac_data, thus smoothly transitioning the current from the initial value to the target value.
[0013] Optionally, if adc_data is less than dac_current, the PWM duty cycle is increased by a preset adjustment step, representing an increase of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to increase the charging current, and the background task is exited. This includes: Based on the charging stage, the foreground task sets the target charging current value dac_current and writes it into the shared variable of the background task; The timer periodically triggers a background task, which reads the target current value dac_current and the current actual current value dac_data from the shared variables. Determine if the current current value dac_data is equal to the target current value dac_current. If they are equal, exit the background task; otherwise, proceed to the next step. If dac_data is less than dac_current, the PWM duty cycle is increased by a preset adjustment step, which represents an increase of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited. If dac_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited. The slope of the current regulation can be controlled by adjusting the trigger period of the timer; The shorter the cycle, the faster the current regulation; The longer the cycle, the slower the current regulation; During the current regulation process, an ADC sampling circuit is used to detect the actual output current in real time, and the sampled value is compared with dac_data to form a closed-loop control to ensure the accuracy of the output current. After the current regulation is completed, dac_data equals dac_current, and the background task no longer adjusts the PWM duty cycle to maintain a stable charging current output; When charging enters the next stage, the foreground task updates the dac_current value, and the background task restarts the current regulation process based on the new target value until it reaches stability again.
[0014] Optionally, if adc_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step size, representing a reduction of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to reduce the charging current, and the background task is exited. This includes: Based on the charging stage and battery status, determine the target charging current value dac_current and write it into the corresponding variable of the foreground task; A timer is used to periodically call a background task to obtain the current actual charging current value adc_data; Check if adc_data is equal to dac_current; if they are equal, exit the background task. If adc_data is less than dac_current, then the PWM duty cycle is increased by the preset adjustment step size, which represents an increase of one unit in the actual charging current. Then the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited. If adc_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited. Different current regulation slopes can be obtained by adjusting the timer period; The shorter the cycle, the faster the current regulation; The longer the cycle, the slower the current regulation; Each time a background task is initiated, the latest adc_data and dac_current values are obtained in order to adjust the charging current in a timely manner. Based on parameters such as battery voltage and temperature, determine whether the charging stage needs to be changed. If a change is needed, update the dac_current value and write it to the foreground task variable. The system uses an interruption method to monitor charging faults, such as overcurrent and overvoltage, and quickly cuts off the charging circuit to ensure charging safety.
[0015] Optionally, during the charging process, when the battery voltage reaches the upper voltage threshold of the current charging stage, the foreground task reads the target charging current value for the next charging stage from the charging parameter mapping table and updates the dac_current variable, including: Step E1: Based on the current charging stage, obtain the upper limit threshold of the battery voltage and monitor the battery voltage in real time. Step E2: If the battery voltage reaches the upper voltage threshold of the current charging stage, then read the target for the next charging stage from the charging parameter mapping table. In step E3, the target charging current value for the next charging stage is read and updated in the dac_current variable. In step E4, the background task periodically retrieves the values of the variables dac_data and dac_current using a timer. Step E5: Determine if dac_data is equal to dac_current. Step E6: If they are equal, exit the background task. In step E7, if dac_data is less than dac_current, increment dac_data by 1, set the charging current, and exit the background task. In step E8, if dac_data is greater than dac_current, then dac_data is decremented by 1, the charging current is set, and the background task is exited. The slope of the charging current change is adjusted by changing the timer period; the shorter the period, the steeper the slope, and the faster the current changes. Step E9: Repeat steps E4-E8 until charging is complete or an abnormal situation occurs, at which point charging will stop. Optionally, if the updated dac_current is not equal to adc_data, the background task adjusts the PWM duty cycle multiple times until adc_data converges to dac_current, smoothly transitioning to the next charging stage and avoiding sudden changes in charging current, including: Step F1: Based on the charging stage, the foreground task sets the target current value dac_current. Step F2: The background task obtains the current current value dac_data and the target current value dac_current. Step F3: Determine if dac_data equals dac_current. If the values are equal in step F4, maintain the current PWM duty cycle and proceed to step F9. Step F5: If dac_data is less than dac_current, increase the charging current by increasing the PWM duty cycle to obtain a new dac_data. Step F6: If dac_data is greater than dac_current, then the charging current is reduced by decreasing the PWM duty cycle to obtain a new dac_data. Step F7: Based on the timer period, determine the time interval for the next adjustment of the PWM duty cycle to achieve gradual current change. In step F8, after the slope control timer reaches the set time, the background task is triggered to execute steps F2-F6 again until dac_data converges to dac_current. In step F9, the actual charging current is set using the new dac_data value. The background task enters a sleep state, waiting for the next adjustment cycle to arrive or for the foreground task to update the dac_current value.
[0016] The technical solutions provided by the embodiments of the present invention may include the following beneficial effects: This invention discloses a method for implementing gradual current change in a high-power charger, based on a dual-task asynchronous parallel architecture for intelligent battery charging. The method presets target current and voltage thresholds for different charging stages using a charging parameter mapping table. A foreground task reads the target current and updates the global variable `dac_current`, while a background task is periodically woken up by a timer to sample the actual charging current `adc_data` and compare it with `dac_current`. Based on the comparison result, the PWM duty cycle is dynamically adjusted to achieve precise control of the charging current. When the battery voltage reaches the threshold, the system smoothly transitions to the next charging stage, avoiding sudden current changes. Throughout the process, `dac_current` and `adc_data` cooperate through closed-loop feedback control to achieve staged constant current and constant voltage charging, effectively extending battery life and improving charging efficiency and safety. Attached Figure Description
[0017] Figure 1 This is a flowchart of a method for implementing current gradient in a high-power charger according to the present invention.
[0018] Figure 2 This is a schematic diagram of a method for implementing gradual current change in a high-power charger according to the present invention.
[0019] Figure 3 This is another schematic diagram of a method for implementing current gradient in a high-power charger according to the present invention. Detailed Implementation
[0020] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] like Figures 1-3 This embodiment of a method for implementing gradual current change in a high-power charger may specifically include: S101. Based on the battery's charge and discharge characteristic curve, preset target charging current values and upper and lower voltage thresholds for different charging stages and store them in the charging parameter mapping table.
[0022] Based on the battery's charge-discharge characteristic curve, target charging current values and upper and lower voltage thresholds are preset for different charging stages and stored in a charging parameter mapping table, including: Step A1: Based on the battery's charge and discharge characteristic curve, preset the target charging current value and voltage upper and lower limit thresholds for different charging stages and store them in the charging parameter mapping table. Step A2: The foreground task retrieves the corresponding target charging current value from the charging parameter mapping table according to the charging stage and sets it to the variable dac_current. Step A3: The background task is called periodically through a background task timer. The background task compares the values of variables dac_data and dac_current. Step A4: If dac_data equals dac_current, then maintain the current charging current and exit the background task. Step A5: If dac_data is less than dac_current, then dac_data is incremented by 1, the function for setting the current is called, the value of dac_data is converted into the corresponding current value, and output to the charging circuit to control the charging current. Then the background task is exited. Step A6: If dac_data is greater than dac_current, then dac_data is decremented by 1, the function for setting the current is called to convert the value of dac_data into the corresponding current value, output it to the charging circuit to control the charging current, and then the background task is exited. The slope of the charging current change can be adjusted by changing the period of the background task timer. The shorter the timer period, the greater the slope of the charging current change, and the faster the current changes. The longer the timer period, the smaller the slope of the charging current change and the slower the current change. Step A7: During the charging process, the foreground task collects the battery voltage value in real time and determines whether it exceeds the upper and lower voltage thresholds of the current charging stage. Step A8: If the threshold is exceeded, switch to the next charging stage or the previous charging stage depending on whether the upper or lower limit is exceeded, and obtain the target charging current value corresponding to the new charging stage from the charging parameter mapping table and set it to the variable dac_current. Step A9: Repeat steps A2 to A8 until charging is complete; The conditions for ending charging are: the charging current drops below a certain value and the battery voltage reaches the full charge voltage value. After a certain period of time, the charging is considered to be finished and charging is stopped.
[0023] Specifically, based on the battery's charge-discharge characteristic curve, target charging current values and upper and lower voltage thresholds are preset for different charging stages and stored in a charging parameter mapping table. For example, for lithium batteries, the charging process can be divided into three stages: pre-charging, constant current charging, and constant voltage charging. In the pre-charging stage, the charging current is 1C, the upper voltage limit is 0V, and the lower voltage limit is 5V; in the constant current charging stage, the charging current is 5C, the upper voltage limit is 2V, and the lower voltage limit is 0V; and in the constant voltage charging stage, the charging current is 0.5C, the upper voltage limit is 2V, and the lower voltage limit is 1V. A foreground task retrieves the corresponding target charging current value from the charging parameter mapping table based on the charging stage and sets it to the variable `dac_current`. A background task timer periodically calls a background task, which compares the values of variables `dac_data` and `dac_current`. If `dac_data` equals `dac_current`, the current charging current remains unchanged, and the background task exits. If `dac_data` is less than `dac_current`, then `dac_data` is incremented by 1, the function for setting the current is called, the value of `dac_data` is converted into the corresponding current value, and output to the charging circuit to control the charging current. Then, the background task exits. If `dac_data` is greater than `dac_current`, then `dac_data` is decremented by 1, the function for setting the current is called, the value of `dac_data` is converted into the corresponding current value, and output to the charging circuit to control the charging current. Then, the background task exits. The slope of the charging current change is adjusted by changing the period of the background task's timer. For example, setting the timer period to 100ms means the background task is called every 100ms, causing the charging current to change every 100ms, with a change increment equal to the current value corresponding to one `dac_data`. During charging, the foreground task collects the battery voltage value in real time and determines whether it exceeds the upper or lower voltage threshold of the current charging stage. If it exceeds the threshold, depending on whether it exceeds the upper or lower limit, it switches to the next or previous charging stage and retrieves the target charging current value corresponding to the new charging stage from the charging parameter mapping table, setting it to the variable `dac_current`. For example, if the battery voltage exceeds 2V during constant current charging, the system switches to constant voltage charging and sets `dac_current` to the value corresponding to 0.5C. This process is repeated until charging is complete. Charging ends when the charging current drops below 0.2C and the battery voltage reaches 2V for 10 minutes.
[0024] S102. An embedded software architecture with dual-task asynchronous parallelism is adopted, in which the foreground task is responsible for reading the target charging current value of the current charging stage from the charging parameter mapping table and writing it into the global variable dac_current.
[0025] Based on the charging stage, the target charging current value for the current stage is obtained from the charging parameter mapping table and written into the global variable `dac_current`. A background task periodically calls this function via a timer to retrieve the value of `dac_current`. The background task then retrieves the current actual charging current value `dac_data` and checks if `dac_data` equals `dac_current`. If they are equal, the background task exits. If `dac_data` is less than `dac_current`, it increments `dac_data` and sets the charging current accordingly. If `dac_data` is greater than `dac_current`, it decrements `dac_data` and sets the charging current accordingly. After completing this round of processing, the background task waits for the timer to trigger again. The timer's period determines the slope of the charging current change; dynamic control of the charging current slope is achieved by adjusting the timer period. Specifically, the target charging current value for the current stage is obtained from the charging parameter mapping table based on the charging stage. For example, the target charging current for the constant current charging stage is 1000mA, and the obtained target charging current value is written to the global variable `dac_current`. The background task uses a timer to periodically call the function every 10ms to obtain the value of `dac_current`, and simultaneously obtains the current actual charging current value `dac_data` through ADC sampling. It checks if `dac_data` equals `dac_current`; if they are equal, the background task exits. If `dac_data` is less than `dac_current`, `dac_data` is incremented by 1, meaning the charging current increases by 1mA every 10ms, and the charging current is set through the DAC module based on the value of `dac_data`. If `dac_data` is greater than `dac_current`, `dac_data` is decremented by 1, meaning the charging current decreases by 1mA every 10ms, and the charging current is set through the DAC module based on the value of `dac_data`. After completing this round of processing, the background task waits for the timer to be triggered again. The timer period determines the slope of the charging current change. For example, if the current timer period is 10ms, and you need to achieve a charging current change at a slope of 100mA / s, you can change the timer period to 100ms. By dynamically adjusting the timer period, you can achieve dynamic control of the charging current slope, thereby meeting the charging needs of different batteries and improving charging efficiency and safety.
[0026] S103. The background task is woken up periodically via a programmable timer, with the wake-up period dynamically adjusted according to the current charging stage. After waking up, the target current value for the current charging stage is obtained by reading the dac_current variable.
[0027] Step B1: Based on the charging stage of the charger, obtain the timer wake-up period corresponding to that stage, and set the wake-up period of the programmable timer to that value. Step B2: After the timer wakes up, read the value of the dac_current variable to obtain the target current value for the current charging stage; Step B3: Obtain the value of the dac_data variable to determine the current actual charging current value; Step B4: Determine if dac_data is equal to dac_current. If they are equal, there is no need to adjust the charging current, and the background task can be exited directly. Step B5: If dac_data is less than dac_current, increment the value of dac_data by 1, set the charging current according to the new dac_data value, and then exit the background task. Step B6: If dac_data is greater than dac_current, decrement the value of dac_data by 1, set the charging current according to the new dac_data value, and then exit the background task. Step B7: After setting the charging current, the value of dac_data is converted into an analog current signal by a DA converter and output to the charging circuit to control the actual charging current. Step B8: Dynamically adjust the wake-up period of the programmable timer according to the status of the charger and the charging status of the battery to adapt to the requirements of the current slope at different charging stages. Step B9: After the background task completes one current adjustment, wait for the next timer wake-up and repeat steps B2 to B8 until the charging process is finished.
[0028] Specifically, during the charging process, the charger dynamically adjusts the wake-up period of the programmable timer based on the battery's charging state and its own operating state. For example, in the pre-charging stage, due to the smaller current, the wake-up period can be set to 100 milliseconds; in the constant current charging stage, the larger current requires more frequent adjustments, so the wake-up period can be set to 20 milliseconds; and in the constant voltage charging stage, as the current gradually decreases, the wake-up period can be gradually increased to 50 milliseconds. After the timer wakes up, the charger reads the `dac_current` variable to obtain the target current value for the current stage, for example, 1000 mA for the constant current charging stage. Then, the charger reads the `dac_data` variable through the ADC to obtain the actual charging current value, for example, 980 mA. The charger compares `dac_data` and `dac_current`. If they are equal, no adjustment is needed, and the process exits directly; if `dac_data` is less than `dac_current`, the value of `dac_data` is incremented by 1, for example, to 981 mA; if `dac_data` is greater than `dac_current`, the value of `dac_data` is decremented by 1, for example, to 979 mA. The adjusted dac_data value is converted into an analog current signal via a DAC to control the actual charging current. This process repeats continuously until charging is complete. Through this timed wake-up and dynamic adjustment method, the charging current can be precisely controlled, achieving a smooth current slope and ensuring charging safety and efficiency.
[0029] S104. The background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data as the basis for feedback control.
[0030] Step C1: Based on the charging stage, the foreground task sets the target charging current value dac_current, while the background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data. Step C2: Determine if adc_data is equal to dac_current. Step C3: If the current values are equal, maintain the current charging current and proceed to step C7. Step C4: If adc_data is less than dac_current, increment dac_data by 1 to obtain a new dac_data value. Use this new dac_data value to set the charging current, causing the actual current to gradually transition towards the target current. In step C5, if adc_data is greater than dac_current, then dac_data is decremented by 1 to obtain a new dac_data value. This new dac_data value is then used to set the charging current, causing the actual current to gradually transition towards the target current. Step C6: Based on the timer period, jump to step C2 to continue current sampling and adjustment. Step C7: Determine that the current charging current has reached the target value, maintain a constant charging current, and wait to enter the next charging stage.
[0031] Specifically, based on the charging stage, the foreground task sets the target charging current value `dac_current`. For example, if the current stage is constant current charging, `dac_current` is set to 1000mA. The background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable `adc_data`. Assume the current sampled value is 980mA. It checks if `adc_data` is equal to `dac_current`. In this example, 980mA is less than 1000mA, so `dac_data` is incremented by 1, resulting in a new value of 1001. The charging current is set using the new value 1001, causing the actual current to gradually approach the target current of 1000mA. If the next sampled value of `adc_data` is 1020mA, which is greater than the 1000mA of `dac_current`, then `dac_data` is decremented by 1, resulting in a new value of 999. The charging current is set using the new value 999, causing the actual current to gradually approach the target current of 1000mA. Based on the timer period, assuming it's 100ms, current sampling and adjustment are performed every 100ms until `adc_data` equals `dac_current`, indicating the actual current has reached the target current. Then, a constant charging current is maintained, awaiting the next charging stage, such as constant voltage charging. This closed-loop control algorithm ensures the charging current reaches the target value smoothly and accurately, preventing damage to the battery from sudden current changes.
[0032] S105. Compare the magnitudes of dac_current and adc_data. If they are equal, the actual current has reached the target value and no adjustment is needed. Exit the background task and wait for the next timer wake-up.
[0033] Step D1: Based on the target current value dac_current set in the foreground task, obtain the current actual current value dac_data. Step D2: Compare the sizes of dac_current and dac_data. Step D3: Determine if the two are equal. In step D4, if dac_current equals dac_data, the actual current has reached the target value and no adjustment is needed. Exit the background task and wait for the next timer wake-up. In step D5, if dac_current is greater than dac_data, then increment dac_data by 1 to obtain a new dac_data value. Use this new dac_data value to set the charging current, then exit the background task and wait for the next timer wake-up. Step D6: If dac_current is less than dac_data, then dac_data is decremented by 1 to obtain a new dac_data value. The charging current is set using the new dac_data value, and the background task is exited, waiting for the next timer wake-up. By changing the timer's period, the slope of the current change can be adjusted; the shorter the period, the steeper the slope, and the faster the current changes. D7 continuously executes steps D1-D6 until dac_current equals dac_data, thus smoothly transitioning the current from the initial value to the target value.
[0034] Specifically, based on the target current value `dac_current` set in the foreground task, the current actual current value `dac_data` is obtained through ADC sampling. The magnitudes of `dac_current` and `dac_data` are compared to determine if they are equal. If `dac_current` equals `dac_data`, the actual current has reached the target value, no adjustment is needed, and the background task exits, waiting for the next timer wake-up. If `dac_current` is greater than `dac_data`, `dac_data` is incremented by 1. For example, if `dac_current` is 1000 and `dac_data` is 800, then `dac_data` becomes 801, obtaining a new `dac_data` value. The charging current is set through the DAC module using the new `dac_data` value, and the background task exits, waiting for the next timer wake-up. If `dac_current` is less than `dac_data`, `dac_data` is decremented by 1. For example, if `dac_current` is 500 and `dac_data` is 800, then `dac_data` becomes 799, obtaining a new `dac_data` value. The charging current is set through the DAC module using the new `dac_data` value, and the background task exits, waiting for the next timer wake-up. By changing the timer period, the slope of the current change can be adjusted. For example, changing the timer period from 1 second to 5 seconds doubles the rate of current change. The shorter the period, the steeper the slope, and the faster the current changes. The above steps are continuously repeated until `dac_current` equals `dac_data`, achieving a smooth transition of the current from the initial value to the target value. The entire algorithm is implemented through software programming, requiring no manual intervention and automatically adjusting the charging current.
[0035] S106. If adc_data is less than dac_current, the PWM duty cycle is increased by a preset adjustment step, which represents an increase of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited.
[0036] Based on the charging stage, the foreground task sets the target charging current value `dac_current` and writes it into a shared variable in the background task. A timer periodically triggers the background task, which reads the target current value `dac_current` and the current actual current value `dac_data` from the shared variable. It checks if the current current value `dac_data` equals the target current value `dac_current`. If they are equal, the background task exits; otherwise, it proceeds to the next step. If `dac_data` is less than `dac_current`, the PWM duty cycle is increased by a preset adjustment step, representing an increase of one unit in the actual charging current. The new PWM duty cycle is then written to the DAC interface to increase the charging current before exiting the background task. If `dac_data` is greater than `dac_current`, the PWM duty cycle is decreased by a preset adjustment step, representing a decrease of one unit in the actual charging current. The new PWM duty cycle is then written to the DAC interface to decrease the charging current before exiting the background task. By adjusting the timer's trigger period, the slope of the current regulation can be controlled. A shorter period results in faster current regulation; a longer period results in slower current regulation. During current regulation, an ADC sampling circuit is used to detect the actual output current in real time. The sampled value is compared with dac_data to form a closed-loop control, ensuring the accuracy of the output current. After current regulation is completed, dac_data equals dac_current, and the background task no longer adjusts the PWM duty cycle, maintaining a stable charging current output. When charging enters the next stage, the foreground task updates the dac_current value, and the background task restarts the current regulation process based on the new target value until stability is achieved again.
[0037] Specifically, the foreground task sets the target charging current value `dac_current` to 500mA based on the charging stage and writes it into the shared variable of the background task. The timer triggers the background task every 10ms. The background task reads the target current value `dac_current` and the current actual current value `dac_data` obtained through ADC sampling from the shared variable. If `dac_data` equals 500mA, the background task exits; otherwise, if `dac_data` is less than 500mA, the PWM duty cycle is increased by 1%, representing an increase of 10mA in the actual charging current, and the new PWM duty cycle is written to the DAC interface before exiting the background task; if `dac_data` is greater than 500mA, the PWM duty cycle is decreased by 1%, representing a decrease of 10mA in the actual charging current, and the new PWM duty cycle is written to the DAC interface before exiting the background task. By adjusting the timer's trigger period to 5ms, the current regulation rate can be doubled. During current regulation, the ADC sampling circuit monitors the actual output current in real time at a frequency of 1kHz, comparing the sampled value with dac_data. If the deviation exceeds ±5mA, the PWM duty cycle is immediately adjusted to form closed-loop control, ensuring output current accuracy. After current regulation is complete, dac_data equals 500mA, and the background task no longer adjusts the PWM duty cycle, maintaining a stable charging current output. When charging enters the constant voltage stage, the foreground task updates dac_current to 200mA, and the background task restarts the current regulation process based on the new target value until stability is achieved again.
[0038] S107. If adc_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited.
[0039] Based on the charging stage and battery state, the target charging current value `dac_current` is determined and written into the corresponding variable in the foreground task. A timer periodically calls the background task to obtain the current actual charging current value `adc_data`. It checks if `adc_data` equals `dac_current`; if they are equal, the background task exits. If `adc_data` is less than `dac_current`, the PWM duty cycle is increased by a preset adjustment step, representing a one-unit increase in the actual charging current. The new PWM duty cycle is then written to the DAC interface to increase the charging current before exiting the background task. If `adc_data` is greater than `dac_current`, the PWM duty cycle is decreased by a preset adjustment step, representing a one-unit decrease in the actual charging current. The new PWM duty cycle is then written to the DAC interface to decrease the charging current before exiting the background task. Different current adjustment slopes are obtained by adjusting the timer period. A shorter period results in faster current adjustment; a longer period results in slower current adjustment. The latest `adc_data` and `dac_current` values are obtained each time the background task is entered to adjust the charging current promptly. Based on parameters such as battery voltage and temperature, determine whether the charging stage needs to be changed. If a change is necessary, update the `dac_current` value and write it to the foreground task variable. Use interrupt methods to monitor charging faults, such as overcurrent or overvoltage, and quickly disconnect the charging circuit to ensure charging safety.
[0040] Specifically, based on the charging stage and battery state, the foreground task determines the target charging current value `dac_current` to be 5A and writes it into the corresponding variable. The background task uses a timer to retrieve the current actual charging current value `adc_data` every 10ms. If `adc_data` equals 5A, the background task exits; if `adc_data` is less than 5A, the PWM duty cycle is increased by 5%, representing an increase of 1A in the actual charging current, and the new PWM duty cycle is written to the DAC interface to increase the charging current before exiting the background task; if `adc_data` is greater than 5A, the PWM duty cycle is decreased by 5%, representing a decrease of 1A in the actual charging current, and the new PWM duty cycle is written to the DAC interface to decrease the charging current before exiting the background task. By adjusting the timer period to 5ms, the current regulation slope can be doubled, accelerating the current regulation speed. Each time the background task is entered, the latest values of `adc_data` and `dac_current` are retrieved again to adjust the charging current promptly. Simultaneously, based on parameters such as battery voltage and temperature, it is determined whether the charging stage needs to be changed. For example, if the voltage exceeds 2V and the temperature exceeds 45℃, the charging stage is changed from constant current charging to constant voltage charging, and dac_current is updated to 2A and written to the foreground task variable. Finally, an interrupt method is used to monitor charging faults. If the charging current exceeds 2A or the battery voltage exceeds 5V, the MOSFET in the charging circuit is quickly disconnected to ensure charging safety.
[0041] S108. During the charging process, when the battery voltage reaches the upper limit threshold of the current charging stage, the foreground task reads the target charging current value of the next charging stage from the charging parameter mapping table and updates the dac_current variable.
[0042] Step E1: Based on the current charging stage, obtain the upper limit threshold of the battery voltage and monitor the battery voltage in real time. Step E2: If the battery voltage reaches the upper voltage threshold of the current charging stage, then read the target for the next charging stage from the charging parameter mapping table. In step E3, the target charging current value for the next charging stage is read and updated in the dac_current variable. In step E4, the background task periodically retrieves the values of the variables dac_data and dac_current using a timer. Step E5: Determine if dac_data is equal to dac_current. Step E6: If they are equal, exit the background task. In step E7, if dac_data is less than dac_current, increment dac_data by 1, set the charging current, and exit the background task. In step E8, if dac_data is greater than dac_current, then dac_data is decremented by 1, the charging current is set, and the background task is exited. The slope of the charging current change is adjusted by changing the timer period; the shorter the period, the steeper the slope, and the faster the current changes. Step E9: Repeat steps E4-E8 until charging is complete or an abnormal situation occurs, at which point charging will stop.
[0043] Specifically, based on the current charging stage, the system retrieves the upper limit threshold of the battery voltage from the charging parameter mapping table. For example, if the current stage is constant current charging, the upper limit threshold is 2V. The system monitors the battery voltage in real time using an ADC. When the voltage reaches 2V, it reads the target charging current value for the next stage from the mapping table, such as 5C, and updates it to the `dac_current` variable. A background task uses a timer with a 10ms cycle to retrieve the values of `dac_data` and `dac_current`. If they are equal, the task exits. If `dac_data` is less than `dac_current` (e.g., `dac_data` = 100 corresponds to 1A, and `dac_current` = 150 corresponds to 5A), `dac_data` is incremented by 1, and the new value 101 is written to the DAC, increasing the charging current by 0.1A, then the task exits. Similarly, if `dac_data` is greater than `dac_current`, it is decremented by 1, decreasing the current by 0.1A. By adjusting the timer period, the current slope can be changed. If the period is 10ms, the current changes 100 times per second, i.e., 1A / s. If the period is 100ms, the slope is 1A / s. The system continuously executes the above process until charging is complete or an abnormality occurs. The entire algorithm ensures a smooth and gradual change in charging current, avoiding abrupt changes and extending battery life.
[0044] S109. If the updated dac_current is not equal to adc_data, the background task will adjust the PWM duty cycle multiple times to eventually make adc_data converge to dac_current, smoothly transitioning to the next charging stage and avoiding sudden changes in charging current.
[0045] Step F1: Based on the charging stage, the foreground task sets the target current value dac_current. Step F2: The background task obtains the current current value dac_data and the target current value dac_current. Step F3: Determine if dac_data equals dac_current. If the values are equal in step F4, maintain the current PWM duty cycle and proceed to step F9. Step F5: If dac_data is less than dac_current, increase the charging current by increasing the PWM duty cycle to obtain a new dac_data. Step F6: If dac_data is greater than dac_current, then the charging current is reduced by decreasing the PWM duty cycle to obtain a new dac_data. Step F7: Based on the timer period, determine the time interval for the next adjustment of the PWM duty cycle to achieve gradual current change. In step F8, after the slope control timer reaches the set time, the background task is triggered to execute steps F2-F6 again until dac_data converges to dac_current. In step F9, the actual charging current is set using the new dac_data value. The background task enters a sleep state, waiting for the next adjustment cycle to arrive or for the foreground task to update the dac_current value.
[0046] Specifically, based on the charging stage, the foreground task sets the target current value dac_current to 500mA. The background task obtains the current value dac_data (480mA) through ADC sampling and compares it with the target current value dac_current. Since dac_data is less than dac_current, the charging current needs to be increased by increasing the PWM duty cycle. Assuming the current PWM duty cycle is 60% and the adjustment step is 5%, the PWM duty cycle is increased to 65%, and a new dac_data of 510mA is obtained by resampling. Based on a timer period of 100ms, the time interval for the next adjustment of the PWM duty cycle is determined to achieve gradual current slope control. After the timer reaches the set time, the background task is triggered to execute the above process again. After three iterations of adjustment, dac_data converges to within ±1% of the target value dac_current, i.e., 495~505mA. The actual charging current is set using the new dac_data value of 510mA, and constant current charging is performed according to the charging algorithm. The background task enters a sleep state, waiting for the next 100ms adjustment cycle or for the foreground task to update the dac_current value. A closed-loop control algorithm enables precise adjustment and dynamic tracking of the charging current, ensuring the safety and reliability of the charging process.
[0047] S1010. Throughout the charging process, dac_current carries the target current for the current charging stage, while adc_data reflects the actual current at all times. The two work together through closed-loop feedback control to ultimately achieve staged constant current and constant voltage charging, thus extending battery life.
[0048] Step G1: Obtain the target charging current value dac_current based on the current charging stage of the battery. Step G2 involves using an MCU timer to periodically call a background task and obtaining the actual charging current value dac_data through an ADC sampling circuit. Step G3: Determine if dac_data is equal to dac_current. If they are equal, maintain the current charging current and proceed to step G7. In step G4, if dac_data is less than dac_current, then increment dac_data by 1 to obtain the new dac_data value. In step G5, if dac_data is greater than dac_current, then dac_data is decremented by 1 to obtain the new dac_data value. Step G6: Based on the new dac_data value obtained in step G4 or G5, the DAC circuit outputs a corresponding control signal to adjust the charging current. Step G7: Determine whether the current charging phase has ended. If step G8 is not completed, proceed to step G2 to continue adjusting the charging current. In step G9, if the current charging phase has ended, obtain the target charging current value dac_current for the next charging phase and jump to step G2. Step G10: After the entire charging process is completed, stop the timer, shut down the ADC and DAC circuits, and release the MCU resources.
[0049] Specifically, based on the current charging stage of the battery, the target charging current value `dac_current` is obtained through a lookup table or calculation formula. For example, for the constant current charging stage of a lithium battery, `dac_current` can be set to 1C, i.e., 2A. Every 10ms, the MCU timer calls a background task to obtain the actual charging current value `dac_data` through a 12-bit ADC sampling circuit. The sampled value is compared with a reference voltage of 3V and converted into a digital quantity. The relationship between `dac_data` and `dac_current` is determined. If they are equal, the current charging current remains unchanged; if `dac_data` is less than `dac_current`, `dac_data` is incremented by 1 LSB, approximately 8mA; if `dac_data` is greater than `dac_current`, `dac_data` is decremented by 1 LSB. Based on the adjusted `dac_data` value, an 8-bit DAC circuit converts the digital quantity into an analog voltage signal of 0~3V to control the charging current. The system then determines whether the current charging stage has ended; for example, in constant current charging, this can be done by comparing whether the battery voltage has reached 2V. If the charging process is not yet complete, continue adjusting the charging current; if it has already ended, proceed to the next charging stage, such as constant voltage charging, and reacquire the target charging current value until charging is complete. Finally, stop the timer, shut down the ADC and DAC circuits, and release the MCU resources.
[0050] The above description of the embodiments is only for the purpose of helping to understand the technical solutions and core ideas of this application; those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A method for achieving gradual current change in a high-power charger, characterized in that, The method includes: Based on the battery's charge and discharge characteristic curve, target charging current values and upper and lower voltage thresholds are preset for different charging stages and stored in the charging parameter mapping table. An embedded software architecture with dual-task asynchronous parallelism is adopted, in which the foreground task is responsible for reading the target charging current value of the current charging stage from the charging parameter mapping table and writing it into the global variable dac_current; The background task is woken up periodically by a programmable timer. The wake-up period is dynamically adjusted according to the current charging stage. After waking up, the target current value of the current charging stage is obtained by reading the dac_current variable. The background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data as the basis for feedback control. Compare the values of dac_current and adc_data. If they are equal, the actual current has reached the target value and no adjustment is needed. Exit the background task and wait for the next timer wake-up. If adc_data is less than dac_current, the PWM duty cycle is increased by a preset adjustment step, which represents an increase of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited. If adc_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited. During the charging process, when the battery voltage reaches the upper limit threshold of the current charging stage, the foreground task reads the target charging current value for the next charging stage from the charging parameter mapping table and updates the dac_current variable. If the updated dac_current is not equal to adc_data, the background task will adjust the PWM duty cycle multiple times to eventually make adc_data converge to dac_current, smoothly transitioning to the next charging stage and avoiding sudden changes in charging current. Throughout the charging process, dac_current carries the target current for the current charging stage, while adc_data reflects the actual current at all times. The two work together through closed-loop feedback control to ultimately achieve staged constant current and constant voltage charging, thus extending battery life.
2. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, The method involves pre-setting target charging current values and upper and lower voltage thresholds for different charging stages based on the battery's charge-discharge characteristic curve, and storing these values in a charging parameter mapping table, including: Step A1: Based on the battery's charge and discharge characteristic curve, preset the target charging current value and voltage upper and lower limit thresholds for different charging stages and store them in the charging parameter mapping table. Step A2: The foreground task retrieves the corresponding target charging current value from the charging parameter mapping table according to the charging stage and sets it to the variable dac_current. Step A3: The background task is called periodically through a background task timer. The background task compares the values of variables dac_data and dac_current. Step A4: If dac_data equals dac_current, then maintain the current charging current and exit the background task. Step A5: If dac_data is less than dac_current, then dac_data is incremented by 1, the function for setting the current is called, the value of dac_data is converted into the corresponding current value, and output to the charging circuit to control the charging current. Then the background task is exited. Step A6: If dac_data is greater than dac_current, then dac_data is decremented by 1, the function for setting the current is called to convert the value of dac_data into the corresponding current value, output it to the charging circuit to control the charging current, and then the background task is exited. The slope of the charging current change can be adjusted by changing the period of the background task timer. The shorter the timer period, the greater the slope of the charging current change, and the faster the current changes. The longer the timer period, the smaller the slope of the charging current change and the slower the current change. Step A7: During the charging process, the foreground task collects the battery voltage value in real time and determines whether it exceeds the upper and lower voltage thresholds of the current charging stage. Step A8: If the threshold is exceeded, switch to the next charging stage or the previous charging stage depending on whether the upper or lower limit is exceeded, and obtain the target charging current value corresponding to the new charging stage from the charging parameter mapping table and set it to the variable dac_current. Step A9: Repeat steps A2 to A8 until charging is complete; The conditions for ending charging are: the charging current drops below a certain value and the battery voltage reaches the full charge voltage value. After a certain period of time, the charging is considered to be finished and charging is stopped.
3. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, The embedded software architecture employs a dual-task asynchronous parallel approach, where the foreground task is responsible for reading the target charging current value for the current charging stage from the charging parameter mapping table and writing it into the global variable dac_current, including: Based on the charging stage, the target charging current value for the current stage is obtained from the charging parameter mapping table and written into the global variable `dac_current`. A background task periodically calls this function via a timer to retrieve the value of `dac_current`. The background task then retrieves the current actual charging current value `dac_data` and checks if `dac_data` equals `dac_current`. If they are equal, the background task exits. If `dac_data` is less than `dac_current`, `dac_data` is incremented by 1, and the charging current is set according to its value. If `dac_data` is greater than `dac_current`, `dac_data` is decremented by 1, and the charging current is set according to its value. After completing this round of processing, the background task waits for the timer to trigger again. The timer's period determines the slope of the charging current change; dynamic control of the charging current slope is achieved by adjusting the timer period.
4. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, The background task is woken up periodically by a programmable timer, with the wake-up period dynamically adjusted according to the current charging stage. After waking up, the target current value for the current charging stage is obtained by reading the dac_current variable, including: Step B1: Based on the charging stage of the charger, obtain the timer wake-up period corresponding to that stage, and set the wake-up period of the programmable timer to that value. Step B2: After the timer wakes up, read the value of the dac_current variable to obtain the target current value for the current charging stage; Step B3: Obtain the value of the dac_data variable to determine the current actual charging current value; Step B4: Determine if dac_data is equal to dac_current. If they are equal, there is no need to adjust the charging current, and the background task can be exited directly. Step B5: If dac_data is less than dac_current, increment the value of dac_data by 1, set the charging current according to the new dac_data value, and then exit the background task. Step B6: If dac_data is greater than dac_current, decrement the value of dac_data by 1, set the charging current according to the new dac_data value, and then exit the background task. Step B7: After setting the charging current, the value of dac_data is converted into an analog current signal by a DA converter and output to the charging circuit to control the actual charging current. Step B8: Dynamically adjust the wake-up period of the programmable timer according to the status of the charger and the charging status of the battery to adapt to the requirements of the current slope at different charging stages. Step B9: After the background task completes one current adjustment, wait for the next timer wake-up and repeat steps B2 to B8 until the charging process is finished.
5. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, The background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data as the basis for feedback control, including: Step C1: Based on the charging stage, the foreground task sets the target charging current value dac_current, while the background task samples the actual charging current of the battery in real time through the ADC interface and assigns the sampled value to the global variable adc_data. Step C2: Determine if adc_data is equal to dac_current. Step C3: If the current values are equal, maintain the current charging current and proceed to step C7. Step C4: If adc_data is less than dac_current, increment dac_data by 1 to obtain a new dac_data value. Use this new dac_data value to set the charging current, causing the actual current to gradually transition towards the target current. In step C5, if adc_data is greater than dac_current, then dac_data is decremented by 1 to obtain a new dac_data value. This new dac_data value is then used to set the charging current, causing the actual current to gradually transition towards the target current. Step C6: Based on the timer period, jump to step C2 to continue current sampling and adjustment. Step C7: Determine that the current charging current has reached the target value, maintain a constant charging current, and wait to enter the next charging stage.
6. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, The comparison of dac_current and adc_data, if they are equal, indicates that the actual current has reached the target value, requiring no adjustment. The background task then exits and waits for the next timer wake-up, including: Step D1: Based on the target current value dac_current set in the foreground task, obtain the current actual current value dac_data. Step D2: Compare the sizes of dac_current and dac_data. Step D3: Determine if the two are equal. In step D4, if dac_current equals dac_data, the actual current has reached the target value and no adjustment is needed. Exit the background task and wait for the next timer wake-up. In step D5, if dac_current is greater than dac_data, then increment dac_data by 1 to obtain a new dac_data value. Use this new dac_data value to set the charging current, then exit the background task and wait for the next timer wake-up. Step D6: If dac_current is less than dac_data, then dac_data is decremented by 1 to obtain a new dac_data value. The charging current is set using the new dac_data value, and the background task is exited, waiting for the next timer wake-up. By changing the timer's period, the slope of the current change can be adjusted; the shorter the period, the steeper the slope, and the faster the current changes. D7 continuously executes steps D1-D6 until dac_current equals dac_data, thus smoothly transitioning the current from the initial value to the target value.
7. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, If `adc_data` is less than `dac_current`, the PWM duty cycle is increased by a preset adjustment step, representing an increase of one unit in the actual charging current. The new PWM duty cycle is then written to the DAC interface to increase the charging current before exiting the background task. Based on the charging stage, the foreground task sets the target charging current value dac_current and writes it into the shared variable of the background task; The timer periodically triggers a background task, which reads the target current value dac_current and the current actual current value dac_data from the shared variables. Determine if the current current value dac_data is equal to the target current value dac_current. If they are equal, exit the background task; otherwise, proceed to the next step. If dac_data is less than dac_current, the PWM duty cycle is increased by a preset adjustment step, which represents an increase of one unit in the actual charging current. Then, the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited. If dac_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited. The slope of the current regulation can be controlled by adjusting the trigger period of the timer; The shorter the cycle, the faster the current regulation; The longer the cycle, the slower the current regulation; During the current regulation process, an ADC sampling circuit is used to detect the actual output current in real time, and the sampled value is compared with dac_data to form a closed-loop control to ensure the accuracy of the output current. After the current regulation is completed, dac_data equals dac_current, and the background task no longer adjusts the PWM duty cycle to maintain a stable charging current output; When charging enters the next stage, the foreground task updates the dac_current value, and the background task restarts the current regulation process based on the new target value until it reaches stability again.
8. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, If `adc_data` is greater than `dac_current`, the PWM duty cycle is reduced by a preset adjustment step size, representing a one-unit reduction in the actual charging current. The new PWM duty cycle is then written to the DAC interface to reduce the charging current, and the background task is exited. This includes: Based on the charging stage and battery status, determine the target charging current value dac_current and write it into the corresponding variable of the foreground task; A timer is used to periodically call a background task to obtain the current actual charging current value adc_data; Check if adc_data is equal to dac_current; if they are equal, exit the background task. If adc_data is less than dac_current, then the PWM duty cycle is increased by the preset adjustment step size, which represents an increase of one unit in the actual charging current. Then the new PWM duty cycle is written to the DAC interface to increase the charging current, and then the background task is exited. If adc_data is greater than dac_current, the PWM duty cycle is reduced by a preset adjustment step, which means the actual charging current is reduced by one unit. Then the new PWM duty cycle is written to the DAC interface to reduce the charging current, and then the background task is exited. Different current regulation slopes can be obtained by adjusting the timer period; The shorter the cycle, the faster the current regulation; The longer the cycle, the slower the current regulation; Each time a background task is initiated, the latest adc_data and dac_current values are obtained in order to adjust the charging current in a timely manner. Based on parameters such as battery voltage and temperature, determine whether the charging stage needs to be changed. If a change is needed, update the dac_current value and write it to the foreground task variable. The system uses an interruption method to monitor charging faults, such as overcurrent and overvoltage, and quickly cuts off the charging circuit to ensure charging safety.
9. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, During the charging process, when the battery voltage reaches the upper voltage threshold of the current charging stage, the foreground task reads the target charging current value for the next charging stage from the charging parameter mapping table and updates the dac_current variable, including: Step E1: Based on the current charging stage, obtain the upper limit threshold of the battery voltage and monitor the battery voltage in real time. Step E2: If the battery voltage reaches the upper voltage threshold of the current charging stage, then read the target for the next charging stage from the charging parameter mapping table. In step E3, the target charging current value for the next charging stage is read and updated in the dac_current variable. In step E4, the background task periodically retrieves the values of the variables dac_data and dac_current using a timer. Step E5: Determine if dac_data is equal to dac_current. Step E6: If they are equal, exit the background task. In step E7, if dac_data is less than dac_current, increment dac_data by 1, set the charging current, and exit the background task. In step E8, if dac_data is greater than dac_current, then dac_data is decremented by 1, the charging current is set, and the background task is exited. The slope of the charging current change is adjusted by changing the timer period; the shorter the period, the steeper the slope, and the faster the current changes. Step E9: Repeat steps E4-E8 until charging is complete or an abnormal situation occurs, at which point charging will stop.
10. The method for achieving gradual current change in a high-power charger according to claim 1, characterized in that, If the updated dac_current is not equal to adc_data, the background task will adjust the PWM duty cycle multiple times until adc_data converges to dac_current, smoothly transitioning to the next charging stage and avoiding sudden changes in charging current. This includes: Step F1: Based on the charging stage, the foreground task sets the target current value dac_current. Step F2: The background task obtains the current current value dac_data and the target current value dac_current. Step F3: Determine if dac_data equals dac_current. If the values are equal in step F4, maintain the current PWM duty cycle and proceed to step F9. Step F5: If dac_data is less than dac_current, increase the charging current by increasing the PWM duty cycle to obtain a new dac_data. Step F6: If dac_data is greater than dac_current, then the charging current is reduced by decreasing the PWM duty cycle to obtain a new dac_data. Step F7: Based on the timer period, determine the time interval for the next adjustment of the PWM duty cycle to achieve gradual current change. In step F8, after the slope control timer reaches the set time, the background task is triggered to execute steps F2-F6 again until dac_data converges to dac_current. In step F9, the actual charging current is set using the new dac_data value. The background task enters a sleep state, waiting for the next adjustment cycle to arrive or for the foreground task to update the dac_current value.