What you learn today
- Convert ticks to seconds
- On-delay
- Run-on time
A pump should only start once the valves are surely open. A warning lamp should keep shining after the machine has stopped. Both are times, and the chip measures time in ticks.
Ticks and seconds
One tick lasts 0.5 s, so a second has 2 ticks. If your main loop runs with exactly one yield per pass, every pass is one tick:
| Time | Ticks |
|---|---|
| 1 s | 2 |
| 10 s | 20 |
| 1 min | 120 |
| 1 h | 7200 |
sleep waits as well, but during that time the chip does nothing else. For timers that run alongside the rest of the logic you therefore count ticks.
On-delay
The output only switches on after the input has been on for a while without interruption. The counter runs up while the input is 1 and drops to 0 at once when it becomes 0:
add tOn tOn 1
mul tOn tOn input # input off: counter to 0
sge out tOn DELAY # on long enough?
A short tap triggers nothing. That also protects against operating mistakes.
Run-on time
The other way round, an output stays on for a while after switching off. While the input is on, the counter is charged to full. Afterwards it counts down:
sub tRun tRun 1
select tRun input RUNON tRun # on: recharge
max tRun tRun 0
sgtz lamp tRun # time left?
The template “Lights on presence” in the IC10 coder works the same way.
A pass is only one tick if the loop stays below 128 instructions. If it needs more, the chip continues in the middle of the pass during the next tick, and your times are no longer right.
Write times as a define in ticks and put the seconds in the comment: define DELAY 6 # 3 s. Then everyone sees right away what is meant.
Diagram
Exercise
Task
The lever “Pumpe” starts the volume pump “Umfuellpumpe”.
- Start delay: the pump only runs once the lever has been on for
DELAYticks (3 s) without interruption. - Run-on: the flashing light “Betrieb” is on while the pump runs and for
RUNONticks (5 s) afterwards. - If the lever is missing, the pump stops.
Hints
Hint 1
sgtz input input turns NaN into 0 – no lever, no pump.
Hint 2
Start delay: count up, multiply by input, compare with DELAY using sge.
Hint 3
Run-on: count down, set to RUNON with select while the pump runs, max … 0, then sgtz.
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