After the hardware design work for each module is completed, the system functions have been physically combined into a whole. The next step is to design the software for each module. The portable power supply system mainly consists of three parts, each part is independently programmed by its own chip to control the corresponding functions: the charging module and the discharging module process their respective data, and the portable power management module will collect and display their data on the LCD screen. The coordinated operation of each module ensures the orderly operation of the entire portable power system through data transmission, processing, and control. This chapter will introduce the specific software design of the key parts of each module.
1. Program design of portable power system management module
1.1 System Management Module Circuit Main Program Design
The software design of the portable power system management module requires collecting data information from various parts of the entire system and displaying it on the LCD screen for users to read and operate. The STM32 microcontroller system used in this section completes a series of initialization operations for the portable power supply system after power on reset, such as clock initialization, timer initialization, and serial communication initialization. After initialization, the portable power supply system parameters are configured. After the above program is executed, the voltage and current information of the module is cyclically detected in the interrupt service program, and then the data is processed and transmitted to the LCD screen driver module for data display.
1.2 AD sampling subroutine design
The STM32F103C8T6 chip comes with three ADC conversion modules, and the ADC input range of the chip is: VSSA ≤ VIN ≤ VDDA. Determined by two external pins, VDDA and VSSA. Usually, when designing the schematic, the VSSA pin is grounded and the VDDA pin is connected to 3.3V, resulting in an input voltage range of 0-3.3V for the ADC. And by designing an external voltage conditioning circuit, the input range to be measured can be widened, such as an operational amplifier, which can increase or decrease the voltage to be converted to the 0-3.3V range, so that the ADC can perform measurements.
When designing the circuit in this article, the set collection input voltage range is set to 0-3.3V, and the accuracy of the ADC is 12 bits. The relationship between analog and digital quantities can be established through the formula:

Among them, X corresponds to the collected digital voltage, and Y represents the converted analog voltage. According to the equation, the actual voltage value can be derived.
1.3 LCD screen driver subroutine design
The data instructions for configuring HT1621 are divided into command mode and data mode. The portable power supply system of HT1621 can be configured through command mode, and data transmission can be operated using the instruction code of data mode. The modes include read-only (READ) operation, write only (WRITE) operation, and read-write (READ-MODIFY-WRITE) operation. The specific relationship between the instruction code and the corresponding operation is shown in Table .
Operation | Parameters | Instruction code |
READ | Data | 110 |
WRITE | Data | 101 |
READ-MODIFY-WRITE | Data | 101 |
COMMAND | Command | 100 |
The main control chip is connected to CS, DATA, WR, and RD through four ports, and transmits corresponding data to perform write instruction operations on the LCD driver chip. CS serves as the chip selection signal port for the driver chip. When the CS signal is low, the “read/write” command operation takes effect. DATA is a serial data input/output port, through which instructions and data address operations are transmitted. WR is the write clock port, and the instructions and data addresses on DATA will be transmitted to the corresponding RAM area inside the chip when their signal is on the rising edge. RD is the clock reading port, and chip memory data will be transmitted to the DATA line when RD is the falling edge.
2. FSBB charging module circuit program design
2.1 Main Program Design of Charging Module Circuit
The STC12C5410AD is selected as the control chip for the battery charging module, which needs to collect input voltage, output current, and battery voltage (output voltage) signals. The signals are processed by the current controller and voltage controller for current voltage dual loop processing. Finally, the corresponding PWM signal is output by the logic controller for MOS switch on/off control.
FSBB controls the main program of the portable power supply system to first perform a series of initialization operations. After initialization, configure the parameters of each module of the portable power supply system, and then check whether the battery level is fully charged. If the battery level is full, the program will directly jump out. If it is not fully charged, the required signal will be continuously detected in the interrupt service program. After processing, it will be transmitted to the FSBB working mode subroutine for control.
2.2 FSBB working mode subroutine design
In the portable power supply system controlled by FSBB, the configuration of FSBB working mode is achieved by collecting input and output voltage signals for comparison. During the operation of the subroutine, the input and output voltage signals collected by the ADC interrupt program are first compared in size. If the difference in input and output voltage is too large, the charging chip will determine it as overvoltage or undervoltage and prohibit PWM signal output; If the difference between the two is within the set range, the chip will perform pattern recognition through the expected designed voltage switching point, and change the PWM signal and portable power system control parameters when the FSBB converter needs to perform pattern conversion.
3. Program design of full bridge inverter discharge circuit
3.1 Main program design of discharge module circuit
The AC discharge module can be divided into two parts. The first part is the front-end push-pull boost circuit. The portable power supply system uses the developed EG1612 chip, so only the peripheral hardware circuit of the chip needs to be designed, without the need to write internal programs; The second part is the post stage full bridge inverter circuit, which uses the STC12C5410AD microcontroller to detect the operating parameters of the portable power supply system in real time. It is then re tuned to the voltage PID parameters KP, KI, and KD through a fuzzy controller. The current PID controller is then used to adjust the output control parameters, and the signal wave emitted by SPWM is used to control the output AC voltage of four IGBT switching tubes. Simultaneously complete other control functions such as fault handling, alarm, etc. Firstly, the microcontroller initializes the portable power supply system, and after initialization, it enters the SPWM pulse width calculation program to calculate the corresponding pulse width to control the IGBT of the inverter bridge. At the same time, the microcontroller filters the collected digital information and compares it with the set value. If it does not match the set value, a fuzzy control strategy is used to control the SPWM wave output to correct the output waveform.
3.2 Subprogram Design of Voltage Fuzzy PID Composite Control
Fuzzy algorithm program design based on fuzzy control table query method: Firstly, design a fuzzy control data table and pre configure it in the microcontroller. At the beginning of each cycle, the average voltage value is calculated based on the collected signal. At the end of each cycle, the preset reference signal is compared with the collected signal to calculate the voltage error e and the change in error ec. Then, by searching for the preset fuzzy control table, the control quantity is output to control the control parameters of the next pulse cycle SPWM wave. Reciprocating cycle.
The entire process is computationally simple, occupies minimal internal resources of the microcontroller, and has a fast response rate. By collecting voltage, current, and calculated error and error rate signals, the control parameters of SPWM waves are continuously changed in real time to reduce the output voltage THD and enhance the stability of portable power supply systems.
4. Summary
The software design of portable power system is introduced in detail, including FSBB charging main circuit program and three mode working mode subprogram, full bridge inverter circuit main program and fuzzy PID control subprogram, portable power system management main program and LCD driver subprogram. On the basis of the connection at the physical level in the previous chapter, a complete set of portable power system is formed through the connection at the software level, Preparation has been made for further experimental setup.