PI (discrete)

Sampled PI with output saturation and a bounded integral state. Every state updates at the sample instant, so exported C reproduces it exactly.

  • signal
  • Gradara equations
  • 3 ports
  • 4 parameters
BlockPI (discrete)KindpiLibraryControl

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 continuous PI and PID controllers and their sampled counterparts.

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

Also in this example:Discrete PIDStepGainLow-pass filterPI (continuous)PID (continuous)

Ports

Inputs 2

  • refreference

    Setpoint.

  • measmeasured

    Measured value, in the same units as the reference.

Outputs 1

  • y

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

Parameters

  • Proportional gainkp1

    Proportional gain.

  • Integral gainki2

    Integral gain, per second.

  • Output limitlimit10

    ≥ 0.001

    Output limit, at least 0.001, in the unit of the output. Clamps both the output and the integral to ±limit.

  • 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; for a continuous controller with back-calculation anti-windup, use PI (continuous).
  • 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.