# Design of Direct Current Microgrid Converter with Cost-Effective Low-Voltage Battery Storage System
## 7 Control Algorithms  
Control algorithms in discrete form have many advantages. Furthermore, using microprocessors enables advanced functions like communication data acquisition and processing. For our design, we chose a cost-effective modern digital signal processor from the family  
Figure 8: Energy transfer through the middle cell.  
Figure 7: Principal schematic of active balancer without galvanic isolation.  
STM32g474 with a high-resolution timer, multiple ADCs, and a core frequency of up to 170 MHz.  
Each of the converters on prototype has its discrete controller (Figure 9), which, depending on the state of the output variable, adjusts the relative switch-on time (duty) using a reference for the module. The high-resolution timer generates PWM signals. The inputs to the controller are the necessary variables in the inverter, which are converted to digital form by an analog-to-digital converter with a resolution of 12 bits. The sampling moment is synchronized with the PWM frequency. The sampling time is at the clock signal frequency for analog-to-digital converters \(f_{\text{clkADC}}=36\) MHz, about 70 ns.  
Figure 9: Complex control algorithm.  
Considering the time length for calculation of the controller parameters, at the frequency \(f_{\text{pwm}}=250\) kHz, the action is applied every 8 periods, i.e., 32 \(\upmu\)s; for the MPPT charge converter controller, it is applied every 63 periods, i.e., 252 \(\upmu\)s. This is because of the possibly slower changes in the solar controller circuit. The hardware built-in comparator compares the maximum current limit for each half period. The current limit for the solar controller is fixed to a maximum peak value of 17 A. For the output converter, the maximum peak current is selectable using an internal digital-to-analog converter, defaulting to 21 A, the same as the saturation current of the coil used. Another potential problem is the reverse power flow for the charging inverter from the battery to the solar panel input. This problem is solved by the zero-crossing current module, which closes the inverter transistors if this situation occurs.  
To simplify user access, the system also includes an OLED display showing the values of charging / output currents, voltages, and power flows; the display's refresh rate is 0.33 Hz, controlled by the TIM1 timer. To verify the functionality of the system and its possible self-sustained operation, the module also contains an SD card slot, where the values of all variables are stored at regular intervals of one second in a text file. For a quick status indication for the operator, the module also contains a set of multicolored LEDs that indicate the operating status by lighting or flashing.  
Since the whole module is powered by a battery of cells that need to be recharged, the module's consumption must be considered, which can range from 20 to 70 mA depending on the additional functions used. To put the whole system to sleep, a button in the corner of the board is used, and the interruption generated by pressing this button is directly connected to the clock pulse control. This will cause the system to sleep or wake up. The energy consumption in sleep mode is less than 200 mW.