# Battery CC-CV

**Libraries:**

Simscape /
Battery /
BMS /
Current Management

## Description

This block implements a constant-current (CC), constant-voltage (CV) charging algorithm for
a battery. For a discharging battery, the block uses the value of the
**CurrentWhenDischarging** input port.

This block supports single-precision and double-precision floating-point simulation.

**Note**

To enable single-precision floating-point simulation, the data type of all inputs and
parameters, except for the **Sample time (-1 for inherited)**
parameter, must be `single`

.

You can switch between continuous and discrete implementations of the block by using
the **Sample time (-1 for inherited)** parameter. To configure the
block for continuous time, set the **Sample time (-1 for
inherited)** parameter to `0`

. To configure the block for
discrete time, set the **Sample time (-1 for inherited)**
parameter to a positive, nonzero value, or to `-1`

to inherit the
sample time from an upstream block.

**Note**

Continuous-time implementation of this block works only in a double-precision floating-point simulation. If you provide single-precision floating-point parameters and inputs, this block casts them to double-precision floating-point values to prevent errors.

This diagram illustrates the overall structure of the block:

### Equations

This block implements the CC-CV algorithm in constant-current and constant-voltage modes. This figure shows the operation of these modes:

This equation defines the battery reference current that the block outputs:

$$Current=\{\begin{array}{cc}Maximum\text{\hspace{0.17em}}charge\text{\hspace{0.17em}}current,& if\text{\hspace{0.17em}}battery\text{\hspace{0.17em}}is\text{\hspace{0.17em}}charging\text{\hspace{0.17em}}and\text{\hspace{0.17em}}{v}_{meas}<{v}_{\mathrm{max}}\\ \left({K}_{p}+{K}_{i}\frac{1}{s}\right)\left({v}_{\mathrm{max}}-{v}_{meas}\right),& if\text{\hspace{0.17em}}battery\text{\hspace{0.17em}}is\text{\hspace{0.17em}}charging\text{\hspace{0.17em}}and\text{\hspace{0.17em}}{v}_{meas}\ge {v}_{\mathrm{max}}\\ Maximum\text{\hspace{0.17em}}discharge\text{\hspace{0.17em}}current,& if\text{\hspace{0.17em}}battery\text{\hspace{0.17em}}is\text{\hspace{0.17em}}discharging\end{array}$$

where

*v*is the value of the_{max}**Maximum cell voltage (V)**parameter.*v*is the voltage of the highest cell._{meas}*K*and_{p}*K*are the values of the_{i}**Controller proportional gain**and**Controller integral gain**parameters.

## Examples

## Ports

### Input

### Output

## Parameters

## Extended Capabilities

## Version History

**Introduced in R2022b**