# 理想開關 (`idealSwitch`)

> 閘極訊號變低或變高時，斷開或接通一條路徑。

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

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

**分類:** 開關元件 · **種類:** `{"kind":"idealSwitch"}`

## 何時使用

用於由訊號直接驅動的雙向開關。需要線圈時用繼電器，需要體二極體時用 MOSFET 開關。

## 接腳

| 接腳 | 訊號域 | 意義 |
|---|---|---|
| `p` | 電氣 | 一端；電流可雙向流動 |
| `n` | 電氣 | 另一端 |
| `gate` | 訊號 | 訊號輸入；大於 0.5 時導通 |

## 常用參數

- `ron`: Resistance when it is on (預設值: 1m)
- `roff`: Resistance when it is off (預設值: 1meg)
- `tdon`: Delay before it turns on (預設值: 0)
- `tdoff`: Delay before it turns off (預設值: 0)

## 參數

| 鍵 | 單位 | 預設值 | 典型範圍 | 說明 |
|---|---|---|---|---|
| `ron` | Ω | 1m |  | Resistance when it is on |
| `roff` | Ω | 1meg |  | Resistance when it is off |
| `vf` | V | 0 |  | Voltage lost while it conducts |
| `device` | — | 選填（預設關閉） |  | Device name used to look up losses |
| `thermal` | — | 選填（預設關閉） |  | Where the lost heat goes |
| `eon` | J | 0 |  | Energy lost each time it turns on |
| `eoff` | J | 0 |  | Energy lost each time it turns off |
| `err` | J | 0 |  | Energy lost when the diode recovers |
| `vref` | V | 0 |  | Voltage used to measure those energies |
| `iref` | A | 0 |  | Current used to measure those energies |
| `tc` | 1/K | 0 |  | How on-resistance changes with heat |
| `tj` | °C | 25 |  | Junction temperature for the loss tables |
| `nParallel` | — | 1 |  | Identical devices this one switch stands for: the current is shared, the losses add up, each device keeps its own junction |
| `tjMax` | °C | 選填（預設關閉） |  | Highest junction temperature allowed; overrides the device's rating |
| `ls` | H | 0 | 500p – 50n H | Unwanted inductance in series with it |
| `coss` | F | 0 | 10p – 5n F | Capacitance across the device |
| `cj` | F | 0 | 5p – 2n F | Extra capacitance across the junction |
| `tdon` | s | 0 | 1n – 500n s | Delay before it turns on |
| `tdoff` | s | 0 | 1n – 500n s | Delay before it turns off |
| `qrr` | C | 0 | 1n – 5u C | Charge released as the diode recovers |
| `trr` | s | 100n | 10n – 1u s | How long the diode takes to recover |
| `qrrTemp` | — | 選填（預設關閉） |  | Junction temperature (°C) and factor pairs that scale qrr, from the datasheet's curve |
| `part` | — | 選填（預設關閉） |  | Part number; the catalogue part number, such as BSC070N10NS5, written on the schematic; information only, not simulated |
| `vRating` | V | 選填（預設關閉） |  | Voltage rating; the largest blocking voltage of the data sheet's maximum ratings (VDS, VCES, VRRM), written on the schematic; information only, not simulated |
| `iRating` | A | 選填（預設關閉） |  | Current rating; the continuous current of the data sheet's maximum ratings (ID, IC, IF), written on the schematic; information only, not simulated |

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

**適用於:** 理想 PWM 橋臂 · 訊號驅動開關 · 負載步階

**不適用於:** 需要體二極體的開關 → [`mosfet`](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/switches/mosfet/) · 線圈驅動的接點 → [`relay`](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/switches/relay/)

## 公式

| 公式 | 方程式 | 出處 |
|---|---|---|
| 導通損失 | P = ron·Irms² | Mohan, Undeland & Robbins, Power Electronics, 3rd ed. (2003), ch. 2 (on-state power loss of a switch) |
| 關斷漏電損失 | P = V²/roff | Mohan, Undeland & Robbins, Power Electronics, 3rd ed. (2003), ch. 2 (off-state leakage of a switch) |

## 快速驗算

輸入:

- `irms`: 導通時的均方根電流 = 5 A
- `ron`: 導通電阻 = 1m Ω, `ron`
- `vblock`: 關斷時的阻斷電壓 = 48 V
- `roff`: 關斷電阻 = 1meg Ω, `roff`

輸出:

- `pcond`: 導通損失 = `ron*irms^2` W
- `poff`: 關斷損失 = `vblock^2/roff` W

## 模型邏輯

- 閘極訊號大於 0.5 時它是電阻 ron，雙向導通且無壓降；等於或小於 0.5，或閘極未接時，它是電阻 roff。
- 控制方塊送出的 PWM 邊緣會讓時間步結束在該瞬間，所以開關在那一刻切換，而不是等到下一個格點。
- tdon 與 tdoff 延遲閘極訊號，ls 加入串聯電感，coss 與 cj 在開關兩端並聯電容；預設全部為 0。
- eon 與 eoff 在每次切換時依 (V/vref)·(I/iref) 比例計入損失報告；它們不會改變波形。

## 模型

閘極大於 0.5 時開關是電阻 ron，否則是電阻 roff，兩個電流方向都一樣，沒有壓降（vf 無作用）。狀態在步邊界改變。選用的 ls、coss、cj、tdon 與 tdoff 會加入串聯電感、並聯電容與閘極延遲。

## 常見錯誤

- 同一個橋臂的兩個開關同時導通，會經由 ron 把電源軌短路。請在兩個閘極訊號之間留死區時間。
- ron 單位是歐姆，數值過小或字首打錯會被提醒。求解器也把 ron 的下限設在 1 nohm，roff 與 ron 的比值過大會讓方程式變得僵硬。
- 閘極沒接時，開關一直是斷開的。電感有電流時打開開關，電壓會是該電流乘以 roff，請加二極體或緩衝電路。

Problems 規則: `shoot-through`, `param.out_of_range`

## 規格書與來源

ron 取自接點或通道電阻，roff 取自工作電壓下的漏電。要計入損耗時，依切換能量表設定 eon、eoff、vref 與 iref，並在 thermal 填散熱片節點的名稱。

## 範例

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

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