動作原理
A PID controller computes its output from the error between the reference and the measured value: a proportional term reacts to the present error, an integral term removes steady-state error, and a derivative term reacts to how fast the error changes. In power electronics, PI controllers are the workhorse of current and voltage loops.
This generator produces a discrete-time implementation for a fixed sampling period dt, ready to drop into a control interrupt. You can choose C (including a direct-access style for ISRs and the TI C2000 CLA), C++, Python or Arduino, and enable anti-windup, feedforward, and input and output limits.
Anti-windup stops the integrator from accumulating while the output is saturated, which avoids large overshoot when the system comes out of saturation. Output limits clamp the command, for example to the PWM duty range.
計算式
- Continuous PID
- u(t) = Kp·e(t) + Ki·∫e dt + Kd·de/dt
- Discrete integral (rectangular)
- I[k] = I[k−1] + e[k] · dt
- Discrete derivative
- D[k] = (e[k] − e[k−1]) / dt
- Output
- u[k] = Kp·e[k] + Ki·I[k] + Kd·D[k]
計算例
For a current loop sampled at 20 kHz, set dt = 50 µs, choose PI, enable anti-windup and limit the output to the duty-cycle range 0–1. The generated function can be called once per PWM interrupt with the current reference and the measured current.
よくある質問
Should I use PI or PID?
Most power converter current and voltage loops use PI. The derivative term amplifies measurement noise and switching ripple, so it is used only when the plant needs extra phase lead.
How do I choose Kp and Ki?
Start from the plant model and the desired crossover frequency, typically one tenth of the switching frequency or less for a current loop, then check the phase margin on a Bode plot.
Why does sampling time matter?
The discrete integral and derivative are scaled by dt. Using a different dt than the real interrupt period changes the effective gains.
計算結果は工学的な推定値です。データシート、シミュレーション、実測で設計を確認してください。