Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B09RECTIFIER

The task

V1 and V2 put a sine wave on P0, swinging 2 volts either side of 2.5 volts.

Fold it: on CH2, output the distance from the middle, doubled, as a PWM duty on P1.

Above the middle and below it, the output rises the same.

The board

The chip of RECTIFIERChip u1 with 2 ports: P0 analog in, reaching V2, CH1; P1 pwm out, reaching R1, C1, CH2.u1CHIP SC-2P0ANALOG INV2, CH1P1PWM OUTR1, C1, CH2
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.5 V and V2 2 V sine at 50 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

The middle, 2.5 volts, reads as 50 percent.

Hints

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

Hint 1Show

Subtract 50, then make the result positive: NEG flips the sign of A.

Hint 2Show

Doubling 40 percent from the middle gives 80 percent: 4 volts at the peaks.

Solution

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

u1SC-2 standard

IN P0
SUB 50
JG W
NEG
W: MUL 2
OUT P1
CYCLES
400
at par
ENERGY
800
at par
NODES
1
at par
INSTRUCTIONS
6
at par

Another way: Double first

A second program that also passes, and matches par on every benchmark.

Doubles first, then folds.

u1SC-2 standard

IN P0
SUB 50
MUL 2
JG W
NEG
W: OUT P1
CYCLES
400
at par
ENERGY
800
at par
NODES
1
at par
INSTRUCTIONS
6
at par