Two-cascade joint debugging direct-current stabilized power supply method based on microcontroller control
Through a two-cascade DC voltage-regulating power supply method based on microcontroller, the step-down transformer, rectifier bridge, filter capacitor, switching power supply module and adjustable integrated voltage regulator are used, combined with the STM32F4 microcontroller and PID algorithm, the problem of unstable output of the traditional DC voltage-regulating power supply is solved, and the continuous adjustable and real-time protection of the output voltage is achieved.
Patent Information
- Application Number
- CN202510878936.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-08-05
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional DC voltage-regulated power supplies have a fixed output voltage or limited adjustment range, which is difficult to adapt to a variety of application scenarios. The output voltage is unstable when load changes or input voltage fluctuates, and lacks real-time monitoring and intelligent protection functions.
The two-cascaded DC voltage-regulating power supply method based on microcontroller is adopted, and the voltage regulation and stabilization is used to regulate and stabilize the voltage by step-down transformer, rectifier bridge, parallel filter capacitor, switching power module, adjustable integrated voltage regulator and microcontroller (STM32F4). The PID algorithm and relay switching circuit are combined to realize real-time monitoring and protection of the output voltage.
It realizes continuous adjustable output voltage in the range of 2.5V to 20V, improves the stability and intelligence level of the power supply system, has real-time monitoring and overcurrent protection functions, and adapts to different load conditions.
Smart Images

