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

Day 311 of 365 · Expert · Month 11: Optimisation and debugging

Probes in the code

Probes in the code: write intermediate values to displays and the housing, read another chip's LineNumber and add counters for switching events.

Lesson 16 min Week 45

What you learn today

  • Write values to displays and db
  • Read LineNumber
  • add counters

The workshop heater switches. But how often? Too often, because the hysteresis is too narrow? Without measuring you are only guessing. A probe is a line that writes an intermediate value to a place where you can see it – like a meter you clip onto a wire.

Three places for a probe

PlaceLinegood for
Housings db Setting r0one value, without any extra device
LED displaysbn DISP HASH("Sonde1") Setting r0several values at once, with a unit via Mode
Logic Memorysbn MEMORY HASH("Sonde2") Setting r0values a second chip should evaluate

Write the value the way the chip sees it, before any conversion. That is exactly when NaN, Kelvin instead of Celsius and doubled sums stand out immediately.

Warning

s db Setting overwrites the setting of the housing. If another chip uses that setting as a mailbox, the probe destroys its message. Use a display of its own then.

LineNumber: where is the chip?

LineNumber of a housing is the line its chip is on right now. A second chip can read and display it. If the display shows the same line in a waiting loop for minutes, the chip is waiting there for a condition that never happens – for example for a door that is already open.

define GEHAEUSE HASH("StructureCircuitHousing") # IC housing
lbn line GEHAEUSE HASH("Schleusenchip") LineNumber Average
sbn ANZ HASH("Sonde1") Setting line

In normal operation the value changes all the time, usually it is the place where the chip waits for the next tick. LineNumber becomes meaningful when it stops moving.

Adding counters

Many questions are “how often?”: how often does the loop run, how often does the heater switch on, how long does a state last? A counter answers that.

add passes passes 1     # counts every tick
sgt edge on old           # 1 only on a change from 0 to 1
add starts starts edge
move old on

The edge counter only counts switching on, not every tick with the heater running. If it rises every few seconds, the hysteresis is too narrow.

Tip

Some probes are worth keeping forever. A display with the number of switch-on events hangs next to the heater in many bases.

Diagram

Reading with l, writing with s Gas sensor (d0) Temperature 293.15 IC10 r0 = 293.15 Wall light (d1) On 1 l r0 d0 Temperature device → register s d1 On 1 value → device
A probe is an extra s or sbn: the chip writes an intermediate value to a place where you can read it.

Exercise

Task

The workshop heater already works. Add two probes: the housing shows the measured temperature in Kelvin (-1 if the sensor is missing), the display “Schaltzahl” counts how often the heater was switched on. The control itself stays unchanged.

Hints

Hint 1

First select tmp ok temp -1, then s db Setting tmp.

Hint 2

You detect switching on with sgt edge on old: 1 only if on is 1 now and was 0 before.

Hint 3

After counting move old on, otherwise the chip counts every tick.

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