Firmware for a coil winding machine turns counter. Displays revolution count and RPM on an SSD1306 OLED display, reads rotation from a quadrature encoder. Counts in both directions.
Written in Rust, using RTIC framework and Embassy HAL.
- MCU: STM32F103C8 "Blue Pill" (ARM Cortex-M3, 72 MHz)
- Display: SSD1306 128x32 OLED (I2C)
- Encoder: Quadrature encoder (1024 PPR, x4 = 4096 counts/rev)
- Programmer: ST-Link or any probe-rs compatible SWD debugger
| Function | Pin |
|---|---|
| I2C1 SCL | PB6 |
| I2C1 SDA | PB7 |
| Encoder CH1 | PA0 |
| Encoder CH2 | PA1 |
https://app.cirkitdesigner.com/project/313b2b6d-25d9-41d3-8ceb-3a537f561505
- TIM2 runs in quadrature encoder mode, counting pulses from the encoder
QeiManagerwraps the 16-bit hardware counter, tracking overflows/underflows to extend the range to 64-bit- TIM1 fires at 20 Hz, triggering the display update interrupt
- Each update reads the encoder count, computes revolutions and RPM (smoothed with a 20-sample moving average), and renders to the OLED
XXX.XXX r <- RPM (moving average)
XXXX.XXX cn <- total revolution count
Requires:
- Rust toolchain with
thumbv7m-none-eabitarget - probe-rs for flashing/debugging
rustup target add thumbv7m-none-eabi
cargo install probe-rs-toolscargo run # debug build, flash via probe-rs
cargo run --release # release build with LTOMIT OR Apache-2.0

