Skip to content

Configurable PWM frequency, full-duty MAX_PWM default, track voltage warning (v2.4.0)#9

Open
yamanote1138 wants to merge 3 commits into
mainfrom
feature/configurable-pwm-freq
Open

Configurable PWM frequency, full-duty MAX_PWM default, track voltage warning (v2.4.0)#9
yamanote1138 wants to merge 3 commits into
mainfrom
feature/configurable-pwm-freq

Conversation

@yamanote1138

@yamanote1138 yamanote1138 commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Motor PWM frequency (PWM_FREQ) is now a secrets.ini build flag instead of a hardcoded 20kHz, following the existing MAX_PWM pattern. Currently testing at 32kHz on hardware.
  • Compile-time ceiling: build fails with #error above 40kHz, since analogWrite on ESP8266 is software PWM sharing one hardware timer across all 4 active channels (motor + R/G/B status LED) — too high starves the WiFi/WebSocket stack.
  • MAX_PWM default raised 500 → 1000 (full duty resolution / full track voltage) in secrets.ini.example.
  • Track voltage over 10V now renders bold/red in both the debug panel and the main throttle UI's "Track:" readout — most users won't open the debug view unless something's already wrong. trackVoltage/trackVoltageDanger are shared computeds in useTrainController so both spots derive from one source of truth.
  • docs/BUILD.md updated to document both PWM_FREQ and the new MAX_PWM default.
  • Version bumped to 2.4.0 (firmware VERSION macro + frontend package.json/package-lock.json).

Test plan

  • pio test -e native — 38/38 passed
  • pio run -e d1_mini — builds clean at PWM_FREQ=32000
  • Verified the 40kHz ceiling actually rejects the build (tested at 50000, got the expected #error)
  • npm test (frontend) — 13/13 passed
  • npm run build (frontend) — builds clean
  • On-hardware verification of 32kHz PWM — looking good, confirmed track voltage warning shows correctly at 90% throttle

… track voltage

- Motor PWM frequency now comes from PWM_FREQ in secrets.ini instead of a
  hardcoded 20kHz, following the existing MAX_PWM build-flag pattern.
- Add a compile-time ceiling (#error above 40kHz) since analogWrite on
  ESP8266 is software PWM sharing one timer across all 4 active channels
  (motor + R/G/B status LED) — too high starves the WiFi/WebSocket stack.
- Bump MAX_PWM 500 -> 1000 in secrets.ini.example for full duty resolution.
- Debug panel: bold/red Track Voltage when it exceeds 10V.
Most users won't open the debug view unless something's already wrong.
Extracted trackVoltage/trackVoltageDanger as shared computeds in
useTrainController so the "Track:" readout in SpeedController and the
debug panel's row both derive from one source of truth instead of each
reimplementing the 12V * speed and >10V threshold logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant