Syscall 2: Firmware, home

BenchChapter 7: Frames and loops

B53ZERO CROSS

The task

P0 reads a sine wave around 2.5 volts. P2 ticks every 10 cycles.

Flash the LED on P1 for one tick each time the wave crosses 2.5 volts on its way up,

and keep it dark the rest of the time.

The board

The chip of ZERO CROSSChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2; P2 timer 10 cycles.u1CHIP SC-2P0ANALOG INV1, CH1P1DIGITAL OUTR1, D1, CH2P2TIMER 10 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 50 Hz and V2 2.5 V
Resistors
R1 330 Ω
LEDs
D1 yellow
Probes
CH1 and CH2

Key idea

Compare each sample with 50 percent, and remember in B whether the last one was below.

Hints

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

Hint 1Show

A crossing is a sample at or above 50 right after one below it.

Hint 2Show

On a low sample, write 0 and set B to 1. On a high one, write B, then set B to 0.

Solution

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

Flash once each time the wave climbs through the middle.

u1SC-2 standard

L: IN P2
IN P0
SUB 50
JL LO
MOV A, B
OUT P1
MOV A, 0
MOV B, A
JMP L
LO: MOV A, 1
MOV B, A
MOV A, 0
OUT P1
CYCLES
676
at par
ENERGY
1352
at par
NODES
1
at par
INSTRUCTIONS
13
at par