Syscall 2: Firmware, home

BenchChapter 9: Special nodes

B69DIFF AMP

The task

P0 and P1 read two signals on CH1 and CH2. Amplify the difference between them.

Set P2 to 50 plus 4 times (P0 minus P1). R1 and C1 smooth it onto CH3.

Words hold minus 128 to 127. The PWM pin clamps a duty to the range 0 to 100.

The board

The chip of DIFF AMPChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 analog in, reaching V3, CH2; P2 pwm out, reaching R1, C1, CH3.u1CHIP SC-2P0ANALOG INV1, CH1P1ANALOG INV3, CH2P2PWM OUTR1, C1, CH3
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.6 V sine at 5 Hz, V2 2.5 V, V3 2.25 V, and V4 0.5 V square at 3.125 Hz
Resistors
R1 10 kΩ
Capacitors
C1 1 µF
Probes
CH1, CH2, and CH3

Key idea

The difference is small, so four times it, plus 50, stays well inside a word.

Hints

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

Hint 1Show

Subtract first, then multiply, then add 50.

Hint 2Show

IN P1, MOV B, A, IN P0, SUB B, MUL 4, ADD 50, OUT P2.

Solution

Reveal the Full SolutionThe complete program for DIFF AMP. 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.

Subtract, then gain, then the offset.

u1SC-2 standard

IN P1
MOV B, A
IN P0
SUB B
MUL 4
ADD 50
OUT P2
CYCLES
2400
at par
ENERGY
4800
at par
NODES
1
at par
INSTRUCTIONS
7
at par