Simvik

Reflow oven: a PI loop that does not wind up

Run one step of a PI temperature loop whose integral stops growing while the heater is saturated. A hard embedded C problem (PID control), run and graded in…

hard · PID control · pi · anti-windup · saturation · product

Product: Industrial reflow oven (Industrial)

Requirement. The oven solders circuit boards and must reach each temperature step without overshooting: too hot and the components are damaged. The heater's output is 0 to 1000 (per mille of full power).

Each step, with err = setpoint - temp in degrees: output = 8 × err + (integral + err).

  • If that output is above 1000, return 1000; below 0, return 0. In both cases leave the integral unchanged: the heater is already doing all it can, so the error must not pile up (that pile-up is integral windup, and it causes the overshoot).
  • Otherwise add err to the integral and return the output.

Starter code

int16_t oven_pi(pi_t *c, int16_t setpoint, int16_t temp) {
  int32_t err = setpoint - temp;
  c->integral += err;
  int32_t out = 8 * err + c->integral;
  if (out > 1000) out = 1000;
  if (out < 0) out = 0;
  return (int16_t)out;
}

Example tests

Close to the setpoint

pi_t c = { 0 };
int a = oven_pi(&c, 200, 190);
int b = oven_pi(&c, 200, 190);
printf("%d %d\n", a, b);

Expected output:

90 100

After a long warm-up at full power

pi_t c = { 0 };
for (int i = 0; i < 50; i++) oven_pi(&c, 250, 25);
printf("%d\n", oven_pi(&c, 250, 249));

Expected output:

9

Learn it first

  • PID control · Feedback loops, the three terms, anti-windup and tuning.

More PID control problems