B60H BRIDGE
The task
P0 reads a direction knob on CH1. P1 and P2 drive the two halves of a motor's H bridge.
Over 50, drive P1 with twice the reading's distance from 50; under 50, drive P2 that way.
The other half stays at 0. CH2 and CH3 show the two duties, smoothed.
The board
- Sources
- V1 3.5 V, V2 2 V square at 12.5 Hz, and V3 1 V square at 6.25 Hz
- Resistors
- R1 10 kΩ and R2 10 kΩ
- Capacitors
- C1 1 µF and C2 1 µF
- Probes
- CH1, CH2, and CH3
Key idea
The distance from 50, doubled, runs from 0 at the middle to 100 at either end.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
A PWM pin treats a duty under 0 as 0, so a negative value turns its half off by itself.
Hint 2Show
Write (reading minus 50) times 2 to P1, then the same value negated to P2.
Solution
Reveal the Full SolutionThe complete program for H BRIDGE. 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.
One signed value serves both halves, since the PWM pins clamp at 0.
u1SC-2 standard
IN P0
SUB 50
MUL 2
OUT P1
NEG
OUT P2- CYCLES
- 1600
- at par
- ENERGY
- 3200
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 6
- at par
Another way: Branch
A second program that also passes, by a different road, at a cost on INSTRUCTIONS.
Tests the side first and writes 0 to the other half.
u1SC-2 standard
L: IN P0
SUB 50
JL R
MUL 2
OUT P1
MOV A, 0
OUT P2
JMP L
R: MUL -2
OUT P2
MOV A, 0
OUT P1- CYCLES
- 1600
- at par
- ENERGY
- 3200
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 12
- over par