I. Scheme Demonstration
1. Comparison and Selection
Scheme 1: Connect a MOS tube to the output of the operational amplifier. Using the virtual short principle of the operational amplifier, the microcontroller sets a voltage value to one end of the input end of the operational amplifier. The closed-loop feedback is used to control the voltage value of the output end of the operational amplifier to control the conduction degree of the MOSFET. Control the MOSFET source voltage and then cooperate with the sampling resistor to achieve constant current. The circuit structure is simple, but the implementation function is not perfect.

Figure 1 Scheme 1 Main Topology
Scheme 2: Use a buck-boost chopper circuit. Its basic principle is to connect two universal half-bridge boards in series, connect the same-name ends, and form a full-bridge circuit. Connect a fixed resistor R1 after the buck-boost chopper circuit to form a DC electronic load circuit. Constant current and constant resistance control is achieved through two PWMs. The topology is simple, the control method is simple, the operation is easy, and the stability is high.

Figure 2 Scheme 2 Main Topology
Based on the above demonstration, Scheme 2 is selected, that is, the buck-boost chopper circuit is used.
2. Scheme Description
The system consists of five parts: main circuit module, auxiliary power supply module, measurement module, control module, and display module. The main topology adopts a buck-boost chopper circuit. Its basic principle is to connect two universal half-bridge boards in series, connect the same-name ends, and form a full-bridge circuit. A fixed resistor R1 is connected after the buck-boost chopper circuit to form a DC electronic load circuit. The auxiliary power supply module uses the mc34063 boost circuit to take power from the microcontroller and increase it to 12V to power the sampling circuit and control circuit. The sampling circuit includes voltage sampling and current sampling. The voltage sampling is composed of a voltage divider resistor and the current sampling is composed of an INA282 current detection chip. The control module is based on STM32F103. The sampling voltage and current are obtained through the sampling circuit. The PID algorithm is used for constant current and constant resistance control, and the display module displays in real time. In addition, we added a wireless remote control to change the system mode. The system block diagram is shown in Figure 3.

Figure 3 System block diagram
II. Circuit and program design
1. Main circuit and device selection
The main circuit is composed of a buck-boost chopper circuit and a high-power fixed resistor. A fixed resistor R1 is connected after the buck-boost chopper circuit to form a DC electronic load circuit. The system can work stably in two modes, namely constant current mode (CC) and constant resistance mode (CR). The main circuit topology is shown in Figure 4.

In constant current mode, it is required to keep Ui constant, that is, when Ii changes, Ui remains unchanged. From the law of conservation of power, it can be seen that in order to achieve constant Ii, when Ui increases or decreases, Uo needs to be increased or decreased. By adjusting the duty cycle of the switch tube to change the voltage gain of the buck-boost chopper circuit, Uo changes in the same direction as Ui, and finally realizes the function of constant input voltage at the load end.
In constant resistance mode, it is required to keep the equivalent resistance Radj unchanged, that is, when Ui changes, Radj remains constant. From the law of conservation of power, it can be seen that in order to achieve constant Radj, when Ui increases or decreases, Uo needs to be increased or decreased. By adjusting the duty cycle of the switch tube to change the voltage gain of the buck-boost chopper circuit, Uo changes in the same direction as Ui, and finally realizes the function of constant input voltage at the load end.
Switch tube selection: The peak voltage of the MOSFET tube in this system is 30V. Considering the voltage spike during the switching process, a 50% margin is reserved. When the circuit is working normally, the maximum current passing through the switch tube is about 2.5A, so the withstand current is preferably greater than 3A. Considering that the switch tube loss should be reduced as much as possible, the N-channel MOS tube SET0178 is selected, with a withstand voltage of 100V. Inductor
selection: Considering the high efficiency requirements of the system, the leakage inductance of the inductor should be as small as possible. When the circuit is working, it is important to avoid inductor saturation and excessive temperature rise. Iron silicon aluminum magnetic rings with strong peak current bearing capacity and low EMI should be used, and their leakage inductance is extremely small.
Capacitor selection: In the main topology, the voltage input and output side capacitors will directly affect the voltage ripple. Since the problem has high requirements for voltage stability, a large-capacitance electrolytic capacitor is selected in parallel with a high-frequency ceramic capacitor to suppress the ripple as much as possible.
2. Measurement control circuit and control program
(1) Voltage measurement circuit The
voltage measurement circuit consists of a voltage divider resistor and a voltage follower. The system needs to collect two voltages, so the LM358 dual op amp chip is used to design a voltage follower, and the voltage divider resistor is appropriately selected to improve the sampling accuracy of the single-chip microcomputer. The voltage measurement schematic diagram is shown in Figure 5.

(2) Current measurement circuit
In order to ensure the accuracy of the system maximum power point tracking, the current measurement uses the INA282 high-precision chip. INA282 can amplify the voltage at both ends of the constant copper wire by 50 times. The single-chip microcomputer collects the voltage signal through its own ADC to calculate the current size. The current measurement schematic diagram is shown in Figure 6.

(3) PID algorithm
This system uses the PID algorithm for closed-loop control. The PID controller is a linear controller. First, the deviation is obtained based on the given value and the actual value, and then the deviation is linearly combined according to the proportional term, integral term and differential term to form a control quantity. The control block diagram is shown in Figure 7.

