What you learn today
- Output proportional to the error
- Choose the gain
- Steady-state error
The buffer tank in front of the air supply should hold 2000 kPa. The base keeps drawing air from it, sometimes more, sometimes less. With a hysteresis the volume pump either runs at full power or not at all: the pressure saws back and forth between the thresholds and the pump switches every few seconds. Better is a pump that delivers exactly as much as is missing right now. That is what a P controller (P for proportional) does.
Error and output
You need three terms all week:
| Term | Meaning | in the example |
|---|---|---|
| Setpoint | where you want to be | 2000 kPa |
| Process value | what the sensor measures | Pressure of the pipe analyzer |
| Output | what the chip writes to the device | Setting of the pump, 0 to 10 |
The error e is setpoint minus process value. The P controller turns it into the output by multiplying it with the gain KP:
sub e TARGET press # e > 0: pressure too low
mul u e KP # output proportional to e
clamp u u 0 MAXPUMP # only what the pump can do
Double the error, double the pump output. If nothing is missing, the pump stands still. You already know clamp from day 57: otherwise an empty tank would ask for Setting 40 and an overfull one for a negative value.
Choosing the gain
KP says how much Setting you give per kPa of error. The easiest way to find it is the question: at which error should the pump run at full power? If it should be at the limit 500 kPa below the setpoint, KP = 10 / 500 = 0.02.
define KP 0.02 # 10 / 500 kPa: full at 500 kPa short
| KP | full from | Behaviour |
|---|---|---|
| 0.005 | 2000 kPa | sluggish, stays far below the setpoint |
| 0.02 | 500 kPa | calm, small remainder |
| 0.5 | 20 kPa | almost on/off, tends to oscillate |
If KP is too large, the output jumps from 0 to 10 at the tiniest error. Because the pressure does not react to the pump instantly, it then overshoots the target, the pump switches off, the pressure drops, the pump goes back to full – the controller oscillates.
The steady-state error
Now the catch. Suppose the base uses so much that the pump permanently needs Setting 4. A P controller only delivers 4 while there is an error: e = 4 / KP = 4 / 0.02 = 200 kPa. So the tank settles at 1800 kPa, not at 2000. Waiting longer changes nothing – at 2000 kPa e would be 0 and the pump would be off.
This steady-state error is not a bug in the code, it belongs to the P controller. A larger KP makes it smaller but makes the controller more restless. If you roughly know the consumption, a fixed base value helps, the feed-forward:
mul u e KP
add u u BASE # known base load, e.g. 4
clamp u u 0 MAXPUMP
If the consumption changes, the remainder is back. Only the I term makes it disappear for good – that is tomorrow.
Watch the sign. For a pump that fills, e > 0 means “do more”, so e = setpoint − process value. For cooling it is the other way round: too warm means cool more, so e = process value − setpoint. With the wrong sign the controller works against you and runs at full power when it should be off.
Diagram
Exercise
Task
A pipe analyzer “Puffer” measures the pressure in the buffer tank, the volume pump “Nachschub” fills it.
- Error e = TARGET − pressure
- Pump Setting = KP · e, limited to 0 to 10
On= 1 as soon as the Setting is greater than 0- Analyzer gone: Setting 0 and pump off
The defines and reading the pressure are already there.
Hints
Hint 1
sub e TARGET press, then mul u e KP and clamp u u 0 MAXPUMP.
Hint 2
sgtz on u gives 1 when u is greater than zero.
Hint 3
Right after reading, bnan press fault. Under the label fault: you write Setting 0 and On 0 and jump back.
Quiz
5 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in