Syscall 2: Firmware, home

BenchChapter 11: Capstones

B88FAN CURVE

The task

P0 reads the temperature on CH1. P1 drives the fan with PWM, smoothed onto CH2.

Under 30 the fan is off, and from 70 up it runs at 100.

Between, the duty is 2.5 times the reading minus 30.

Words hold minus 128 to 127, and the PWM pin clamps a duty under 0 to 0.

The board

The chip of FAN CURVEChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 pwm out, reaching R1, C1, CH2; P2 timer 20 cycles.u1CHIP SC-2P0ANALOG INV1, CH1P1PWM OUTR1, C1, CH2P2TIMER 20 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 2 V sine at 5 Hz and V2 2.5 V
Resistors
R1 10 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

60 times 5 does not fit in a word, so deal with the top of the range before you scale.

Hints

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

Hint 1Show

Twice a number plus half of it is 2.5 times it, and every step stays small.

Hint 2Show

Over 70, write 100. Otherwise keep the reading minus 30 in B and add B, B, and B DIV 2.

Solution

Reveal the Full SolutionThe complete program for FAN CURVE. 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 clamped linear curve, scaled without overflow.

u1SC-2 standard

L: IN P2
IN P0
SUB 70
JG F
ADD 40
MOV B, A
DIV 2
ADD B
ADD B
OUT P1
JMP L
F: MOV A, 100
OUT P1
CYCLES
925
at par
ENERGY
1850
at par
NODES
1
at par
INSTRUCTIONS
13
at par