PI controller

Sampled PI control with output saturation and a bounded integral state.

  • signal
  • Gradara equations
  • 3 ports
  • 4 parameters
BlockPI controllerKindpiLibraryControl

Description

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.

Set point (PI)PI (sampled)Plant (PI)y (PI)Set point (PID)ErrorPIDPlant (PID)y (PID)Set point (sampled PID)PID (sampled)Plant (sampled PID)y (sampled PID)
In Gradara, select a PI controller block and press F1, then choose Open example. It opens as a new model in My models, ready to run.

Also in this example:SubtractStepGainLow-pass filterPIDDiscrete PID

Ports

Inputs 2

  • refreference

    Setpoint.

  • measmeasured

    Measured value, in the same units as the reference.

Outputs 1

  • outy

    Controller output, held between samples and limited to ±limit.

Parameters

  • Proportional gainkp0.6

    Proportional gain.

  • Integral gainki2

    Integral gain, per second.

  • Voltage limitlimit24 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 periodsamplePeriod0.001 s

    ≥ 0.0001

    Sample period Ts, in seconds, at least 0.1 ms. The first sample is at t = 0.

Equations

Modelica
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

The block’s Modelica model
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.