Syscall 2: Firmware, home

BenchChapter 10: Meshes

B76SET POINT

The task

P2 reads the set point from a dial on CH1. P0 heats C1 through R1, and R2 leaks heat away.

P1 reads the temperature on CH2. Sample both on each tick of P3.

Heat while the temperature is more than 10 under the set point; stop when more than 10 over.

The board

The chip of SET POINTChip u1 with 4 ports: P0 digital out, reaching R1, C1, R2, CH2; P1 analog in, reaching R1, C1, R2, CH2; P2 analog in, reaching V1, CH1; P3 timer 16 cycles.u1CHIP SC-2P0DIGITAL OUTR1, C1, R2, CH2P1ANALOG INR1, C1, R2, CH2P2ANALOG INV1, CH1P3TIMER 16 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes. On a narrow screen, scroll the board sideways to see all of it.
Sources
V1 0.5 V square at 12.5 Hz, V2 1 V square at 6.25 Hz, and V3 1.5 V
Resistors
R1 10 kΩ and R2 47 kΩ
Capacitors
C1 2.2 µF
Probes
CH1 and CH2

Key idea

Inside the band, from 10 under to 10 over, leave the heater as it is.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

Subtract the set point from the temperature, then test the difference against minus 10 and 10.

Hint 2Show

The dial moves in steps, so the band moves with it.

Solution

Reveal the Full SolutionThe complete program for SET POINT. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

A band of 10 either side of the dial.

u1SC-2 standard

L: IN P3
IN P2
MOV B, A
IN P1
SUB B
ADD 10
JL ON
SUB 20
JG OFF
JMP L
ON: MOV A, 1
OUT P0
JMP L
OFF: MOV A, 0
OUT P0
CYCLES
1000
at par
ENERGY
2000
at par
NODES
1
at par
INSTRUCTIONS
15
at par

Another way: Short nop

A second program that also passes, by a different road, at a cost on CYCLES and ENERGY.

The short form with a pause after the tick.

u1SC-2 standard

L: IN P3
NOP
IN P2
MOV B, A
IN P1
SUB B
ADD 10
JL ON
SUB 20
JG OFF
JMP L
ON: OUT P0
JMP L
OFF: MOV A, 0
OUT P0
CYCLES
1082
over par
ENERGY
2164
over par
NODES
1
at par
INSTRUCTIONS
15
at par

Another way: Short

A second program that also passes, and beats par on CYCLES, ENERGY, and INSTRUCTIONS.

A negative difference is nonzero, so it lights the heater as it is.

u1SC-2 standard

L: IN P3
IN P2
MOV B, A
IN P1
SUB B
ADD 10
JL ON
SUB 20
JG OFF
JMP L
ON: OUT P0
JMP L
OFF: MOV A, 0
OUT P0
CYCLES
983
under par
ENERGY
1966
under par
NODES
1
at par
INSTRUCTIONS
14
under par