stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 80

Day 80 of 365 · Beginner · Month 3: First systems

Timers and delays

One tick is 0.5 seconds. With a counter you build an on-delay and a run-on time without the chip standing still in sleep.

Lesson 14 min Week 12

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:

TimeTicks
1 s2
10 s20
1 min120
1 h7200

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.

Warning

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.

Tip

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

Ticks and yield on a timeline tick 0 · 0.0 s tick 1 · 0.5 s tick 2 · 1.0 s tick 3 · 1.5 s 5 instr. yield 5 instr. yield 5 instr. yield 128 instr. no yield: limit hit Device values only change between two ticks.
Every pass of the main loop with one yield is one tick. A counter in a register measures time that way.

Exercise

Task

The lever “Pumpe” starts the volume pump “Umfuellpumpe”.

  • Start delay: the pump only runs once the lever has been on for DELAY ticks (3 s) without interruption.
  • Run-on: the flashing light “Betrieb” is on while the pump runs and for RUNON ticks (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

Esc
↑ ↓ selectEnter open/ opens search anywhere