What you learn today
- State machine and ring buffer as building blocks
- PI controller and device check as building blocks
- Combine blocks
A pro does not write every chip from scratch. He keeps a few proven building blocks in mind and plugs them together. You built these four over the past months:
State machine and ring buffer
| Block | Core | What for |
|---|---|---|
| State machine | state number in a register, transitions every tick | sequences, faults, airlocks |
| Ring buffer | poke at an index, mod for the circle, get db to read | mean, history, trend |
The ring buffer smooths, the state machine decides. In series you get a decision that does not tip with every outlier:
poke i p
add i i 1
mod i i LENGTH # 0, 1, 2, 3, 0, ...
PI controller and device check
| Block | Core | What for |
|---|---|---|
| PI controller | P from the error, I accumulated with clamp | stepless actuators |
| Device check | NaN with Average, Count, bnan before calculating | safe state on failure |
The device check belongs before every other block: bnan p fault jumps before a NaN gets into the ring buffer or the integral.
Combining blocks
The order is almost always the same: check → smooth → decide → output. Every block gets a section # --- … --- of its own and its own registers. The state machine here holds the alarm until the mean is back above the warning threshold – not just above the alarm threshold:
seq tmp state S_ALARM
and tmp tmp next # in alarm and still below WARN?
select next tmp S_ALARM next
An empty ring buffer contains zeros. Without prefilling, the mean reports 25 kPa right after the start – and the state machine goes into alarm. That is why the chip fills the buffer before the start label once with the first reading.
and tmp tmp next works here because next is only 0, 1 or 2 and the alarm case needs tmp = 1: 1 AND 1 = 1, 1 AND 2 = 0. With bit instructions always check which values really occur.
Diagram
Exercise
Task
A pressure guard from two building blocks. Prefilling and the device check are done.
- Block 1: ring buffer over the last 4 pressure readings, mean on display “Mittel”
- Block 2: state 0 normal, 1 warning (mean below 90 kPa), 2 alarm (below 50 kPa); the alarm stays until the mean reaches at least 90 kPa again
- Sensor gone: state 3. Display “Zustand”
Hints
Hint 1
Ring buffer: poke i p, add i i 1, mod i i LENGTH, then a loop with get tmp db k over all 4 places.
Hint 2
New state without memory: slt next mean WARN plus slt tmp mean ALARM.
Hint 3
Hold the alarm: if the state was alarm and next is still 1, it stays at S_ALARM.
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