Keeping a laser centred on a spinning disk.
A closed-loop embedded system that holds a laser spot on four photodiodes mounted to a
rotating disk — at every angle, up to 1.5 revolutions per second. Bare-metal STM32,
no RTOS, an empty while(1), and a coordinate-rotation controller running at
the hardware's hard 200 Hz ceiling.
The Physical Setup
A red laser is steered by two mirror-mounted stepper motors onto a 2×2 photodiode array that rides on a spinning disk; two light barriers tell the MCU exactly where the disk is, and the diode brightnesses tell it where the spot landed.
The Photodiode Data Protocol
The Maya hardware never stops talking: it streams one byte per photodiode over UART, four diodes to a frame, at a fixed 200 frames per second — and the controller fires the instant the fourth byte lands.
Encoder & Zero-Crossing Detection
Two light barriers offset by a quarter mark generate a Gray-code quadrature signal; decoding its transitions yields direction and an absolute position 0–459, and a special wide null marker resets that count once per revolution.
Stepper Motor Control
Each mirror is driven by a unipolar stepper in half-step mode — an 8-state coil sequence walked one step per TIM6 interrupt — moving the laser in fine, bounded increments.
Software Architecture
Six modules, zero polling: every action happens inside an interrupt handler, and a carefully chosen NVIC priority hierarchy guarantees that encoder edges and diode data are never missed while low-priority debug output drains in the background.
The Control Algorithm
The diodes spin, but the mirrors don't — so a raw sensor error would send the laser spiralling. The fix is a coordinate rotation by the disk angle that turns sensor-frame error into lab-frame error, fed through a PD controller with deadband and saturation.
Bugs Found & Fixed
Four real defects from the original monolithic firmware — each a small, plausible mistake with an outsized effect. Presented as symptom → root cause → fix.
System Performance
The refactor hits every grade tier through Sehr gut (1.0) — reliable tracking to 1.5 rev/s — by trading an error-prone if-ladder for a closed-form rotation and locking the control rate to the data rate.
Maya Laser Tracker — STM32F334R8, STM32 LL, fully interrupt-driven.
Firmware & documentation by Harald Fuchs (12447523) and Florian Beer (12421428).
TU Wien LVA 384.996 “Mikrocomputer LU”.