What you learn today
- Step in a register
- Advance on a condition
- Restart the sequence
The hangar door should not just spring open. First a warning lamp flashes, then the door opens, stays open for a while and closes again while the lamp is still warning. That is a sequence: several steps one after another, each with its own job.
The step sits in a register
Every step gets a number. A register remembers which step the sequence is in right now:
| Step | What happens | next when … |
|---|---|---|
| 0 | idle, door closed | the button is pressed |
| 1 | warning lamp on | PREWARN ticks have passed |
| 2 | door open | OPENTIME ticks have passed |
| 3 | door closed, lamp still on | PREWARN ticks have passed |
After step 3 it goes back to step 0. Then the sequence is ready for the next start.
Branching by step
At the start of every pass the chip jumps to the code of the current step:
beq step 1 s1
beq step 2 s2
beq step 3 s3
# step 0 is here
Every step block sets its outputs and checks its condition. If it is met, the block writes the next number and resets the time:
s1:
move warning 1
blt time PREWARN output # not done yet
move step 2
move time 0
j output
In the end all blocks land at output:. There the chip writes the devices, exactly once per pass.
Time within a step
A counter time runs up every tick and is reset to 0 on every change of step. That way every step knows how long it has been running, and you need no separate counter per step.
Do not forget the j output at the end of a block. Otherwise the chip runs into the next block and does two steps in one tick.
Step 0 is the idle state: door closed, lamp off. In the game the register keeps its old value after an upload. Set step to 0 with move before the start label, then the sequence always starts cleanly.
Diagram
Exercise
Task
Build the sequence for the hangar door from the table above.
- Button “Tortaster” (
StructureLogicButton): the edge starts the sequence, but only in step 0. - Door “Hangartor” (
StructureCompositeDoor, valueOpen), flashing light “Torwarnung”. - After step 3 back to step 0, a new press starts the sequence again.
- If the button is missing, everything stays idle.
Hints
Hint 1
After the inputs: beq step 1 s1, beq step 2 s2, beq step 3 s3. What follows is step 0.
Hint 2
Every block: set outputs, blt time … output, otherwise the next step number and move time 0.
Hint 3
Every block ends with j output – only the last one may run straight into the label.
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