seveibar/nema17-stepper-motor-driver-tmc2209-usb-pd
RP2040-based USB-C PD stepper-motor controller with TMC2209 drive, AS5600 position feedback, TMP102 thermal shutdown, current/voltage telemetry, RGB status LED, and protected buzzer alarm circuitry.
- Version
- 0.2.0
- License
- unset
- Stars
- 0
firmware/audible_alarm.py
"""Passive buzzer driven through Q_BUZZER. No GPIO load current."""
from tmp102 import WARN_C, TRIP_C
def alarm_duty(temperature_c, hardware_alert_ok, now_ms):
if not hardware_alert_ok or temperature_c is None or temperature_c >= TRIP_C:
return 32768
if temperature_c >= WARN_C:
# Short chirp each second before shutdown temperature is reached.
return 32768 if now_ms % 1000 < 200 else 0
return 0
class AudibleAlarm:
def __init__(self, pwm):
self.pwm = pwm
self.pwm.freq(2731)
self.pwm.duty_u16(0)
def update(self, temperature_c, hardware_alert_ok, now_ms):
self.pwm.duty_u16(alarm_duty(temperature_c, hardware_alert_ok, now_ms))
def close(self):
self.pwm.duty_u16(0)
self.pwm.deinit()