PI controller
Sampled PI control with output saturation and a bounded integral state.
- signal
- Gradara equations
- 3 ports
- 4 parameters
piLibraryControlDescription
A sampled PI controller acting on the error between a reference and a measurement. At each sample it updates a clamped integral and computes a saturated output, which then holds until the next sample.
Use it for loops such as motor speed or output-voltage regulation where a fixed controller rate matters.
Example
PI and PID loops The same first-order plant under a sampled PI, a continuous PID, and a sampled PID controller.
Also in this example:SubtractStepGainLow-pass filterPIDDiscrete PID
Ports
Inputs 2
-
ref
referenceSetpoint.
-
meas
measuredMeasured value, in the same units as the reference.
Outputs 1
-
out
yController output, held between samples and limited to ±limit.
Parameters
-
Proportional gain
kp0.6Proportional gain.
-
Integral gain
ki2Integral gain, per second.
-
Voltage limit
limit24 V≥ 0.1
Output limit, at least 0.1. Clamps both the output and the integral to ±limit. Labeled in volts, but it applies in whatever unit the output uses.
-
Sample period
samplePeriod0.001 s≥ 0.0001
Sample period Ts, in seconds, at least 0.1 ms. The first sample is at t = 0.
Equations
error = reference − measured At t = k · samplePeriod: integral = max(−limit, min(limit, integral⁻ + samplePeriod · ki · error)) y = max(−limit, min(limit, kp · error + integral)) integral⁻ is the value from the previous sample; integral starts at 0.
Implementation
discrete Real integral(start=0, fixed=true); Real error; error = reference - measured; when sample(0, samplePeriod) then integral = max(-limit, min(limit, pre(integral) + samplePeriod*ki*error)); y = max(-limit, min(limit, kp*error + integral)); end when;
Assumptions and limitations
- The integral is updated with the current error (backward Euler), so a step in error affects y at the same sample, with no computation delay.
- Anti-windup is a clamp on the integral at ±limit, not back-calculation. The integral can still sit at the limit while the proportional term alone saturates the output.
- No derivative term. For one, use Discrete PID.
- The error is read only at sample instants; nothing between samples is seen.
Tips
- Choose samplePeriod well below the loop’s time constants; each sample is a simulation event.
Used in
These larger examples use it too. Open them from Examples in the app.
- Data center cooling control
- Motor speed control
- 480 VAC → 24 VDC flyback
See also
Select a block in Gradara and press F1 to open its page offline.