What you learn today
- Hysteresis, NaN guard, display, timer compared
- Which pattern when
Three months, many programs. Look closely and almost all of them consist of the same four building blocks. If you know them, you build new controls from parts instead of starting from scratch every time.
The four patterns
Hysteresis: two limits and a memory. For everything that should not flicker: heater, pump, generator.
slt tmp value UPPER
and on on tmp
slt tmp value LOWER
or on on tmp
NaN guard: every Average value can be NaN. Either the wording makes NaN fall into the safe direction by itself, or you catch it explicitly.
snan missing value
or alarm alarm missing
Display: convert values and write them to an LED, Kelvin to Celsius, ratio to percent.
sub c temp CELSIUSOFFSET
sbn DISPLAY HASH("Temp") Setting c
Timer: count ticks instead of sleep. Count up with reset for a delay, charge and count down for a run-on.
add t t 1
mul t t input
Which pattern when?
| Question | Pattern |
|---|---|
| Should something stay calm between two values? | hysteresis |
| Can a device be missing? | NaN guard (almost always: yes) |
| Should a person see the value? | display |
| Does duration matter, such as “only after 5 s” or “for another 10 s”? | timer |
| Should a short event count instead of a state? | edge |
Most real controls need three or four of them at once. The order in the body is almost always the same: read → guard → decide → shape in time → write.
Patterns get in each other’s way when they use the same registers. Give each pattern its own registers and list them in the alias block. A tmp shared by two patterns may only be valid across two or three lines.
The templates in the IC10 coder are exactly these patterns, ready to use. Look at them again with this in mind.
Diagram
Exercise
Task
Server room with gas sensor “Serverraum”. Combine all four patterns:
- hysteresis: wall cooler “Serverkuehler” on above 30 °C, off below 26 °C
- timer: flashing light “Serverwarnung” on when it is above 35 °C for longer than 3 s (6 ticks)
- display: LED “Servertemp” shows the temperature in °C
- NaN guard: without a sensor cool, warn and show −999 on the display
Hints
Hint 1
Cooling is the reversed hysteresis: sgt instead of slt.
Hint 2
Timer: sgt tmp temp HOT, count up, multiply by tmp, compare with DELAY using sge.
Hint 3
Display: convert first, then select c missing NOVALUE c.
Quiz
4 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