Figure CN120433601A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of DC regulated power supply, in particular to a two-stage cascade regulation DC regulated power supply method based on microcontroller control. Background Art
[0002] A DC regulated power supply is an electronic device that converts alternating current (AC) into a stable DC voltage output. It is commonly used to provide a stable and reliable power supply for various electronic devices, ensuring their proper function under varying load conditions and input voltage fluctuations. DC regulated power supplies are widely used in industrial control, communications equipment, medical instruments, laboratory testing equipment, and other fields. Therefore, utilizing advanced technologies to improve the intelligence and safety of DC regulated power supplies has become a pressing issue.
[0003] In the field of DC regulated power supplies, traditional DC regulated power supplies often have a fixed output voltage or a limited adjustment range, which makes it difficult to adapt to the needs of various application scenarios. When the load changes or the input voltage fluctuates, the output voltage of the traditional regulated power supply is easily affected, resulting in unstable output. In addition, traditional regulated power supplies usually do not have real-time monitoring and intelligent protection functions. Users cannot understand the system status in a timely manner, nor can they automatically take protective measures under abnormal circumstances. Summary of the Invention
[0004] In view of the above existing problems, the present invention is proposed.
[0005] Therefore, the present invention provides a two-stage cascaded DC regulated power supply method based on microcontroller control to solve the problem that traditional DC regulated power supplies often have a fixed output voltage or a limited adjustment range, which is difficult to adapt to the needs of various application scenarios. When the load changes or the input voltage fluctuates, the output voltage of the traditional regulated power supply is easily affected, resulting in unstable output.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions: In a first aspect, the present invention provides a two-stage cascade-regulated DC regulated power supply method based on microcontroller control, comprising: A step-down transformer is used to convert AC mains power into a secondary output AC voltage, which is then converted into a pulsating DC voltage via a rectifier bridge; Use parallel filter capacitors to filter the pulsating DC voltage to reduce voltage fluctuations and obtain a smooth DC voltage; The smooth DC voltage is input to the switching power supply module, and the working state of the switch tube is adjusted using the PWM control method to adjust the output voltage and obtain the primary stable DC voltage; The three-terminal adjustable integrated voltage regulator LM317 is used in combination with a voltage divider network to regulate and stabilize the primary DC voltage, ensuring that the output voltage is continuously adjustable within the range of 2.5V to 20V. The STM32F4 series microcontroller is used as the control core. The output voltage and current data are collected through the ADC interface, and the PID algorithm is applied to calculate the required adjustment parameters, thereby adjusting the PWM duty cycle to optimize the output voltage stability. Use the relay switching circuit to connect different load resistors and measure the output voltage changes and ripple size under different load conditions; The serial port screen displays the current output voltage, current value and system status information in real time, and provides overcurrent protection function, which automatically cuts off the main circuit when the current exceeds the limit.
[0007] As a preferred solution of the two-stage cascaded DC regulated power supply method based on microcontroller control of the present invention, wherein: the AC mains is converted into a secondary output AC voltage by a step-down transformer, and then converted into a pulsating DC voltage by a rectifier bridge, the specific steps are as follows: A step-down transformer is used to reduce the voltage of the input 220V AC mains power; Calculate the secondary output AC voltage based on the transformer turns ratio; Assume the number of turns of the primary winding is , the number of turns of the secondary winding is ; Calculate the secondary output voltage using the expression: ; in, is the primary voltage value; The rectifier bridge D1 is used to rectify the secondary output AC voltage Uac; When the AC voltage is in the positive half cycle, diodes D1 and D3 in the rectifier bridge are turned on, and current flows through the load from top to bottom; When the AC voltage is in the negative half cycle, diodes D2 and D4 are turned on, and the current still flows from top to bottom; Through the action of the rectifier bridge, the original bidirectional AC voltage is converted into a unidirectional pulsating DC voltage Udc1.
[0008] As a preferred solution of the two-stage cascade-regulated DC regulated power supply method based on microcontroller control of the present invention, wherein: the pulsating DC voltage is filtered by a parallel filter capacitor to reduce voltage fluctuations and obtain a smooth DC voltage. The specific steps are: Connect capacitors C1 and C4 in parallel across the rectified pulsating DC voltage Udc1; When the voltage increases, the capacitor charges and stores energy; When the voltage drops, the capacitor releases energy to replenish the reduced voltage; Assume the capacitor capacity is , the load resistance is , then the capacitor charging and discharging time constant is Determines the smoothness of voltage fluctuations and obtains a smoother DC voltage Udc2.
[0009] As a preferred solution of the two-stage cascaded DC regulated power supply method based on microcontroller control of the present invention, wherein: the smoothed DC voltage is input to the switching power supply module, the working state of the switching tube is adjusted by PWM control to achieve the regulation of the output voltage and obtain the primary stable DC voltage, the specific steps are as follows: The smooth DC voltage Udc2 obtained by processing through the step-down transformer and the rectifier filter circuit is used as the input voltage of the switching power supply module; The XL6009 chip integrated in the switching power supply module generates a PWM signal through the internal PWM controller according to the set target output voltage Vo requirement; Assume the target output voltage is , the input voltage is , calculate the PWM duty cycle , the expression is: ; And obtain the primary stable DC voltage Vsw1; A feedback loop is set inside the switching power supply module to monitor the primary stable DC voltage Vsw1 in real time and compare it with the preset target output voltage. Make comparisons; Assume the current output voltage error is ,in ; Proportional term ,in is the proportional gain coefficient; Integral Item ,in is the integral gain coefficient, is the sum of the errors of all sampling points from the beginning to now; differential term ,in is the differential gain coefficient, is the error value of the last sampling, is the time interval between two samples; The total adjustment is ; Update PWM duty cycle , ensuring that the output voltage reaches and maintains the predetermined value, obtaining a more accurate primary stable DC voltage ; The primary stable DC voltage after PWM modulation Input to the inductor and capacitors In the LC filter composed of; Assume the inductance is , the capacitance value is , then the time constant of the filter is Determines its ability to suppress high-frequency ripple and obtain the final stable primary DC voltage .
[0010] As a preferred solution of the two-stage cascaded DC regulated power supply method based on microcontroller control of the present invention, wherein: the three-terminal adjustable integrated voltage regulator LM317 is used in combination with a voltage divider network to regulate and stabilize the primary stable DC voltage to ensure that the output voltage is continuously adjustable within the range of 2.5V to 20V. The specific steps are as follows: Use the three-terminal adjustable integrated voltage regulator LM317 to stabilize the primary DC voltage For further adjustment, the LM317 adjusts the output voltage through an internal reference voltage and an external resistor divider network; Connect a resistor R1 between the output terminal and the adjustment terminal of LM317, and connect another resistor R2 between the adjustment terminal and ground to form a voltage divider network. Assuming the resistance value of R1 is R1 and the resistance value of R2 is R2, calculate the output voltage according to the formula: ; in, The internal reference voltage of LM317 is 1.25V; According to the required target output voltage , use the above formula to reversely calculate the appropriate resistance values of R1 and R2; The primary stabilized DC voltage Input to the input of LM317, and change the output voltage by adjusting the resistance ratio of R1 and R2 ; Capacitors C2 and C3 are connected in parallel at the input and output of LM317 respectively to filter out high-frequency noise and ripple to improve the stability and quality of the output voltage. Assume that the capacity of C2 is C2 and the capacity of C3 is C3, then the selection of capacitors should take into account the load current and frequency response.
[0011] As a preferred solution of the two-stage cascaded DC regulated power supply method based on microcontroller control of the present invention, wherein: the three-terminal adjustable integrated voltage regulator LM317 is used in combination with a voltage divider network to regulate and stabilize the primary stable DC voltage to ensure that the output voltage is continuously adjustable within the range of 2.5V to 20V. The specific steps are as follows: Use the three-terminal adjustable integrated voltage regulator LM317 to stabilize the primary DC voltage For further adjustment, the LM317 adjusts the output voltage through an internal reference voltage and an external resistor divider network; Connect a resistor R1 between the output terminal and the adjustment terminal of LM317, and connect another resistor R2 between the adjustment terminal and ground to form a voltage divider network. Assuming the resistance value of R1 is R1 and the resistance value of R2 is R2, calculate the output voltage according to the formula: ; in, The internal reference voltage of LM317 is 1.25V; According to the required target output voltage , use the above formula to reversely calculate the appropriate resistance values of R1 and R2; The primary stabilized DC voltage Input to the input of LM317, and change the output voltage by adjusting the resistance ratio of R1 and R2 ; Capacitors C2 and C3 are connected in parallel at the input and output of LM317 respectively to filter out high-frequency noise and ripple to improve the stability and quality of the output voltage. Assume that the capacity of C2 is C2 and the capacity of C3 is C3, then the selection of capacitors should take into account the load current and frequency response.
[0012] 6. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control as claimed in claim 5, characterized in that: the STM32F4 series microcontroller is used as the control core, the output voltage and current data are collected through the ADC interface, and the PID algorithm is applied to calculate the required adjustment parameters, and then the PWM duty cycle is adjusted to optimize the output voltage stability, and the specific steps are: The STM32F4 series microcontroller is used as the control core of the entire system. The STM32F4 series microcontroller has powerful processing capabilities and rich peripheral resources; The built-in ADC interface of the STM32F4 microcontroller is used to adjust the output voltage after LM317 and current Conduct real-time collection; Assume the target output voltage is The actual measured output voltage is ; Compare the collected output voltage data with the preset target output voltage and calculate the current output voltage error , the expression is: ; The PID algorithm is used to calculate the error To process, first calculate the proportional term ; Assume the proportional gain coefficient is , then the proportional term P is calculated as: ; The PID algorithm is used to calculate the error Process and calculate the integral term ; Assume the integral gain coefficient is , cumulative error The sum of the errors of all sampling points from the beginning to now; The PID algorithm is used to calculate the error Process and calculate the differential term ; Assume the differential gain coefficient is , the error value of the last sampling is The time interval between two samples is ; Comprehensive proportion item , integral item and the differential term , calculate the total adjustment ; According to the adjustment amount Update the current PWM duty cycle ; The updated PWM duty cycle The XL6009 chip used in the switching power supply module can precisely adjust the output voltage by adjusting the working state of the switching tube.
[0013] As a preferred solution of the two-stage cascade-regulated DC regulated power supply method based on microcontroller control of the present invention, wherein: using a relay switching circuit to connect different load resistors and measuring the change of output voltage and ripple size under different load conditions, the specific steps are as follows: Adopt relay switching circuit to automatically switch to load resistors of different resistance values according to preset programs or user instructions; Use the STM32F4 series microcontroller to control the relay switching circuit through the GPIO pin and select the appropriate load resistor; Under the selected load resistance, the ADC interface of the STM32F4 microcontroller is used to collect the current output voltage and current data in real time; According to the collected output voltage data, calculate the output voltage change under each load resistance ; Use an oscilloscope to measure the ripple voltage under each load resistor; The measured output voltage change The ripple voltage is stored in the memory of the STM32F4 microcontroller and the data is displayed in real time through the serial port screen; Determine the output voltage change under each load resistance based on the measurement results Whether the ripple voltage meets the technical requirements; If the measurement results do not meet the technical requirements, adjust the PID parameters and retest; Repeat the above steps, including relay switching, data acquisition, calculation, measurement, display and judgment, until the output voltage change and ripple voltage under all load resistances meet the technical indicator requirements.
[0014] As a preferred solution of the two-stage cascaded DC regulated power supply method based on microcontroller control of the present invention, wherein: the current output voltage, current value and system status information are displayed in real time through the serial port screen, and an overcurrent protection function is provided. When the current exceeds the limit, the main circuit is automatically cut off. The specific steps are as follows: The output voltage and current regulated by LM317 are collected in real time using the built-in ADC interface of the STM32F4 series microcontroller. Format the collected output voltage and current data into information suitable for display; Receive data from the STM32F4 microcontroller through the serial port screen and present it visually to the user; Set the safety threshold for overcurrent protection and monitor the current value collected through the ADC interface in real time; The monitored current value is compared with the set safety threshold to determine whether overcurrent protection is triggered; When the current exceeds the limit, the relay is triggered immediately to disconnect the main circuit to prevent equipment damage.
[0015] In a third aspect, the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, any step of the two-stage cascaded DC regulated power supply method based on microcontroller control as described in the first aspect of the present invention is implemented.
[0016] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements any step of the two-stage cascaded DC regulated power supply method based on microcontroller control as described in the first aspect of the present invention.
[0017] The beneficial effects of the present invention are as follows: by connecting capacitors C1 and C4 in parallel at both ends of the rectified pulsating DC voltage Udc1, charging when the voltage increases and discharging when it decreases, thereby reducing voltage fluctuations and obtaining a relatively smooth DC voltage Udc2, preliminary filtering and smoothing of the rectified voltage are achieved; by inputting the filtered DC voltage Udc2 into a switching power supply module, using an XL6009 chip to generate a PWM signal, and dynamically adjusting the duty cycle using a PID algorithm according to the error between the target output voltage Vo and the actual output voltage, finally obtaining a primary stable DC voltage after LC filtering, efficient primary voltage regulation of the output voltage is achieved; by inputting the primary stable DC voltage into a three-terminal adjustable integrated voltage regulator LM317, and connecting a voltage divider network composed of R1 and R2 between its output terminal and the adjustment terminal, combined with an internal reference voltage of 1.25V, the output voltage is continuously adjustable in the range of 2.5V to 20V, thereby achieving precise secondary voltage regulation of the output voltage. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0019] Figure 1 This is a flow chart of the two-stage cascaded DC regulated power supply method based on microcontroller control in Example 1. DETAILED DESCRIPTION
[0020] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0021] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0022] Secondly, the term "one embodiment" or "embodiment" herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in various places throughout this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive of other embodiments.
[0023] Example 1, with reference to Figure 1 , which is the first embodiment of the present invention, provides a two-stage cascade-regulated DC regulated power supply method based on microcontroller control, comprising the following steps: S1, uses a step-down transformer to convert AC mains power into a secondary output AC voltage, and then converts it into a pulsating DC voltage through a rectifier bridge; Furthermore, a step-down transformer is used to reduce the voltage of the input 220V AC mains power; Calculate the secondary output AC voltage based on the transformer turns ratio; Assume the number of turns of the primary winding is , the number of turns of the secondary winding is ; Calculate the secondary output voltage using the expression: ; in, is the primary voltage value; The rectifier bridge D1 is used to rectify the secondary output AC voltage Uac; When the AC voltage is in the positive half cycle, diodes D1 and D3 in the rectifier bridge are turned on, and current flows through the load from top to bottom; When the AC voltage is in the negative half cycle, diodes D2 and D4 are turned on, and the current still flows from top to bottom; Through the action of the rectifier bridge, the original bidirectional AC voltage is converted into a unidirectional pulsating DC voltage Udc1; It should be noted that the step-down transformer used in this step is an industrial frequency transformer. The input end is connected to 220V AC power, and the output end selects a suitable turns ratio according to the design requirements to obtain the required secondary voltage. The rectifier bridge D1 consists of four diodes to form a full-wave rectifier circuit, which converts the AC voltage into a unidirectional pulsating DC voltage, which is suitable for subsequent filtering processing. This structure is simple and reliable and is widely used in various linear power supply systems.
[0024] S2, use parallel filter capacitors to filter the pulsating DC voltage to reduce voltage fluctuations and obtain a smooth DC voltage; Furthermore, capacitors C1 and C4 are connected in parallel across the rectified pulsating DC voltage Udc1; When the voltage increases, the capacitor charges and stores energy; When the voltage drops, the capacitor releases energy to replenish the reduced voltage; Assume the capacitor capacity is , the load resistance is , then the capacitor charging and discharging time constant is Determines the smoothness of voltage fluctuations and obtains a smoother DC voltage Udc2; It should be noted that the parallel filter capacitors C1 and C4 used in this step are usually electrolytic capacitors because they have large capacitance and good low-frequency filtering characteristics. By reasonably selecting the matching relationship between the capacitance value and the load resistance, the ripple component in the output voltage can be effectively reduced and the voltage stability can be improved.
[0025] S3. Input the smooth DC voltage to the switching power supply module, use PWM control to adjust the working state of the switch tube, realize the regulation of the output voltage, and obtain the primary stable DC voltage; Furthermore, the smoothed DC voltage Udc2 obtained after processing by the step-down transformer and the rectifier filter circuit is used as the input voltage of the switching power supply module; The XL6009 chip integrated in the switching power supply module generates a PWM signal through the internal PWM controller according to the set target output voltage Vo requirement; Assume the target output voltage is , the input voltage is , calculate the PWM duty cycle , the expression is: ; And obtain the primary stable DC voltage Vsw1; A feedback loop is set inside the switching power supply module to monitor the primary stable DC voltage Vsw1 in real time and compare it with the preset target output voltage. Make comparisons; Assume the current output voltage error is ,in ; Proportional term ,in is the proportional gain coefficient; Integral Item ,in is the integral gain coefficient, is the sum of the errors of all sampling points from the beginning to now; differential term ,in is the differential gain coefficient, is the error value of the last sampling, is the time interval between two samples; The total adjustment is ; Update PWM duty cycle , ensuring that the output voltage reaches and maintains the predetermined value, obtaining a more accurate primary stable DC voltage ; The primary stable DC voltage after PWM modulation Input to the inductor and capacitors In the LC filter composed of; Assume the inductance is , the capacitance value is , then the time constant of the filter is Determines its ability to suppress high-frequency ripple and obtain the final stable primary DC voltage ; It should be noted that the XL6009 chip used in this step is a high-efficiency DC-DC step-up / step-down regulator with an integrated PWM controller and power switch tube. It is suitable for power supply systems with a wide input voltage range. The feedback loop uses a PID control algorithm to perform closed-loop regulation of the output voltage to ensure stable output under different load conditions. The LC filter consists of an inductor L and a capacitor C, which can further suppress high-frequency switching noise and improve the output voltage quality.
[0026] S4. Use the three-terminal adjustable integrated voltage regulator LM317 in combination with the voltage divider network to regulate and stabilize the primary stable DC voltage to ensure that the output voltage is continuously adjustable in the range of 2.5V to 20V; Furthermore, a three-terminal adjustable integrated voltage regulator LM317 is used to stabilize the primary DC voltage. For further adjustment, LM317 adjusts the output voltage through the internal reference voltage and external resistor divider network; Connect a resistor R1 between the output terminal and the adjustment terminal of LM317, and connect another resistor R2 between the adjustment terminal and ground to form a voltage divider network. Assuming the resistance value of R1 is R1 and the resistance value of R2 is R2, calculate the output voltage according to the formula: ; in, The internal reference voltage of LM317 is 1.25V; According to the required target output voltage , use the above formula to reversely calculate the appropriate resistance values of R1 and R2; The primary stabilized DC voltage Input to the input of LM317, and change the output voltage by adjusting the resistance ratio of R1 and R2 ; Capacitors C2 and C3 are connected in parallel at the input and output of LM317 respectively to filter out high-frequency noise and ripple to improve the stability and quality of the output voltage. Assuming the capacity of C2 is C2 and the capacity of C3 is C3, the selection of capacitors should take into account the load current and frequency response; It should be noted that the LM317 used in this step is a widely used three-terminal adjustable positive voltage regulator with built-in overheating and overcurrent protection functions. Its output voltage is determined by the external voltage divider resistors R1 and R2. C2 and C3 are used for high-frequency filtering at the input and output ends, respectively. Ceramic capacitors are recommended to improve high-frequency response performance, thereby ensuring the stability and anti-interference ability of the output voltage.
[0027] S5 uses the STM32F4 series microcontroller as the control core, collects output voltage and current data through the ADC interface, and applies the PID algorithm to calculate the required adjustment parameters, thereby adjusting the PWM duty cycle to optimize the output voltage stability; Furthermore, the STM32F4 series microcontroller is used as the control core of the entire system. The STM32F4 series microcontroller has powerful processing capabilities and rich peripheral resources; The built-in ADC interface of the STM32F4 microcontroller is used to adjust the output voltage after LM317 and current Conduct real-time collection; Assume the target output voltage is The actual measured output voltage is ; Compare the collected output voltage data with the preset target output voltage and calculate the current output voltage error , the expression is: ; The PID algorithm is used to calculate the error To process, first calculate the proportional term ; Assume the proportional gain coefficient is , then the proportional term P is calculated as: ; The PID algorithm is used to calculate the error Process and calculate the integral term ; Assume the integral gain coefficient is , cumulative error The sum of the errors of all sampling points from the beginning to now; The PID algorithm is used to calculate the error Process and calculate the differential term ; Assume the differential gain coefficient is , the error value of the last sampling is The time interval between two samples is ; Comprehensive proportion item , integral item and the differential term , calculate the total adjustment ; According to the adjustment amount Update the current PWM duty cycle ; The updated PWM duty cycle The XL6009 chip used in the switching power supply module can precisely adjust the output voltage by adjusting the working state of the switching tube; It should be noted that the STM32F4 series microcontroller used in this step has a high-performance ARM Cortex-M4 core, supports floating-point operations and rich peripheral resources, is suitable for real-time control systems, and has high ADC interface acquisition accuracy and configurable sampling frequency. It can meet the high-precision measurement requirements of analog signals such as voltage and current. The PID control algorithm runs inside the microcontroller and achieves precise control of the output voltage through dynamic adjustment of the error, thereby enhancing the system's adaptability and stability.
[0028] S6. Use the relay switching circuit to connect different load resistors and measure the output voltage changes and ripple size under different load conditions; Furthermore, a relay switching circuit is used to automatically switch to load resistors of different resistance values according to a preset program or user instructions; Use the STM32F4 series microcontroller to control the relay switching circuit through the GPIO pin and select the appropriate load resistor; Under the selected load resistance, the ADC interface of the STM32F4 microcontroller is used to collect the current output voltage and current data in real time; According to the collected output voltage data, calculate the output voltage change under each load resistance ; Use an oscilloscope to measure the ripple voltage under each load resistor; The measured output voltage change The ripple voltage is stored in the memory of the STM32F4 microcontroller and the data is displayed in real time through the serial port screen; Determine the output voltage change under each load resistance based on the measurement results Whether the ripple voltage meets the technical requirements; If the measurement results do not meet the technical requirements, adjust the PID parameters and retest; Repeat the above steps, including relay switching, data acquisition, calculation, measurement, display and judgment, until the output voltage variation and ripple voltage under all load resistances meet the technical index requirements; It should be noted that the relay switching circuit used in this step consists of multiple relays and corresponding load resistors. It can automatically switch different load conditions according to preset programs or user instructions. By measuring the output voltage change and ripple size under different loads, the load capacity and stability of the power supply system can be evaluated. The test data is stored by the microcontroller and displayed on the serial port screen, which facilitates the analysis and optimization of system parameters and improves debugging efficiency and system reliability.
[0029] S7, the serial port screen displays the current output voltage, current value and system status information in real time, and provides overcurrent protection function, automatically cutting off the main circuit when the current exceeds the limit; Furthermore, the built-in ADC interface of the STM32F4 series microcontroller is used to collect the output voltage and current regulated by the LM317 in real time; Format the collected output voltage and current data into information suitable for display; Receive data from the STM32F4 microcontroller through the serial port screen and present it visually to the user; Set the safety threshold for overcurrent protection and monitor the current value collected through the ADC interface in real time; The monitored current value is compared with the set safety threshold to determine whether overcurrent protection is triggered; When the current exceeds the limit, the relay is immediately triggered to disconnect the main circuit to prevent equipment damage; It should be noted that the serial port screen used in this step has a good human-computer interaction interface and can display the current output voltage, current value and system status information in real time, such as normal operation, overcurrent protection, etc. The overcurrent protection function is achieved by setting the current threshold and continuously monitoring the output current. Once a current abnormality is detected, the main circuit is immediately cut off to prevent equipment damage caused by short circuit or overload. This mechanism effectively improves the safety and intelligence level of the system.
[0030] This embodiment also provides a computer device, which is suitable for the case of a two-stage cascade-regulated DC regulated power supply method based on microcontroller control, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute computer-executable instructions to implement the two-stage cascade-regulated DC regulated power supply method based on microcontroller control proposed in the above embodiment.
[0031] The computer device may be a terminal, comprising a processor, memory, a communication interface, a display, and an input device connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores an operating system and computer programs. The internal memory provides an environment for the operating system and computer programs stored in the non-volatile storage media. The communication interface of the computer device is used to communicate with external terminals via wired or wireless communication. Wireless communication may be achieved via Wi-Fi, a carrier network, NFC (near-field communication), or other technologies. The display of the computer device may be a liquid crystal display or an electronic ink display. The input device may be a touchscreen overlay on the display, buttons, a trackball, or a touchpad on the computer device housing, or an external keyboard, touchpad, or mouse.
[0032] This embodiment also provides a storage medium having a computer program stored thereon. When the program is executed by a processor, the method for implementing a two-stage cascaded DC regulated power supply based on microcontroller control as proposed in the above embodiment is implemented. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0033] In summary, the present invention achieves preliminary filtering and smoothing of the rectified voltage by connecting capacitors C1 and C4 in parallel at both ends of the pulsating DC voltage Udc1 after rectification, charging when the voltage rises and discharging when it falls, thereby reducing voltage fluctuations and obtaining a smoother DC voltage Udc2. The present invention also achieves efficient primary voltage regulation of the output voltage by inputting the filtered DC voltage Udc2 into a switching power supply module, generating a PWM signal using the XL6009 chip, and dynamically adjusting the duty cycle using a PID algorithm according to the error between the target output voltage Vo and the actual output voltage, and finally obtaining a primary stable DC voltage after LC filtering. The present invention also achieves precise secondary voltage regulation of the output voltage by inputting the primary stable DC voltage into a three-terminal adjustable integrated voltage regulator LM317, and connecting a voltage divider network composed of R1 and R2 between its output terminal and the adjustment terminal, and combining the internal reference voltage 1.25V to achieve continuous adjustment of the output voltage in the range of 2.5V~20V.
[0034] 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 the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A two-stage cascade-regulated DC regulated power supply method based on microcontroller control, characterized in that: include: A step-down transformer is used to convert AC mains power into a secondary output AC voltage, which is then converted into a pulsating DC voltage via a rectifier bridge; Use parallel filter capacitors to filter the pulsating DC voltage to reduce voltage fluctuations and obtain a smooth DC voltage; The smooth DC voltage is input to the switching power supply module, and the working state of the switch tube is adjusted using the PWM control method to adjust the output voltage and obtain the primary stable DC voltage; The three-terminal adjustable integrated voltage regulator LM317 is used in combination with a voltage divider network to regulate and stabilize the primary DC voltage, ensuring that the output voltage is continuously adjustable within the range of 2.5V to 20V. The STM32F4 series microcontroller is used as the control core. The output voltage and current data are collected through the ADC interface, and the PID algorithm is applied to calculate the required adjustment parameters, thereby adjusting the PWM duty cycle to optimize the output voltage stability. Use the relay switching circuit to connect different load resistors and measure the output voltage changes and ripple size under different load conditions; The serial port screen displays the current output voltage, current value and system status information in real time, and provides overcurrent protection function, which automatically cuts off the main circuit when the current exceeds the limit.
2. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 1, characterized in that: The step-down transformer is used to convert the AC mains power into a secondary output AC voltage, and then the secondary output AC voltage is converted into a pulsating DC voltage through a rectifier bridge. The specific steps are as follows: A step-down transformer is used to reduce the voltage of the input 220V AC mains power; Calculate the secondary output AC voltage based on the transformer turns ratio; Assume the number of turns of the primary winding is , the number of turns of the secondary winding is ; Calculate the secondary output voltage using the expression: ; in, is the primary voltage value; The rectifier bridge D1 is used to rectify the secondary output AC voltage Uac; When the AC voltage is in the positive half cycle, diodes D1 and D3 in the rectifier bridge are turned on, and current flows through the load from top to bottom; When the AC voltage is in the negative half cycle, diodes D2 and D4 are turned on, and the current still flows from top to bottom; Through the action of the rectifier bridge, the original bidirectional AC voltage is converted into a unidirectional pulsating DC voltage Udc1.
3. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 2, characterized in that: The parallel filter capacitor is used to filter the pulsating DC voltage to reduce voltage fluctuations and obtain a smooth DC voltage. The specific steps are as follows: Connect capacitors C1 and C4 in parallel across the rectified pulsating DC voltage Udc1; When the voltage increases, the capacitor charges and stores energy; When the voltage drops, the capacitor releases energy to replenish the reduced voltage; Assume the capacitor capacity is , the load resistance is , then the capacitor charging and discharging time constant is Determines the smoothness of voltage fluctuations and obtains a smoother DC voltage Udc2.
4. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 3, characterized in that: The smoothed DC voltage is input to the switching power supply module, and the working state of the switch tube is adjusted using the PWM control method to adjust the output voltage and obtain the primary stable DC voltage. The specific steps are as follows: The smooth DC voltage Udc2 obtained by processing through the step-down transformer and the rectifier filter circuit is used as the input voltage of the switching power supply module; The XL6009 chip integrated in the switching power supply module generates a PWM signal through the internal PWM controller according to the set target output voltage Vo requirement; Assume the target output voltage is , the input voltage is , calculate the PWM duty cycle , the expression is: ; And obtain the primary stable DC voltage Vsw1; A feedback loop is set inside the switching power supply module to monitor the primary stable DC voltage Vsw1 in real time and compare it with the preset target output voltage. Make comparisons; Assume the current output voltage error is ,in ; Proportional term ,in is the proportional gain coefficient; Integral Item ,in is the integral gain coefficient, is the sum of the errors of all sampling points from the beginning to now; differential term ,in is the differential gain coefficient, is the error value of the last sampling, is the time interval between two samples; The total adjustment is ; Update PWM duty cycle , ensuring that the output voltage reaches and maintains the predetermined value, obtaining a more accurate primary stable DC voltage ; The primary stable DC voltage after PWM modulation Input to the inductor and capacitors In the LC filter composed of; Assume the inductance is , the capacitance value is , then the time constant of the filter is Determines its ability to suppress high-frequency ripple and obtain the final stable primary DC voltage .
5. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 4, characterized in that: The three-terminal adjustable integrated voltage regulator LM317 is used in combination with a voltage divider network to regulate and stabilize the primary stable DC voltage to ensure that the output voltage is continuously adjustable within the range of 2.5V to 20V. The specific steps are as follows: Use the three-terminal adjustable integrated voltage regulator LM317 to stabilize the primary DC voltage For further adjustment, the LM317 adjusts the output voltage through an internal reference voltage and an external resistor divider network; Connect a resistor R1 between the output terminal and the adjustment terminal of LM317, and connect another resistor R2 between the adjustment terminal and ground to form a voltage divider network. Assuming the resistance value of R1 is R1 and the resistance value of R2 is R2, calculate the output voltage according to the formula: ; in, The internal reference voltage of LM317 is 1.25V; According to the required target output voltage , use the above formula to reversely calculate the appropriate resistance values of R1 and R2; The primary stabilized DC voltage Input to the input of LM317, and change the output voltage by adjusting the resistance ratio of R1 and R2 ; Capacitors C2 and C3 are connected in parallel at the input and output of LM317 respectively to filter out high-frequency noise and ripple to improve the stability and quality of the output voltage. Assume that the capacity of C2 is C2 and the capacity of C3 is C3, then the selection of capacitors should take into account the load current and frequency response.
6. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 5, characterized in that: The STM32F4 series microcontroller is used as the control core, the output voltage and current data are collected through the ADC interface, and the PID algorithm is applied to calculate the required adjustment parameters, thereby adjusting the PWM duty cycle to optimize the output voltage stability. The specific steps are as follows: The STM32F4 series microcontroller is used as the control core of the entire system. The STM32F4 series microcontroller has powerful processing capabilities and rich peripheral resources; The built-in ADC interface of the STM32F4 microcontroller is used to adjust the output voltage after LM317 and current Conduct real-time collection; Assume the target output voltage is The actual measured output voltage is ; Compare the collected output voltage data with the preset target output voltage and calculate the current output voltage error , the expression is: ; The PID algorithm is used to calculate the error To process, first calculate the proportional term ; Assume the proportional gain coefficient is , then the proportional term P is calculated as: ; The PID algorithm is used to calculate the error Process and calculate the integral term ; Assume the integral gain coefficient is , cumulative error The sum of the errors of all sampling points from the beginning to now; The PID algorithm is used to calculate the error Process and calculate the differential term ; Assume the differential gain coefficient is , the error value of the last sampling is The time interval between two samples is ; Comprehensive proportion item , integral item and the differential term , calculate the total adjustment ; According to the adjustment amount Update the current PWM duty cycle ; The updated PWM duty cycle The XL6009 chip used in the switching power supply module can precisely adjust the output voltage by adjusting the working state of the switching tube.
7. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 6, characterized in that: The relay switching circuit is used to connect different load resistors and measure the change of output voltage and ripple size under different load conditions. The specific steps are as follows: Adopt relay switching circuit to automatically switch to load resistors of different resistance values according to preset programs or user instructions; Use the STM32F4 series microcontroller to control the relay switching circuit through the GPIO pin and select the appropriate load resistor; Under the selected load resistance, the ADC interface of the STM32F4 microcontroller is used to collect the current output voltage and current data in real time; According to the collected output voltage data, calculate the output voltage change under each load resistance ; Use an oscilloscope to measure the ripple voltage under each load resistor; The measured output voltage change The ripple voltage is stored in the memory of the STM32F4 microcontroller and the data is displayed in real time through the serial port screen; Determine the output voltage change under each load resistance based on the measurement results Whether the ripple voltage meets the technical requirements; If the measurement results do not meet the technical requirements, adjust the PID parameters and retest; Repeat the above steps, including relay switching, data acquisition, calculation, measurement, display and judgment, until the output voltage variation and ripple voltage under all load resistances meet the technical index requirements.
8. The two-stage cascade-regulated DC regulated power supply method based on microcontroller control according to claim 7, characterized in that: The serial port screen displays the current output voltage, current value and system status information in real time, and provides overcurrent protection function, which automatically cuts off the main circuit when the current exceeds the limit. The specific steps are as follows: The output voltage and current regulated by LM317 are collected in real time using the built-in ADC interface of the STM32F4 series microcontroller. Format the collected output voltage and current data into information suitable for display; Receive data from the STM32F4 microcontroller through the serial port screen and present it visually to the user; Set the safety threshold for overcurrent protection and monitor the current value collected through the ADC interface in real time; The monitored current value is compared with the set safety threshold to determine whether overcurrent protection is triggered; When the current exceeds the limit, the relay is triggered immediately to disconnect the main circuit to prevent equipment damage.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the two-stage cascaded DC regulated power supply method based on microcontroller control are implemented as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the two-stage cascaded DC regulated power supply method based on microcontroller control according to any one of claims 1 to 8 are implemented.