# 電池 (`battery`)

> 電壓會隨荷電狀態變化的充電電池。

![battery](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/battery.svg)

[元件參考](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/) · [English](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/sources/battery/)

**分類:** 電源 · **種類:** `{"kind":"battery"}`

## 何時使用

用於儲能系統、電池充電器、電動車與備援電源。只需要固定電壓時，請用直流電壓源。

## 接腳

| 接腳 | 訊號域 | 意義 |
|---|---|---|
| `p` | 電氣 | 正端 |
| `n` | 電氣 | 負端 |
| `soc` | 訊號 | 荷電狀態，0 到 1（輸出訊號） |

## 常用參數

- `ah`: Capacity (預設值: 2.5)
- `soc0`: State of charge at the start, 0 to 1 (預設值: 0.8)
- `r0`: Resistance that drops the voltage at once (預設值: 50m)
- `ns`: Cells in series; the voltage table is per cell (預設值: 1)

## 參數

| 鍵 | 單位 | 預設值 | 典型範圍 | 說明 |
|---|---|---|---|---|
| `ah` | Ah | 2.5 |  | Capacity |
| `soc0` | — | 0.8 |  | State of charge at the start, 0 to 1 |
| `r0` | Ω | 50m |  | Resistance that drops the voltage at once |
| `r1` | Ω | 15m |  | Resistance of the first RC branch |
| `c1` | F | 2k |  | Capacitance of the first RC branch |
| `r2` | Ω | 選填（預設關閉） |  | Resistance of the second, slower RC branch |
| `c2` | F | 選填（預設關閉） |  | Capacitance of the second RC branch |
| `ns` | — | 1 |  | Cells in series; the voltage table is per cell |
| `socs` | — | 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 |  | State of charge points of the voltage table |
| `ocvs` | — | 3.0 3.45 3.55 3.62 3.68 3.74 3.82 3.91 4.0 4.09 4.2 |  | Rest voltage of one cell at each point |
| `temp` | °C | 25 |  | Battery cell temperature |
| `tref` | °C | 25 |  | Temperature the table and resistances belong to |
| `dOcvDt` | V/K | 0 |  | Change of a cell's rest voltage with temperature |
| `ea` | J/mol | 0 |  | Activation energy that raises the resistances in the cold |
| `soh` | — | 1 |  | Capacity left after ageing, as a share of ah |
| `rAge` | — | 1 |  | Growth of the resistances with ageing, 1 when new |
| `thermal` | — | 選填（預設關閉） |  | Thermal net of its cells; takes the heat of its resistances, and with ea set its temperature moves them |

_參數說明在兩種語言中都是英文。_

**適用於:** 儲能系統 · 電池充電器 · 電動車 · 備援電源

**不適用於:** 固定電源電壓 → [`dcVoltageSource`](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/sources/dcVoltageSource/) · 超級電容儲能 → [`supercap`](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/passive/supercap/)

## 公式

| 公式 | 方程式 | 出處 |
|---|---|---|
| C 率 | C-rate = i/ah | IEC 61960-3:2017, clause 3 |
| 充滿後的放電時間 | t = 3600·ah/i | Linden's Handbook of Batteries, 4th ed. (2011), Ch. 1 |
| 負載下的端電壓 | V = ns·voc − i·r0 | Linden's Handbook of Batteries, 4th ed. (2011), Ch. 2 |

## 快速驗算

輸入:

- `ah`: 容量 = 2.5 Ah, `ah`
- `i`: 放電電流 = 5 A
- `r0`: 串聯電阻 = 50m Ω, `r0`
- `ns`: 串聯芯數 = 1 —, `ns`
- `voc`: 電池芯開路電壓 = 4 V

輸出:

- `crate`: C 率 = `i/ah` —
- `trun`: 充滿後的放電時間 = `3600*ah/i` s
- `vt`: 瞬間端電壓 = `ns*voc - i*r0` V

## 模型邏輯

- 元件寫入受控電壓 ns·OCV(soc)，接著串聯 r0、最多兩組並聯 RC 支路與一個通往 p 的內部電流表；RC 電容從 0 V 開始。
- 荷電狀態從 soc0 開始積分 -i/(3600·ah·soh)，限制在 0 到 1 之間；電池芯 OCV 依 socs 與 ocvs 以直線查表，超出範圍時維持端點值。
- OCV 經由控制方塊跟隨荷電狀態，所以落後一步；r0、r1 與 r2 屬於整個電池組，不會乘上 ns。
- 溫度與老化在整次模擬中一次性地調整電阻並平移 OCV；自我發熱、自放電、遲滯與隨放電率變化的容量都沒有建模。

## 模型

電池由開路電壓、串聯電阻 r0 與最多兩組 RC 支路（r1 並 c1、r2 並 c2）串接而成。開路電壓等於 ns 乘上單一電池芯的電壓，電池芯電壓依荷電狀態查表 ocvs 得到，socs 各點之間以直線連接。荷電狀態從 soc0 開始，每秒減少 i / (3600 * ah)，其中 i 是由 p 流出的電流（與電池同名的元件的電流）。荷電狀態是訊號 name:soc，限制在 0 到 1 之間；電流仍推著它越過界限時會出現警告。預設的表是鋰離子 NMC 電池芯常見形狀的示意曲線，不是實測資料，預設的電阻與容量也只是示意。溫度與老化在整次模擬中固定：在電池芯溫度 temp 下，每個電阻都乘上 exp(ea / R * (1 / T - 1 / Tref))（阿瑞尼斯定律，R = 8.314 J/(mol K)，溫度以克耳文計）再乘上 rAge，表中每個電壓都平移 dOcvDt * (temp - tref)。老化也會讓容量縮小為 soh * ah。預設值（ea 與 dOcvDt 為 0，soh 與 rAge 為 1）表示新電池芯在表的溫度下。自我發熱與自放電都沒有建模。

## 常見錯誤

- 預設的表是單一電池芯的值。電池組要把 ns 設為串聯的芯數，否則電壓只有 3.7 V 左右。
- ah 的單位是安培小時，所以 100 ms 的模擬幾乎不會改變荷電狀態。想在短時間內看到變化，請把 ah 設小一點。
- 電池充滿後仍被充電，或放空後仍被放電時，電壓會停在表的端點。模擬後請看警告。

## 規格書與來源

ah 取額定容量，r0 取直流內阻。socs 與 ocvs 取自電池芯的開路電壓曲線，r1、c1、r2、c2 取自脈衝測試，也就是電流階躍後電壓慢慢回復的部分。ea 取自在兩個以上溫度量到的內阻（ln r 對 1/T 的斜率乘上 R），dOcvDt 取自兩個溫度下的靜置電壓（熵係數），soh 與 rAge 取自老化電池芯相對於新品的容量與電阻。

## 範例

以指令 `file.openExample` 開啟範例，名稱為 `demo:battery`.

---
由 `cargo xtask reference` 依使用說明文字與參數規格產生，請勿手動編輯。
