Discrete PID controller

control.discrete_pid

PID control of the error input, computed every Ts seconds and held between samples. At each sample the integral adds ki Ts times the error (backward Euler), and the derivative is kd times the change in error since the last sample over Ts. The first sample is at t = Ts; before it the output is 0.

Ports

NameDomainDirection
usignalin
ysignalout

Parameters

NameUnitDefaultRangeDescription
kp11Proportional gain
ki1/s1Integral gain
kds0Derivative gain
Tss0.011e-9 to ∞Sample period

Variables

NameUnitStartDescription
I1Integral term
ep1Error at the last sample
yh1Held output
nextsTsTime of the next sample

Equations

der(I) = 0
der(ep) = 0
der(yh) = 0
der(next) = 0
when time >= next then reinit(I, I + ki * Ts * u), reinit(ep, u), reinit(yh, kp * u + I + ki * Ts * u + kd * (u - ep) / Ts), reinit(next, next + Ts)
y = yh