Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B06QUADRATURE

The task

Two LEDs, two channels: P0 drives the red one, P1 the green one.

Each blinks with a period of four ticks of P2, on for two and off for two.

The green LED runs one tick behind the red one.

The board

The chip of QUADRATUREChip u1 with 3 ports: P0 digital out, reaching R1, D1, CH1; P1 digital out, reaching R2, D2, CH2; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL OUTR1, D1, CH1P1DIGITAL OUTR2, D2, 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.
Resistors
R1 330 Ω and R2 330 Ω
LEDs
D1 red and D2 green
Probes
CH1 and CH2

Key idea

The tick count modulo four gives the phase, 0 to 3.

Hints

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

Hint 1Show

Dividing the phase by 2 gives 0, 0, 1, 1: one LED's pattern.

Hint 2Show

The other LED's phase is one tick earlier: subtract 1 before the modulo, or add 3.

Solution

Reveal the Full SolutionThe complete program for QUADRATURE. 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 P2
MOV B, A
MOD 4
DIV 2
OUT P0
MOV A, B
ADD 3
MOD 4
DIV 2
OUT P1
CYCLES
231
at par
ENERGY
462
at par
NODES
1
at par
INSTRUCTIONS
10
at par

Another way: Branch

A second program that also passes. It beats par on CYCLES and ENERGY and gives some back on INSTRUCTIONS.

Four ticks, four writes: the pattern spelled out.

u1SC-2 standard

IN P2
MOV A, 0
OUT P1
IN P2
MOV A, 1
OUT P0
IN P2
OUT P1
IN P2
MOV A, 0
OUT P0
CYCLES
64
under par
ENERGY
128
under par
NODES
1
at par
INSTRUCTIONS
11
over par