A dual-channel numerical control power supply system based on STM32 and a dual-channel numerical control method thereof
Patent Information
- Application Number
- CN202610717262.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-22
- Publication Date
- 2026-08-21
AI Technical Summary
[0004]鉴于上述现有技术的不足之处,本发明的目的在于提供一种基于STM32的双路数控电源系统及其双路数控方法,旨在解决现有的数控电源采用单一拓扑结构,难以兼顾电源效率和波纹大的问题
双主控模块由STM32F407与STM32G474构成,通过UART串口实现数据同步。F407负责交互与通信,G474负责功率闭环与保护,实现控制实时性与操作流畅性兼顾。
Smart Images

Figure CN122620971A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of dual-channel CNC power supply technology, and in particular to a dual-channel CNC power supply system based on STM32 and its dual-channel CNC method. Background Technology
[0002] Adjustable DC regulated power supplies are core equipment for electronic teaching, research and development debugging, and laboratory testing. Existing CNC power supplies generally suffer from the following problems: 1. The use of a single MCU architecture often leads to resource conflicts between real-time control and human-computer interaction tasks, resulting in interface lag and slow response. 2. Most of them use a single topology. Switching power supplies have high efficiency but large ripple, while linear power supplies have small ripple but low efficiency, making it difficult to achieve both. 3. Insufficient sampling accuracy, simple control algorithm, large overshoot and poor stability when load changes suddenly; 4. The protection mechanism is inadequate, lacking multi-level linkage protection such as overvoltage, overcurrent, overheating, and reverse connection protection; 5. The interaction method is limited, and there is a lack of remote monitoring and data traceability capabilities.
[0003] Therefore, existing technologies still need to be improved and enhanced. Summary of the Invention
[0004] In view of the shortcomings of the prior art, the purpose of this invention is to provide a dual-channel CNC power supply system based on STM32 and its dual-channel CNC method, which aims to solve the problem that the existing CNC power supply adopts a single topology structure and it is difficult to balance power efficiency and large ripple.
[0005] To achieve the above objectives, the present invention adopts the following technical solution: Firstly, a dual-channel CNC power supply system based on STM32 and its dual-channel CNC method are disclosed. The dual-channel CNC power supply system includes a dual main control module, a dual-channel independent power output module, a high-precision sampling module, a human-machine interaction module, and a protection module. The dual main control module consists of two ARM architecture microcontrollers, an STM32F407 and an STM32G474, which are interconnected via an asynchronous serial port. The dual-channel independent power output module adopts a synchronous BUCK step-down circuit and a linear voltage regulator circuit, which are connected in parallel to the STM32G474. The high-precision sampling module is connected to both the dual-channel power output module and the dual main control module. The human-machine interaction module is connected to the STM32F407. The protection module is connected in parallel to both the dual main control module and the power output module.
[0006] Furthermore, the dual-master control module includes an STM32F407 master control chip and an STM32G474 master control chip; the TX and RX pins of the STM32F407 master control chip are electrically connected to the RX and TX pins of the STM32G474 respectively to realize serial communication connection; the peripheral interface of the STM32F407 master control chip is connected to the human-machine interaction module, and the peripheral interface of the STM32G474 master control chip is connected to the dual-channel independent power output module, the high-precision sampling module, and the protection module.
[0007] Furthermore, the synchronous buck converter circuit includes a driver chip IR2104, MOSFETs Q1 and Q2, inductor L1, diodes D4 and D5, electrolytic capacitors C8, C13, C14, and C5, and filter capacitors C4 and C11. The DC input voltage VIN terminal is connected to one end of electrolytic capacitors C8, C13, C14, and C5, while the other ends of capacitors C8, C13, C14, and C5 are grounded. The DC input voltage VIN terminal is also connected to the drain of MOSFET Q2, and the source of MOSFET Q2 is grounded. The HIN pin of the driver chip IR2104... The two complementary PWM pins of the STM32G474 are connected to the LIN pin; the HO pin of the driver chip IR2104 is connected to the gate of MOSFET Q1 via resistor R5, and the LO pin of the driver chip IR2104 is electrically connected to the gate of MOSFET Q2; the source of MOSFET Q1 and the drain of MOSFET Q2 are shorted and connected to one end of inductor L1; the other end of inductor L1 serves as the output VOUT and is connected to the cathodes of diodes D4 and D5, while the anodes of diodes D4 and D5 are grounded; filter capacitors C4 and C11 are connected in parallel at the output VOUT terminal, and the other ends of filter capacitors C4 and C11 are grounded together.
[0008] Furthermore, the linear regulator circuit includes an operational amplifier U5.1, a power transistor TIP122G, resistors R1, R2, R3, and R4, and capacitors C1, C2, and C3. The non-inverting input of operational amplifier U5.1 is connected to the DAC pin of the STM32G474. The non-inverting output of operational amplifier U5.1 is grounded via resistor R2, and resistor R1 is connected in parallel between the non-inverting output and the output of operational amplifier U5.1. The output of operational amplifier U5.1 is connected to the base of power transistor TIP122G via resistor R4. One end of capacitor C1 is connected to the output of operational amplifier U5.1, and the other end of capacitor C1 is grounded. The collector of power transistor TIP122G is connected to the input voltage DAC_IN, and the emitter of power transistor TIP122G is grounded via resistor R3 and has a linear output terminal OUT connected in parallel. Capacitors C2 and C3 are connected in parallel with resistor R3.
[0009] Furthermore, the high-precision sampling module consists of a voltage sampling circuit and a current sampling circuit connected in parallel. The voltage sampling circuit includes a dual-channel operational amplifier OPA2188, voltage divider resistors R11 and R12, resistor R13, resistor R14, filter capacitors C6 and C7, and diode D1. The input voltage IN+ is connected to pin 3 IN1+ of the dual-channel operational amplifier OPA2188 via resistor R11. The connection point between resistor R11 and pin 3 of the dual-channel operational amplifier OPA2188 is also connected to one end of resistor R12, and the other end of resistor R12 is grounded. One end of resistor R13 is grounded. The other end is connected to pin 2 IN1- of the dual-channel operational amplifier OPA2188 and one end of resistor R14. Pin 1 OUT1 of the dual-channel operational amplifier OPA2188 is connected to the other end of resistor R14. Pin 8 VCC of the dual-channel operational amplifier OPA2188 is connected to a +5V power supply. This power supply node is also connected to a filter capacitor group composed of capacitors C6 and C7. The other ends of capacitors C6 and C7 are grounded together. This power supply node is also connected to one end of diode D1. The other end of diode D1 is connected to the ADC_A6 signal terminal. The ADC_A6 signal terminal is also grounded.
[0010] Furthermore, the high-precision sampling module consists of a voltage sampling circuit and a current sampling circuit connected in parallel. The current sampling circuit includes a current detection amplifier INA213, sampling resistors R15 and R16, gain configuration resistors R17 and R18, filter capacitors C8, C9, C10, C11, and C12, and a clamping diode D2. Sampling resistors R15 and R16 are connected in series. The dual-channel independent power output module is connected in series at the node of the series connection of sampling resistors R15 and R16. Sampling resistor R16 is connected to the +IN pin of the current detection amplifier INA213. R15 is connected to the -IN pin of the current-sense amplifier INA213 via the gain configuration resistor R17; the filter capacitor C11 is connected in parallel with the sampling resistor R15, the sampling resistor R16, and the gain configuration resistor R17; the gain configuration pin of the current-sense amplifier INA213 is connected in parallel with the filter capacitors C8, C9, and C12 to form a filter network; the output of the current-sense amplifier INA213 is connected to the ADC_A7 pin of the main control chip STM32G474 via the gain configuration resistor R18, the filter capacitor C10, and the clamping diode D2; the filter capacitor C10 and the clamping diode D2 are connected in parallel with the gain configuration resistor R18.
[0011] Furthermore, the protection module includes diode D4, relay RLY1, transistor Q2, current-limiting resistors R9 and R10, and LED1. A +5V DC input power supply is simultaneously connected to pin 1 of relay RLY1, the negative terminal of diode D4, and one end of current-limiting resistor R9. The PROTECT protection control pin of the STM32G474 main control chip is connected to the base of transistor Q2 via current-limiting resistor R10. The emitter of transistor Q2 is directly grounded, and its collector is simultaneously connected to the negative terminal of LED1, the positive terminal of diode D4, and pin 4 of relay RLY1. The other end of current-limiting resistor R9 is connected to the positive terminal of LED1, forming a relay operating status indication branch. Pin 2 of relay RLY1 is the common contact terminal, connected to a high-precision sampling module. Pin 3 of relay RLY1 is connected to the IN+ input signal terminal, and pin 5 of relay RLY1 is connected to the DAC_IN+ DAC voltage input signal terminal.
[0012] Secondly, a dual-channel numerical control method based on STM32, employing a dual-channel numerical control power supply system, the dual-channel numerical control method comprising: Step 1: Signal acquisition and preprocessing. The real-time voltage at the power output terminal is sampled by the high-precision sampling module and sent to the ADC pin of the main control chip STM32G474 to complete the conversion from analog signal to digital signal. At the same time, the Kalman filter method is used to obtain a stable and reliable voltage feedback value. Step 2: Control algorithm calculation. Based on the acquired voltage feedback value and the preset target voltage, the STM32G474 performs closed-loop regulation through a feedforward + PID composite control algorithm to calculate the correction amount of the PWM duty cycle. Finally, it outputs the regulated PWM control signal to drive the main power supply circuit, so that the output voltage is stabilized near the target value. Through the communication connection between the STM32F407 and the human-machine interaction module, independent voltage regulation control of the dual power supplies is realized.
[0013] Further, in step 2, the STM32G474 adjusts the voltage based on the acquired voltage feedback value and the preset target voltage through the synchronous BUCK buck circuit and linear regulator circuit of the dual independent power output module. The synchronous BUCK buck circuit uses a feedforward + PID composite control algorithm for adjustment, including: The feedforward section is based on the input voltage With target voltage The estimated open-loop duty cycle is expressed as: ; The PID controller is used to correct for load disturbances, parameter drift, and modeling errors. The final output duty cycle is the sum of the feedforward duty cycle and the PID output, expressed as: ; In the formula: This refers to the feedforward duty cycle; To output the target voltage; Input voltage to the module; This is the final output duty cycle; This is the output of the PID controller.
[0014] Further, in step 2, the STM32G474 adjusts the voltage based on the acquired voltage feedback value and the preset target voltage through the synchronous BUCK buck circuit and linear regulator circuit of the dual independent power output module. The linear regulator circuit uses a feedforward + PID composite control algorithm for adjustment, including: The feedforward section directly proportionals the target voltage. Converted to DAC estimate, it is expressed as: ; The PID section only compensates for minor static errors. The output is superimposed on the feedforward value, and the final DAC output value is expressed as: ; In the formula: This is the output value of the feedforward DAC; This is the feedforward scaling factor; To output the target voltage; This is the final DAC output value, which has no unit. This is the output of the PID controller.
[0015] The technical solution adopted in this invention has the following beneficial effects: The dual-master control module consists of an STM32F407 and an STM32G474, which synchronize data via a UART serial port. The F407 is responsible for interaction and communication, while the G474 is responsible for power closed-loop control and protection, achieving a balance between real-time control and smooth operation.
[0016] The dual-channel independent power output module is divided into channel one and channel two: Channel 1 is a synchronous BUCK step-down circuit, achieving a high-efficiency output of 0~19.4V / 0~5A with an efficiency >90%; Channel 2 is a linear voltage regulator circuit that achieves low-noise output of 0~18.8V / 0~2A with ripple <5mV.
[0017] The high-precision sampling module consists of a voltage divider network, a high-precision operational amplifier, and a current sampling chip, providing accurate feedback for closed-loop control.
[0018] The protection module adopts dual hardware and software protection, including overvoltage, overcurrent, overheat, soft start, reverse connection protection, surge suppression, and rapid power-off under abnormal operating conditions.
[0019] The control algorithm employs PID control with feedforward compensation, combined with Kalman filtering, to improve dynamic response and steady-state accuracy. The system supports both local touchscreen control and remote host computer control, meeting the needs of intelligent testing.
[0020] Dual-core collaboration: Separating control and interaction tasks, resulting in fast system response and no lag; Dual topology output: one high-efficiency, high-power output and one precision, low-noise output, one machine for two uses; High-precision sampling: voltage error < 0.05%, current error < 0.06%; Composite algorithm: feedforward + PID, fast step response, no overshoot, and high stability; Comprehensive protection: Multi-level hardware and software protection ensures safe and reliable operation; Dual-mode control: local + remote, adaptable to multiple scenarios such as teaching, research and development, and laboratories. Attached Figure Description
[0021] Figure 1 This is a diagram of the dual-channel CNC power supply system architecture based on STM32 dual-core collaboration of the present invention; Figure 2 This is a schematic diagram illustrating the working principle of the dual-core collaborative and dual-path independent output of the present invention; Figure 3 This is a schematic diagram of the BUCK synchronous buck converter topology circuit of the present invention; Figure 4 This is a PCB layout diagram of the BUCK power circuit of this invention. Figure 5 This is the schematic diagram of the linear voltage regulator (DAC + op-amp) circuit of the present invention; Figure 6 This is a measured waveform of the sinusoidal wave output by the linear voltage regulator module of this invention. Figure 7 This is a PCB layout diagram of the linear voltage regulator module of the present invention; Figure 8 This is a schematic diagram of the high-precision voltage sampling circuit of the present invention; Figure 9 This is a schematic diagram of the high-precision current sampling circuit of the present invention; Figure 10 This is a schematic diagram of the multi-level hardware and software protection circuit of the present invention; Figure 11 This is a flowchart of the software process for the CNC power supply system of the present invention; Figure 12 This is a measured waveform of the 10V output ripple of the BUCK switch channel in this invention. Figure 13 The above is a measured waveform diagram of the output voltage and ripple of the linear voltage regulator module of this invention. Figure 14This is a diagram showing the host computer monitoring operation interface and waveform following display effect of the present invention; Figure 15 This is a comparison waveform of voltage acquisition before and after Kalman filtering in this invention; Figure 16 This is a measured waveform of the 8V to 15V step response of the linear voltage regulator module of this invention; Figure 17 This is a waveform diagram of the stable output during power-on startup of the BUCK step-down circuit of this invention. Detailed Implementation
[0022] The present invention will now be described in further detail with reference to the accompanying drawings.
[0023] 1. System Overall Architecture The dual-channel CNC power supply based on STM32 described in this invention, combined with Figure 1 and Figure 2 The overall architecture adopts a dual-main-control collaborative + dual-channel independent output architecture, mainly composed of dual main-control modules, dual-channel independent power output modules, high-precision sampling modules, human-machine interaction modules, communication modules and protection modules.
[0024] A dual-channel CNC power supply system based on STM32 and its dual-channel CNC method are disclosed. The dual-channel CNC power supply system includes dual main control modules, dual independent power output modules, a high-precision sampling module, a human-machine interaction module, and a protection module. The dual main control modules consist of two ARM architecture microcontrollers, STM32F407 and STM32G474. The STM32F407 and STM32G474 are interconnected via an asynchronous serial port. The two microcontrollers perform high-speed data interaction and instruction coordination through an asynchronous serial port UART, forming a dual-core division of labor and scheduling architecture. The dual-channel independent power output module adopts a synchronous BUCK step-down circuit and a linear regulator circuit. The synchronous BUCK step-down circuit and the linear regulator circuit are connected in parallel to the STM32G474. The two power supply channels are electrically isolated, independently controlled, and do not interfere with each other. They can output different voltage and current settings at the same time to meet the requirements of high-efficiency power supply and low-noise power supply respectively. The high-precision sampling module is connected to the dual-channel power output module and the dual main control module respectively. It is used to collect output voltage and output current in real time, amplify signals, isolate impedance and filter noise, and feed the sampling results back to the control core to form a closed-loop control circuit. The human-machine interface module is connected to the STM32F407, and the protection module is connected in parallel to the dual main control module and the power output module. It adopts a combination of hardware forced protection and software hierarchical protection to achieve multi-dimensional safety protection against overvoltage, overcurrent, overheating, reverse connection, surge, and power-on impact.
[0025] The human-machine interface module includes a local touchscreen, encoder, or remote host computer. Users set target parameters such as output voltage and current through the local touchscreen, encoder, or remote host computer. After the parameters are parsed by the dual main control modules, they are sent to the two power output units respectively. The output voltage and current are collected, filtered, and calibrated in real time by the high-precision sampling module and then fed back to the power control unit. The control unit uses a PID + feedforward composite algorithm to adjust the output in real time. At the same time, the protection module monitors and provides rapid protection against abnormal states such as overvoltage, overcurrent, overheating, and reverse connection in real time. The system transmits the output status and waveform data back to the human-machine interface unit to achieve real-time display both locally and remotely, forming a complete closed-loop control system.
[0026] 2. Dual main control modules In this embodiment, the dual-master control module adopts a dual-core collaborative architecture of STM32F407 + STM32G474. The two MCUs achieve high-speed data interaction and instruction synchronization through UART serial port. The specific division of labor is as follows: STM32F407: As the main controller for interaction and communication, it is responsible for touch screen driving, button and encoder signal acquisition, host computer communication, parameter power-down storage, data parsing and waveform display, and undertakes non-real-time tasks to ensure smooth operation and no interface lag.
[0027] STM32G474: As the main controller for power and protection, it is responsible for high-frequency PWM generation, DAC output control, high-precision ADC acquisition, PID and feedforward compensation calculation, and execution of multi-level protection logic. It undertakes high real-time control tasks and improves dynamic response speed and output stability.
[0028] The dual-chip architecture, with its division of labor and collaboration, completely resolves the issues of resource conflicts and system response delays associated with real-time control and human-computer interaction in a single-chip architecture.
[0029] In this embodiment, the dual-master control module includes an STM32F407 master control chip and an STM32G474 master control chip. The TX and RX pins of the STM32F407 master control chip are electrically connected to the RX and TX pins of the STM32G474 respectively to achieve serial communication connection. The peripheral interface of the STM32F407 master control chip is connected to the human-machine interaction module, and the peripheral interface of the STM32G474 master control chip is connected to the dual-channel independent power output module, the high-precision sampling module, and the protection module to achieve serial communication connection. The peripheral interface of the STM32F407 is electrically connected to the touch screen, buttons, and host computer interface, and the peripheral interface of the STM32G474 is electrically connected to each power module and the sampling module.
[0030] 3. Dual-channel independent power output module The system is equipped with two independent and non-interfering power output channels, which adopt synchronous BUCK buck topology and linear regulated topology respectively, balancing high efficiency and low noise.
[0031] 3.1 Channel 1: Synchronous BUCK Buck Circuit Channel 1 adopts a synchronous BUCK buck topology, mainly composed of an IR2104 driver chip, an IRF3205 power MOSFET, a power inductor, a high-frequency filter capacitor, and a freewheeling diode.
[0032] The STM32G474 outputs a high-frequency PWM signal, which is converted into a complementary drive waveform by the IR2104 to control the high-speed switching of the MOSFET, thereby achieving chopping, filtering, and voltage regulation of the input voltage. Combined with... Figure 12 By adjusting the PWM duty cycle, it can achieve a continuously adjustable output of 0~19.4V, a maximum output current of 5A, a conversion efficiency of more than 90%, and an output ripple of less than 80mV. It is suitable for high-efficiency power supply scenarios such as digital circuits, motor drives, and high-power loads.
[0033] In this embodiment, combined with Figure 3 and Figure 4 The synchronous buck converter circuit includes a driver chip IR2104, MOSFETs Q1 and Q2, inductor L1, diodes D4 and D5, electrolytic capacitors C8, C13, C14, and C5, and filter capacitors C4 and C11. The DC input voltage VIN terminal is connected to one end of electrolytic capacitors C8, C13, C14, and C5, while the other ends of C8, C13, C14, and C5 are grounded. The DC input voltage VIN terminal is also connected to the drain of MOSFET Q2, and the source of MOSFET Q2 is grounded. The HIN pin of the driver chip IR2104 is connected to L1. The IN pin connects to the two complementary PWM pins of the STM32G474; the HO pin of the driver chip IR2104 is connected to the gate of MOSFET Q1 via resistor R5, and the LO pin of the driver chip IR2104 is electrically connected to the gate of MOSFET Q2; the source of MOSFET Q1 and the drain of MOSFET Q2 are shorted and connected to one end of inductor L1; the other end of inductor L1 serves as the output VOUT and is connected to the cathodes of diodes D4 and D5, while the anodes of diodes D4 and D5 are grounded; filter capacitors C4 and C11 are connected in parallel at the output VOUT terminal, and the other ends of filter capacitors C4 and C11 are grounded together.
[0034] 3.2 Channel Two: Linear Voltage Regulator Circuit Channel 2 adopts a DAC + high-precision operational amplifier + power transistor linear regulator architecture. The STM32G474 built-in DAC outputs a 0~3.3V reference voltage, which is then passed through a high-precision operational amplifier to form an error amplification loop, driving the TIP122 power transistor to operate in the linear amplification region, thereby achieving low-noise DC regulated output.
[0035] Combination Figure 6 and Figure 13 This channel has no switching action, extremely low electromagnetic interference, continuously adjustable output voltage from 0 to 18.8V, maximum output current of 2A, output ripple of less than 5mV, and voltage control error of less than ±0.05%, meeting the power supply requirements of noise-sensitive loads such as precision analog circuits, sensors, and RF modules. Simultaneously, this channel can be switched to a simple low-frequency signal generator via a DAC output waveform, outputting a peak-to-peak 13V, 2kHz sine wave signal.
[0036] In this embodiment, combined with Figure 4 and Figure 7 The linear regulator circuit includes an operational amplifier U5.1, a power transistor TIP122G, resistors R1, R2, R3, and R4, and capacitors C1, C2, and C3. The non-inverting input of operational amplifier U5.1 is connected to the DAC pin of the STM32G474. The non-inverting output of operational amplifier U5.1 is grounded through resistor R2. Resistor R1 is connected in parallel between the non-inverting output and the output of operational amplifier U5.1. The output of operational amplifier U5.1 is connected to the base of power transistor TIP122G through resistor R4. One end of capacitor C1 is connected to the output of operational amplifier U5.1, and the other end of capacitor C1 is grounded. The collector of power transistor TIP122G is connected to the input voltage DAC_IN, and the emitter of power transistor TIP122G is grounded through resistor R3 and connected in parallel to the linear output terminal OUT. Capacitors C2 and C3 are connected in parallel to resistor R3.
[0037] 4. High-precision sampling module The high-precision sampling module consists of a voltage sampling unit and a current sampling unit, providing high-precision and high-reliability feedback signals for closed-loop control and protection.
[0038] 4.1 Voltage Sampling Voltage sampling employs a 10:1 precision resistor divider network + OPA2188 voltage follower architecture. The output voltage is reduced to the ADC's compatibility range by the precision resistor divider before being fed into the OPA2188 voltage follower, achieving high impedance isolation and signal buffering to prevent subsequent loads from affecting sampling accuracy. The divided signal is then input to the STM32G474's ADC channel for digital acquisition, with a maximum absolute voltage sampling error of less than 0.05%.
[0039] In this embodiment of the application, combined with Figure 8 The voltage sampling circuit includes an operational amplifier OPA2188, voltage divider resistors R11 and R12, resistor R13, resistor R14, filter capacitors C6 and C7, and clamping diode D1. The input voltage IN+ is connected to pin 3 (IN1+) of the dual-channel operational amplifier OPA2188 via a 10K resistor R11. The connection point between R11 and pin 3 of the OPA2188 is simultaneously connected to one end of a 1K resistor R12, with the other end of R12 grounded. One end of the 10K resistor R13 is grounded, and the other end is simultaneously connected to the OPA2188. Pin 2 IN1 of the OPA2188 is connected to one end of a 1K resistor R14, and pin 1 OUT1 of the OPA2188 is connected to the other end of the 1K resistor R14. Pin 8 VCC of the OPA2188 is connected to a +5V power supply. This power supply node is also connected to a filter capacitor group consisting of a 10uF capacitor C6 and a 100nF capacitor C7. The other ends of C6 and C7 are grounded together. This power supply node is also connected to one end of an SS34 diode D1. The other end of D1 is connected to the ADC_A6 signal terminal, which is also grounded.
[0040] 4.2 Current Sampling The current sampling employs a 10mΩ high-precision sampling resistor + INA213AIDCKR dedicated current sensing amplifier architecture. A low-resistance sampling resistor is connected in series in the output circuit to convert the current signal into a voltage signal, which is then amplified, conditioned, and fed into the ADC channel. This solution is a non-intrusive sampling method with low loss and fast response, enabling high-precision current monitoring within the range of 0~6.6A, with a maximum absolute error of less than 0.06%.
[0041] In this embodiment of the application, combined with Figure 9The current sampling circuit includes a current-sensing amplifier INA213, sampling resistors R15 and R16, gain configuration resistors R17 and R18, filter capacitors C8, C9, C10, C11, and C12, and a clamping diode D2. Sampling resistors R15 and R16 are connected in series. A dual-channel independent power output module is connected in series at the node where sampling resistors R15 and R16 are connected. Sampling resistor R16 is connected to the +IN pin of the current-sensing amplifier INA213, and sampling resistor R15 is connected via the gain configuration resistor R17. The current sensing amplifier INA213 is connected to its -IN pin; filter capacitor C11 is connected in parallel with sampling resistor R15, sampling resistor R16 and gain configuration resistor R17; filter capacitors C8, C9 and C12 are connected in parallel with the gain configuration pin of the current sensing amplifier INA213 to form a filter network; the output of the current sensing amplifier INA213 is connected to the ADC_A7 pin of the main control chip STM32G474 after passing through gain configuration resistor R18, filter capacitor C10 and clamping diode D2; filter capacitor C10 and clamping diode D2 are connected in parallel with gain configuration resistor R18.
[0042] 5. Protection Module The protection module employs a dual mechanism of hardware-based mandatory protection and software-based hierarchical protection to comprehensively enhance the security and reliability of system operation.
[0043] 5.1 Hardware Protection It consists of a relay, an SS34 reverse connection protection diode, a clamping diode, an NTC thermistor, and a surge suppression circuit. When abnormalities such as overvoltage, overcurrent, overheating, or reverse connection occur, the hardware circuit responds quickly, driving the relay to physically disconnect the main power supply circuit, thus achieving forced power-off protection.
[0044] In this embodiment, combined with Figure 10In the hardware protection circuit, the +5V DC input power supply is simultaneously connected to pin 1 of relay RLY1, the negative terminal of freewheeling protection diode D4 (model 1N4148), and one end of 1kΩ current-limiting resistor R9; the PROTECT protection control pin of the main control chip STM32G474 is connected to the base of NPN transistor Q2 (model 9013) through 1kΩ current-limiting resistor R10. The emitter of Q2 is directly grounded, and the collector is simultaneously connected to the negative terminal of LED1, the positive terminal of D4 (1N4148), and pin 4 of relay RLY1; the other end of R9 is connected to the positive terminal of LED1, forming the relay operating status indication branch; pin 2 of relay RLY1 is the common contact terminal, connected to the current acquisition circuit, and pin 3... Pin 3 is a normally closed contact connected to the IN+ input signal terminal, and pin 5 is a normally open contact connected to the DAC_IN+ DAC voltage input signal terminal. When the PROTECT pin outputs a high level, the 9013 transistor is saturated and conducts, the RLY1 coil is energized and closes, the contact switches from pin 3 to pin 5, the circuit switches from IN+ input to DAC_IN+ input, and LED1 is forward-biased and illuminated to indicate the relay's operating status. The 1N4148 diode provides a reverse electromotive force discharge path for the relay coil, preventing the transistor from being broken down by the reverse high voltage of the coil when it is turned off. When the PROTECT pin outputs a low level, the transistor is cut off, the relay coil is de-energized and released, the contact resets to pin 3, the circuit returns to IN+ input, and LED1 turns off synchronously.
[0045] 5.2 Software Protection The STM32G474 monitors the output status in real time, enabling overvoltage, overcurrent, and overheat threshold judgment, graded soft-start control, fault latching, and fault alarm.
[0046] The soft-start mechanism can suppress power-on surges and prevent output overshoot; after the abnormal state is cleared, the system can resume operation manually or automatically, effectively protecting the power supply and downstream load devices.
[0047] Secondly, a dual-channel numerical control method based on STM32, employing a dual-channel numerical control power supply system, combined with... Figure 11 Dual-channel CNC methods include: Step 1: Signal acquisition and preprocessing. The real-time voltage at the power output terminal is sampled by the high-precision sampling module and sent to the ADC pin of the main control chip STM32G474 to complete the conversion from analog signal to digital signal. At the same time, the Kalman filter method is used to obtain a stable and reliable voltage feedback value. Existing dual-channel CNC power supplies generally suffer from drawbacks such as susceptibility of sampling signals to noise interference, lack of predictive components in conventional PID control, difficulty in balancing speed and stability between the two outputs, and lack of adaptive filtering. These drawbacks easily lead to output jitter, response lag, large overshoot, and decreased accuracy. To address these shortcomings, this invention employs a composite control strategy of Kalman filtering + PID + feedforward compensation, improving the overall control performance of the power supply from four aspects: sampling noise reduction, dynamic prediction, error correction, and branch optimization.
[0048] Traditional power supplies often use average filtering or sliding filtering to process ADC sampling signals, which has problems such as large filtering lag and poor noise suppression. Under switching interference, it is easy to cause sampling distortion and reduced control accuracy.
[0049] To improve sampling accuracy and control stability, this invention introduces a Kalman filter algorithm into the voltage and current ADC sampling loops. By constructing system state equations and observation equations, it performs real-time optimal estimation of the sampled signals, effectively filtering out circuit electromagnetic interference, switching noise, and ADC quantization noise. This significantly improves the smoothness and reliability of the feedback signal, providing high-precision and high-reliability feedback for closed-loop control. A comparison of voltage acquisition waveforms before and after Kalman filtering is provided. Figure 14 As shown, the top image is the original sampled waveform without Kalman filtering, which has high noise and obvious fluctuations; the bottom image is the waveform after using Kalman filtering, which has a smooth and stable signal and significantly enhanced anti-interference ability.
[0050] Step 2: Control algorithm calculation. Based on the acquired voltage feedback value and the preset target voltage, the STM32G474 performs closed-loop regulation through a feedforward + PID composite control algorithm to calculate the correction amount of the PWM duty cycle. Finally, it outputs the regulated PWM control signal to drive the main power supply circuit, so that the output voltage is stabilized near the target value. Through the communication connection between the STM32F407 and the human-machine interaction module, independent voltage regulation control of the dual power supplies is realized.
[0051] The system adopts a composite control structure that combines digital PID and input feedforward compensation. Since the controlled object characteristics of the BUCK switching channel and the linear voltage regulation channel are quite different, this invention adopts an appropriate feedforward strategy and PID parameters for the two channels to achieve the optimal control effect.
[0052] Channel 1 (BUCK buck channel) control strategy The BUCK buck channel is a second-order system containing a double pole LC filter. The control challenge lies in suppressing oscillations, reducing overshoot, and improving dynamic response speed.
[0053] The feedforward section is based on the input voltage With target voltage The formula for calculating the estimated open-loop duty cycle is as follows: ; The PID controller is used to correct for load disturbances, parameter drift, and modeling errors. The final output duty cycle is the sum of the feedforward duty cycle and the PID output, calculated as follows: ; After actual debugging and tuning, the PID parameters for this channel are: proportional coefficient Integral coefficient Differential coefficients .
[0054] ; In the formula: This refers to the feedforward duty cycle; To output the target voltage; Input voltage to the module; This is the final output duty cycle; This is the output of the PID controller; This is the proportionality coefficient; The integral coefficient; is the differential coefficient.
[0055] Channel 2 (Linear Regulated Channel) Control Strategy The linear voltage regulator channel employs a linear regulation architecture consisting of a DAC, operational amplifier, and power transistor. The controlled object approximates a first-order system, featuring fast response and no LC oscillation. Traditional open-loop or single PID control is susceptible to load changes, input fluctuations, and temperature drift, making it difficult to meet high-precision power supply requirements.
[0056] This invention employs a proportional feedforward + PID fine-tuning control scheme: the feedforward section directly adjusts the target voltage according to a proportional coefficient. The formula for converting to DAC estimates is as follows: ; The PID section only compensates for minor static errors. The output is superimposed on the feedforward value, and the final DAC output value is calculated using the following formula: ; Based on actual measurements, the feedforward proportional coefficient is adopted. To achieve optimal open-loop prediction performance, the PID parameters for this channel are: proportional coefficient. Integral coefficient Differential coefficients .
[0057] In the formula: This is the output value of the feedforward DAC; This is the feedforward scaling factor; To output the target voltage; This is the final DAC output value, which has no unit. This is the output of the PID controller; This is the proportionality coefficient; The integral coefficient; is the differential coefficient.
[0058] This scheme fully utilizes the linear transfer characteristics of the DAC and power transistor in the linear regulator channel, allowing the PID to operate only within the small error correction range, significantly reducing parameter tuning difficulty while improving dynamic response speed and steady-state control accuracy. Both channels have a control cycle set to 10kHz. Actual test results show that the linear regulator module exhibits a voltage follow-up time of less than 10ms under an 8V to 15V step voltage condition, with no significant overshoot or oscillation. The waveform is as follows... Figure 15 As shown; the BUCK buck circuit exhibits a smooth voltage rise during power-up without overshoot, and the startup waveform is as follows. Figure 16 As shown, the effectiveness of the Kalman filter and composite control algorithm is fully verified.
[0059] like Figure 17 As shown, with the combined effect of Kalman filtering and feedforward compensation, the two channels have faster dynamic response, higher steady-state accuracy, stronger anti-interference ability, and lower output ripple, and can maintain stable output without jitter under input voltage fluctuations and load changes.
[0060] Dual-core collaborative control and remote communication process The control method section mainly describes the closed-loop control and communication process of this dual-channel CNC power supply, which is divided into four stages: data acquisition, processing and calculation, communication interaction, and control output. 1. Signal Acquisition and Preprocessing The real-time voltage at the power output terminal is sampled by the voltage acquisition module and sent to the ADC pin of the STM32G474 main control chip to complete the conversion from analog signal to digital signal. At the same time, combined with hardware filtering and software filtering algorithms, noise interference is eliminated to obtain a stable and reliable voltage feedback value.
[0061] 2. Control algorithm operation Based on the acquired voltage feedback value and the preset target voltage, the STM32G474 performs closed-loop regulation through a feedforward + PID composite control algorithm, calculates the correction amount of the PWM duty cycle, and finally outputs the regulated PWM control signal to drive the main power supply circuit, so that the output voltage is stabilized near the target value, realizing independent voltage regulation control of dual power supplies.
[0062] 3. Multi-core communication and data upload The STM32G474 processes the real-time voltage data and sends it to the STM32F407 chip via the USART serial port. The STM32H7 acts as a communication hub, transmitting the received data to the host computer via Bluetooth, enabling real-time graphical monitoring and status feedback of voltage, current, and waveform.
[0063] 4. Host computer command issuance and remote control After the target voltage is modified on the host computer, the new setting value is wirelessly transmitted to the STM32F407 chip via Bluetooth, and then forwarded by the STM32F407 to the STM32G474 via serial port. After receiving the new target value, the G474 re-executes the feedforward + PID algorithm adjustment, updates the PWM output, and finally realizes the host computer's remote parameter setting and closed-loop control of the dual power supplies.
[0064] In summary, the STM32G474 and STM32F407 work together through stable serial communication: the STM32G474 is responsible for voltage acquisition, filtering, and closed-loop control calculations, while the STM32F407 is responsible for multi-terminal data interaction and communication relay. Together, they complete the complete control process of the dual-channel CNC power supply.
[0065] Human-computer interaction and remote control: The system supports dual-mode operation of local control and remote host computer monitoring, adapting to the needs of multiple scenarios.
[0066] Local control: Dual-channel parameter configuration, output enable, protection threshold setting, waveform mode switching and other operations are realized through touch screen and encoder. The interface response delay is less than 50ms and the interaction is smooth.
[0067] Remote control: Communicates with the host computer via serial port at a baud rate of 115200bps, using custom communication frames and CRC checksums to achieve remote parameter setting, real-time data upload, waveform refresh (100ms refresh rate), and remote emergency stop functions. Communication is stable with no packet loss and no blocking.
[0068] The present invention has also undergone actual testing, and the power supply performance indicators of the present invention after testing are as follows: The output voltage error is less than 0.3%; The linear channel output ripple is less than 5mV, and the BUCK channel output ripple is less than 80mV. BUCK channel conversion efficiency is greater than 90%; The voltage step dynamic response time is less than 10ms, with no overshoot; The local interactive interface response latency is less than 50ms; The anomaly protection response speed reaches the microsecond level, and the operation is reliable.
[0069] This invention achieves high efficiency, low ripple, high precision, and high reliability dual-channel CNC power supply output through a dual-core collaborative architecture, dual-topology independent output, high-precision sampling, composite control algorithms, and multi-level protection mechanisms. The system features a simple structure, strong scalability, and controllable cost. It supports both local and remote dual-mode control and can be widely applied in university teaching and training, electronic R&D debugging, and laboratory precision testing, providing a lightweight and cost-effective domestic solution for mid-range CNC power supplies.
Claims
1. A dual-channel CNC power supply system based on STM32, characterized in that, The dual-channel CNC power supply system includes a dual main control module, a dual-channel independent power output module, a high-precision sampling module, a human-machine interface module, and a protection module. The dual main control module consists of two ARM architecture microcontrollers, an STM32F407 and an STM32G474, which are connected via an asynchronous serial port. The dual-channel independent power output module uses a synchronous BUCK step-down circuit and a linear regulator circuit, which are connected in parallel to the STM32G474. The high-precision sampling module is connected to both the dual-channel power output module and the dual main control module. The human-machine interface module is connected to the STM32F407. The protection module is connected in parallel to both the dual main control module and the power output module.
2. The dual-channel CNC power supply system based on STM32 according to claim 1, characterized in that, The dual-master control module includes an STM32F407 master control chip and an STM32G474 master control chip. The TX and RX pins of the STM32F407 master control chip are electrically connected to the RX and TX pins of the STM32G474 respectively to realize serial communication. The peripheral interface of the STM32F407 master control chip is connected to the human-machine interaction module, and the peripheral interface of the STM32G474 master control chip is connected to the dual-channel independent power output module, the high-precision sampling module, and the protection module.
3. The dual-channel CNC power supply system based on STM32 according to claim 1, characterized in that, The synchronous buck converter circuit includes a driver chip IR2104, MOSFETs Q1 and Q2, inductor L1, diodes D4 and D5, electrolytic capacitors C8, C13, C14, and C5, and filter capacitors C4 and C11. The DC input voltage VIN terminal is connected to one end of electrolytic capacitors C8, C13, C14, and C5, while the other ends of C8, C13, C14, and C5 are grounded. The DC input voltage VIN terminal is also connected to the drain of MOSFET Q2, and the source of MOSFET Q2 is grounded. The HIN pin of the driver chip IR2104 is connected to L1. The N pin connects to the two complementary PWM pins of the STM32G474; the HO pin of the driver chip IR2104 is connected to the gate of MOSFET Q1 via resistor R5, and the LO pin of the driver chip IR2104 is electrically connected to the gate of MOSFET Q2; the source of MOSFET Q1 and the drain of MOSFET Q2 are shorted and connected to one end of inductor L1; the other end of inductor L1 serves as the output VOUT and is connected to the cathodes of diodes D4 and D5, while the anodes of diodes D4 and D5 are grounded; filter capacitors C4 and C11 are connected in parallel at the output VOUT terminal, and the other ends of filter capacitors C4 and C11 are grounded together.
4. The dual-channel CNC power supply system based on STM32 according to claim 1, characterized in that, The linear regulator circuit includes an operational amplifier U5.1, a power transistor TIP122G, resistors R1, R2, R3, and R4, and capacitors C1, C2, and C3. The non-inverting input of operational amplifier U5.1 is connected to the DAC pin of the STM32G474. The non-inverting output of operational amplifier U5.1 is grounded through resistor R2. Resistor R1 is connected in parallel between the non-inverting output and the output of operational amplifier U5.
1. The output of operational amplifier U5.1 is connected to the base of power transistor TIP122G through resistor R4. One end of capacitor C1 is connected to the output of operational amplifier U5.1, and the other end is grounded. The collector of power transistor TIP122G is connected to the input voltage DAC_IN, and the emitter of power transistor TIP122G is grounded through resistor R3 and connected in parallel to the linear output terminal OUT. Capacitors C2 and C3 are connected in parallel to resistor R3.
5. The dual-channel CNC power supply system based on STM32 according to claim 1, characterized in that, The high-precision sampling module consists of a voltage sampling circuit and a current sampling circuit connected in parallel. The voltage sampling circuit includes a dual-channel operational amplifier OPA2188, voltage divider resistors R11 and R12, resistor R13, resistor R14, filter capacitors C6 and C7, and diode D1. The input voltage IN+ is connected to pin 3 (IN1+) of the dual-channel operational amplifier OPA2188 via resistor R11. The connection point between resistor R11 and pin 3 of the dual-channel operational amplifier OPA2188 is simultaneously connected to one end of resistor R12, and the other end of resistor R12 is grounded. One end of resistor R13 is grounded, and the other end... The first pin is connected to pin 2 (IN1-) of the dual-channel operational amplifier OPA2188 and one end of resistor R14. Pin 1 (OUT1) of the dual-channel operational amplifier OPA2188 is connected to the other end of resistor R14. Pin 8 (VCC) of the dual-channel operational amplifier OPA2188 is connected to a +5V power supply. This power supply node is also connected to a filter capacitor group composed of capacitors C6 and C7. The other ends of capacitors C6 and C7 are grounded together. This power supply node is also connected to one end of diode D1. The other end of diode D1 is connected to the ADC_A6 signal terminal, which is also grounded.
6. The dual-channel CNC power supply system based on STM32 according to claim 1, characterized in that, The high-precision sampling module consists of a voltage sampling circuit and a current sampling circuit connected in parallel. The current sampling circuit includes a current-sensing amplifier INA213, sampling resistors R15 and R16, gain configuration resistors R17 and R18, filter capacitors C8, C9, C10, C11, and C12, and a clamping diode D2. Sampling resistors R15 and R16 are connected in series. The dual-channel independent power output module is connected in series at the node where sampling resistors R15 and R16 are connected. Sampling resistor R16 is connected to the +IN pin of the current-sensing amplifier INA213. The current sensing amplifier INA213 is connected to the -IN pin via gain configuration resistor R17; filter capacitor C11 is connected in parallel with sampling resistor R15, sampling resistor R16 and gain configuration resistor R17; filter capacitors C8, C9 and C12 are connected in parallel with the gain configuration pin of the current sensing amplifier INA213 to form a filter network; the output of the current sensing amplifier INA213 is connected to the ADC_A7 pin of the main control chip STM32G474 via gain configuration resistor R18, filter capacitor C10 and clamping diode D2; filter capacitor C10 and clamping diode D2 are connected in parallel with gain configuration resistor R18.
7. The dual-channel CNC power supply system based on STM32 according to claim 1, characterized in that, The protection module includes diode D4, relay RLY1, transistor Q2, current-limiting resistors R9 and R10, and LED1. A +5V DC input power supply is simultaneously connected to pin 1 of relay RLY1, the cathode of diode D4, and one end of current-limiting resistor R9. The PROTECT protection control pin of the STM32G474 main control chip is connected to the base of transistor Q2 via current-limiting resistor R10. The emitter of transistor Q2 is directly grounded, and its collector is connected to the cathode of LED1, the anode of diode D4, and pin 4 of relay RLY1. The other end of current-limiting resistor R9 is connected to the anode of LED1, forming the relay operating status indication branch. Pin 2 of relay RLY1 is the common contact terminal, connected to a high-precision sampling module. Pin 3 of relay RLY1 is connected to the IN+ input signal terminal, and pin 5 of relay RLY1 is connected to the DAC_IN+ DAC voltage input signal terminal.
8. A dual-channel numerical control method based on STM32 using the dual-channel numerical control power supply system as described in claim 1, characterized in that, Dual-channel CNC methods include: Step 1: Signal acquisition and preprocessing. The real-time voltage at the power output terminal is sampled by the high-precision sampling module and sent to the ADC pin of the main control chip STM32G474 to complete the conversion from analog signal to digital signal. At the same time, the Kalman filter method is used to obtain a stable and reliable voltage feedback value. Step 2: Control algorithm calculation. Based on the acquired voltage feedback value and the preset target voltage, the STM32G474 performs closed-loop regulation through a feedforward + PID composite control algorithm to calculate the correction amount of the PWM duty cycle. Finally, it outputs the regulated PWM control signal to drive the main power supply circuit, so that the output voltage is stabilized near the target value. Through the communication connection between the STM32F407 and the human-machine interaction module, independent voltage regulation control of the dual power supplies is realized.
9. The dual-channel numerical control method based on STM32 according to claim 8, characterized in that, In step 2, the STM32G474 adjusts the voltage based on the acquired voltage feedback value and the preset target voltage through the synchronous BUCK buck circuit and linear regulator circuit of the dual independent power output module. The synchronous BUCK buck circuit uses a feedforward + PID composite control algorithm for adjustment, including: The feedforward section is based on the input voltage With target voltage The estimated open-loop duty cycle is calculated as follows: ; The PID controller is used to correct for load disturbances, parameter drift, and modeling errors. The final output duty cycle is the sum of the feedforward duty cycle and the PID output, expressed as: ; In the formula: This refers to the feedforward duty cycle; To output the target voltage; Input voltage to the module; This is for the final output duty cycle; This is the output of the PID controller.
10. The dual-channel CNC method based on STM32 according to claim 8, characterized in that, In step 2, the STM32G474 adjusts the voltage based on the acquired voltage feedback value and the preset target voltage through the synchronous BUCK buck circuit and linear regulator circuit of the dual independent power output module. The linear regulator circuit uses a feedforward + PID composite control algorithm for adjustment, including: The feedforward section directly proportionals the target voltage. Converted to DAC estimate, it is expressed as: ; The PID section only compensates for small static errors. The output is added to the feedforward value, and the final DAC output value is expressed as: ; In the formula: This is the output value of the feedforward DAC; This is the feedforward scaling factor; To output the target voltage; This is the final DAC output value, which has no unit. This is the output of the PID controller.