Figure 2-2 shows the software implementation of current and voltage control loops. Voltage loop
is cascaded to the current to achieve both constant-current and constant-voltage in
charging and discharging modes. When the battery voltage is far away from the
constant-voltage setting (VSET), the voltage loop gets saturated to constant current
setting (ISET). When battery voltage reaches close to VSET, the voltage loop is closed,
and ISET is reduced to make sure the battery voltage does not exceed the VSET limit. The
controller works in both charge and discharge modes. In the charge mode, VSET limits the
maximum battery voltage, thus stops the charging. While in the discharge mode, VSET
limits the minimum battery voltage which stops the discharging.