Share this

Design and Implementation of CNC DC Current Source

2026-04-06 05:09:46 · · #1
Abstract: This paper uses the SPCE061A microcontroller as the main control component of a digitally controlled DC current source. Through ingenious software design and simple and reliable hardware circuitry, it achieves functions such as preset output current, step adjustment, direct display of output current signal, and voice prompts. The system adopts a closed-loop control scheme, sampling and feeding back the actual output current value through a precision resistor, and correcting the actual output value through a PID algorithm, thereby improving the output accuracy and stability of the current source. Keywords: SPCE061A microcontroller; DC current source; feedback; PID regulation DC current sources with good stability, high accuracy, and preset output are frequently used in electronic devices. The digitally controlled DC current source designed in this paper can effectively reduce output errors caused by component aging, temperature drift, etc. The output current is adjustable from 20mA to 2000mA, and the output current is preset, with "+" and "-" step adjustment, direct display of output current signal, and voice prompts. The hardware circuit uses the Sunplus SPCE061A microcontroller as the control core, employing closed-loop control principles and a feedback circuit to form a closed loop. The software primarily utilizes a PID algorithm to achieve precise control of the output current. This system boasts high reliability, small size, simple and convenient operation, and a user-friendly interface. Figure 1 shows the basic block diagram of the digitally controlled DC current source and the system hardware implementation scheme. This design uses a microcontroller as the main control component. The output current value is preset via a keyboard and displayed in real-time using an LCD module. The entire system hardware consists of a microcontroller, voltage-to-current converter, keyboard, display, DC regulated power supply, and voice prompts. The system block diagram is shown in Figure 1. The microcontroller is the core of the entire system, responsible for its operation. To simplify the hardware circuit, ensure stable and reliable system performance, and facilitate the coordination of functions such as voice broadcasting, keyboard settings, and real-time information display, after evaluating various options, the Sunplus SPCE061A microcontroller was selected. This microcontroller integrates ADC, DAC, PLL, AGC, DTMF, and LCD-Driver circuits (depending on the IC model). It adopts a Reduced Instruction Set Computing (RISC) architecture, with instruction cycles measured in CPU clock cycles. Additionally, it incorporates DSP functionality, featuring a built-in 16-bit hardware multiplier and adder, and is equipped with special DSP instructions, significantly accelerating the execution speed of various algorithms. Furthermore, it can utilize the Sunplus Microcontroller Application Development Tool in a Windows environment. This tool supports standard C language and Sunplus Microcontroller assembly language, integrating assembly, programming, and simulation functions, greatly accelerating the software development process. Using this microcontroller as a controller is suitable; with a simple hardware circuit, it easily implements functions such as A/D and D/A conversion, voice prompts, and PID calculations. Figure 2 shows the V/I conversion circuit diagram. The display module primarily displays the set current output value and other human-machine interaction information. While a seven-segment LED display could be used to display numbers, simple letters, and decimal points, its limited information display and unfriendly human-machine interaction necessitate the use of the LCDSMC1602A character-type liquid crystal display module. This module boasts advantages such as being lightweight, thin, compact, low-voltage, low-power, small in size, radiation-free, providing a flat, right-angle display with stable, flicker-free images. It also offers a large viewable area, excellent surface quality, high resolution, and strong anti-interference capabilities, making it suitable for displaying letters, numbers, symbols, and other information. Furthermore, it requires minimal external circuitry and can be directly controlled and displayed by a microcontroller. The voltage-to-current conversion module consists of a precision operational amplifier and a Darlington transistor circuit composed of three transistors. The conversion circuit utilizes the flat output characteristics of the transistors and a deep negative feedback circuit to stabilize the output current, as shown in Figure 2. This V/I conversion circuit has strong load-carrying capacity, with a current output range of 0–3A. The output current Io passes through the feedback resistor Rf to obtain a feedback voltage Vf, where Vf = V11 - V12. This feedback voltage is applied to the two input terminals of the operational amplifier via R5 and R6. Let the voltages across the operational amplifier be V1 and V2, respectively. Vi is output by the microcontroller's DAC. Since the input current of an ideal op-amp is approximately zero, and V1 = V2, then: V12[1-R6/(R2+R6)>+ViR6/(R2+R6)=V11R1(R1+R6) Since V12 =V11-Vf, then: V11R2/(R2+R6)+(ViR6-VfR2)/(R2+R6)=V11R1/(R1+R5) Let R1=R2=10kW, R5=R6=1kW, then Vf=ViR6/R2=Vi/10 If feedback is not considered for the time being, Io=Vi/(10Rf) It can be seen that the output current is determined by the output voltage Vi and the resistance Rf obtained from the D/A conversion, and the transformation is linear. Rf is made of large-diameter copper wire, and its temperature coefficient is very small (5ppm/℃). The large wire diameter can minimize its temperature effect. The three transistors should be high-power transistors (TIP122) with heat sinks to ensure they operate in the linear region. Figure 3 shows a three-op-amp V/I conversion circuit. Another option for the voltage-to-current conversion module is to use three op-amps to form a variable output current source, as shown in Figure 3. The output current I = Vi/R1. To keep the voltage across R1 constant, differential amplifier IC1b monitors the potential across R1 through emitter follower IC1c. This potential is applied to the inverting input of comparator ICa via pin 7 of IC1b and compared with Vref. The comparator's output changes according to the comparison result until balance is achieved, i.e., Vr1 = Vi. The capacitors in the circuit are used to compensate for the frequency of ICa and reduce the control loop delay. As long as R1 = R2 = R3 = R4 = R5, the circuit performs well, but its load-carrying capacity is weak, and loop delay compensation has a significant impact on circuit stability. Figure 4. System Flowchart. The system keyboard module can be connected independently or in a matrix configuration. This module mainly sets the output current and other information. The DC regulated power supply module powers the entire system, and the voice module provides voice prompts, making the system design more user-friendly. The system has a user-friendly interface. The Sunplus microcontroller integrates ADC, DAC, PLL, AGC, DTMF, and other modules. The voice function can be implemented through software programming without any external circuitry, effectively utilizing system resources. System Operation and Software Flow Based on the above analysis of each module, during operation, the SPCE061A microcontroller converts the preset current to an A/D converter, using the output voltage to drive the V/I conversion circuit. The voltage corresponding to this current is then processed through a closed-loop circuit, converted to an A/D converter by the signal processing circuit, and input into the microcontroller system. The current output is adjusted using a PID algorithm. The entire system workflow is shown in Figure 4. Figure 5. Flowchart of the main program. The system software design is carried out in unSPIDE1.16.1, a microcontroller application development tool for Sunplus 16 microcontrollers. The microcontroller is programmed using Sunplus assembly language and standard C language to realize various functions. It mainly includes: (1) system initialization, including the initialization of each peripheral interface device; (2) keyboard input; (3) D/A and A/D conversion; (4) PID algorithm for current adjustment; (5) voice prompts and current display. The main program flowchart is shown in Figure 5. Figure 6. Flowchart of the IRQ1 interrupt service routine. The A/D conversion part of the program is mainly used to convert the analog voltage signal collected by the sampling resistor into a digital signal. The sampling signal is input by IoA6 and directly sent to the buffer P_ADC_MUX_Data. After the ADC automatic mode is enabled, a start signal will be generated. At this time, RDY=0. The analog voltage of DAC0 is compared with the external sampled analog quantity to find the digital quantity of the external signal analog quantity as soon as possible. The result of the A/D conversion is stored in SAR. When the 10-bit A/D conversion is complete, RDY=1. At this time, the 10-bit A/D conversion data can be obtained by reading the P_ADC_MUX_Data unit. The flowchart of its IRQ1 interrupt service routine is shown in Figure 6. The PID algorithm is mainly used to correct the deviation between the actual output current value and the set value, and adjust the next output value to make the output closer to the set value and improve accuracy. The specific control process is as follows: the microcontroller reads the actual current Ik from the A/D conversion chip, and then compares it with the set current Is to obtain the deviation value Ek=Is-Ik. Based on the magnitude of Ek, the microcontroller calls the PID formula to calculate the increment ΔIk of the current adjustment, and then calculates the current output current Iq based on the previous D/A conversion output current Iq-1. The formula for calculating Discrete Incremental PID is ΔIk=Kp[(Ek-Ek-1)+K1Ek+KD(Ek-2Ek-1+Ek-2)>=Kp(Ek-Ek-1)+K1'Ek+KD'(Ek-2Ek-1+Ek-2)] where: K1'= Kp*K1, KD'=Kp*KD, Ek is the current error of the current sampling, Ek-1 is the current error of the previous sampling, and Ek-2 is the current error value of the subsequent sampling. Conclusion To test the accuracy and reliability of the system operation, the setpoint and feedback quantities can be tested. The error is within 0.01%, and the operation is stable, achieving the expected purpose. A unique audio playback design has also been added. The use of the Sunplus SPCE061A microcontroller in this system makes the system fully functional, with simple peripheral circuits and accurate output. The software programming adopts a hybrid C and assembly programming approach, combining the advantages of both, enriching programming concepts and demonstrating great superiority.
Read next

CATDOLL 136CM Miho (TPE Body with Hard Silicone Head)

Height: 136cm Weight: 23.3kg Shoulder Width: 31cm Bust/Waist/Hip: 60/54/68cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22