(4) Control program
In the electronic load constant current mode, when the current set value "Set_curr" at the input end of the electronic load is greater than the input current "curr_in", the voltage gain of the buck-boost circuit is increased, so that the voltage at both ends of the resistor in the electronic load increases, thereby increasing the current "curr_in" at the input end of the electronic load. When the current setting value "Set_curr" at the input end of the electronic load is less than the input current "curr_in", the voltage gain of the buck-boost circuit is reduced to reduce the voltage across the resistor in the electronic load, thereby reducing the current "curr_in" at the input end of the electronic load.
In the constant resistance mode of the electronic load, the constant resistance is ultimately achieved by adjusting the voltage gain. Therefore, it is necessary to convert the set value of the resistor into the target voltage through "TargVolt = curr_in*SetR/1000", where "SetR" can be adjusted online through the display screen, and "curr_in" is the current at the input end of the electronic load, which is collected by the AD channel of the development board. When the target voltage "TargVolt" is greater than the voltage "volt_in" at the input end of the electronic load, it is equivalent to an increase in the equivalent resistance Radj and a decrease in the input voltage Ui. In order to maintain Radj unchanged, the voltage gain of the buck-boost circuit should be reduced accordingly to reduce the voltage across R1 in the electronic load. When the target voltage "TargVolt" is less than the voltage "volt_in" at the input end of the electronic load, the voltage gain of the buck-
boost to increase the voltage across R1 in the electronic load.

III. Theoretical analysis and calculation
1. Selection and calculation of main circuit device parameters
(1) Inductor selection calculation
Since the DC-DC circuit uses MOSFET tubes instead of traditional freewheeling diodes, the inductor does not have a discontinuous mode, the duty cycle is .95, 0.30, and the maximum load current is 3A. Therefore, the inductor is calculated according to the following formula:
In the bidirectional DC-DC working mode, that is, the battery charging and discharging mode, the duty cycle is .70, 0.40, and the maximum load current is 2A.
In summary and combined with the actual situation, the inductor of the buck-boost chopper circuit is selected to be 1mH.
(2) Capacitor selection calculation
In the bidirectional DC-DC working mode, the ripple size of the battery side voltage should meet:
Where, L=1mH,, 0.30, should have, according to,
then C147.91. Considering the filtering effect and overall quality, select a large capacitance of 470 and a high-frequency ceramic capacitor in parallel.
2. Methods to improve efficiency
(1) The loss of switching devices is inevitable, but low-power switching tubes and diodes can be used.
In the past, we generally used IRF540 NMOS tubes, but the on-resistance of this switch tube is relatively large. In order to better reduce the on-resistance and improve efficiency, we chose SET0178 switch tubes, which have extremely low on-resistance and high stability. The freewheeling diode uses a fast recovery diode FR307 to reduce losses and improve efficiency.
(2) Reduce the frequency of PWM. We use 20kHz PWM to control the on and off of the switch tube, which is more efficient than higher frequency PWM. IV
. Test plan and test results
1. Test plan and test conditions
Connect a 25Ω100W high-power resistor to the buck-boost chopper circuit to form a DC electronic load. By changing the voltage of the regulated power supply, the circuit indicators under different states can be tested. Combined with the test reference wiring diagram in the question, set appropriate voltage and current test points, and use a 5.5-digit benchtop multimeter and a 3.5-digit handheld multimeter to test the corresponding voltage and current values.
Test instruments: DC regulated power supply, 5.5-digit benchtop multimeter, 3.5-digit handheld multimeter.
2. Test results and analysis
(1) The current setting range of the constant current (CC) working mode is 100mA~2000mA, the setting resolution is 10mA, and the setting accuracy is +/-1%. In the constant current (CC) working mode, when the voltage across the electronic load changes by 10V, the absolute value of the output current change is required to be less than 5% of the current value before the change. The results are shown in Table 1.
Table 1 Test data record (I)
/V /A
0.1
0.5
1.0
1.5
2.0
Mode
10
0.102
0.507
1.099
1.511
2.097
CC
20
0.110
0.511
1.021
1.590
2.101
CC
According to the test results, when the voltage across the electronic load changes by 10V, the absolute value of the output current change is less than 5% of the current value before the change.
(2) The resistance setting range of the constant resistance mode is 10-99 ohms, the setting resolution is 10mA, and the setting accuracy is +/-1%. The results are shown in Table 2.
Table 2 Test data record (II)
/Ω
10
30
50
70
90
99
mode
/Ω
10.078
30.013
50.005
70.090
89.996
99.989
CR
According to the test results, the actual resistance value in the constant resistance mode meets the requirements of the question.
(3) The results are shown in Table 3.
Table 3 Test data record (III)
/A
1
2.0
2.5
/V
22.87
0
0
According to the test results, the overload protection current value can be set between 2000-25000Ma, and an effective prompt will be given once an overload occurs. It meets the requirements of the question.
(4) The results are shown in Table 4.
Table 4 Test data record (IV)
/V
10
14
18
22
26
/V
1.201
16.56
1.30
24.97
2.466
93.47%
/A
0.5
0.7
0.9
1.1
1.3
1.4
/A
0.513
0.712
0.912
1.113
1.321
1.422
According to the test results, the display accuracy meets the requirements of the question.
(5) When in the constant resistance mode, the resistance value can be displayed in real time. The accuracy is +/- (2%+0.8%FS or more), and the resolution is 1Ω. The results are shown in Table 5.
Table 5 Test data record (V)
/Ω
10
30
50
70
90
/Ω
9.987
29.798
49.899
69.945
89.978
From the test results, it can be seen that when in the constant resistance mode, the resistance value can be displayed in real time. The accuracy is +/- (2%+0.8%FS or more), and the resolution is 1Ω. It meets the requirements of the question.