diff --git a/docs/BUILD.md b/docs/BUILD.md index ff9177a..b97df58 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -38,7 +38,7 @@ node --version # v18+ required ```bash cp secrets.ini.example secrets.ini ``` - Edit `secrets.ini` with your WiFi SSID and password. Optionally change the mDNS hostname (default: `ztrain`) and `MAX_PWM` to tune top speed (default: `500` — about half voltage to the track, which is plenty for Z-scale). These are plain PlatformIO `build_flags` (`-D WIFI_SSID='"..."'` etc. — note the single-quote wrapping, required so values with spaces survive PlatformIO's flag tokenizer) merged in via `extra_configs` in `platformio.ini` — `secrets.ini` is gitignored, so nothing here ever gets committed. + Edit `secrets.ini` with your WiFi SSID and password. Optionally change the mDNS hostname (default: `ztrain`), `MAX_PWM` to tune top speed (default: `1000` — full voltage to the track), and `PWM_FREQ` to tune the motor's PWM switching frequency in Hz (default: `20000` — above the audible range, so the motor doesn't whine). `analogWrite` on the ESP8266 is software PWM sharing one hardware timer across all 4 active channels (motor + R/G/B status LED), so pushing `PWM_FREQ` too high risks starving the WiFi/WebSocket stack — the build fails outright above `40000` as a safety ceiling. These are plain PlatformIO `build_flags` (`-D WIFI_SSID='"..."'` etc. — note the single-quote wrapping, required so values with spaces survive PlatformIO's flag tokenizer) merged in via `extra_configs` in `platformio.ini` — `secrets.ini` is gitignored, so nothing here ever gets committed. 3. **Install frontend dependencies:** ```bash diff --git a/firmware/z-duino/z-duino.ino b/firmware/z-duino/z-duino.ino index 59c5b1a..9f85c1b 100644 --- a/firmware/z-duino/z-duino.ino +++ b/firmware/z-duino/z-duino.ino @@ -11,7 +11,15 @@ #include #include -#define VERSION "2.3.0" +#define VERSION "2.4.0" + +// analogWrite on ESP8266 is software PWM sharing one hardware timer across +// all 4 active channels (motor + R/G/B status LED). Above ~40kHz the +// interrupt load starts contending with the WiFi/WebSocket stack, risking +// jitter and dropped connections. +#if PWM_FREQ > 40000 +#error "PWM_FREQ exceeds the 40kHz safe ceiling for this board's shared software-PWM timer" +#endif // WiFi credentials from secrets.ini char wifi_ssid[] = WIFI_SSID; @@ -186,8 +194,8 @@ void setup() { pinMode(stby, OUTPUT); digitalWrite(stby, HIGH); - // PWM config: 20kHz (above audible range), 0-1000 range - analogWriteFreq(20000); + // PWM config: frequency from secrets.ini (above audible range), 0-1000 range + analogWriteFreq(PWM_FREQ); analogWriteRange(1000); // Initialize LittleFS diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 28ea4e0..20a9b5f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "z-duino-frontend", - "version": "2.3.0", + "version": "2.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "z-duino-frontend", - "version": "2.3.0", + "version": "2.4.0", "dependencies": { "@nuxt/ui": "^4.5.1", "tailwindcss": "^4.2.1", diff --git a/frontend/package.json b/frontend/package.json index 2000aa0..c5ee93a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "z-duino-frontend", - "version": "2.3.0", + "version": "2.4.0", "private": true, "type": "module", "scripts": { diff --git a/frontend/src/components/DebugModal.vue b/frontend/src/components/DebugModal.vue index 0df4d69..6c87358 100644 --- a/frontend/src/components/DebugModal.vue +++ b/frontend/src/components/DebugModal.vue @@ -19,7 +19,7 @@ :class="i % 2 === 0 ? 'bg-neutral-800/50' : ''" > {{ row.label }} - {{ row.value }} + {{ row.value }} @@ -34,7 +34,7 @@ import { useTrainController } from '../composables/useTrainController' const { getDebugInfo } = useTrainController() const isOpen = ref(false) -const rows = ref<{ label: string; value: string }[]>([]) +const rows = ref<{ label: string; value: string; danger?: boolean }[]>([]) function open() { rows.value = getDebugInfo() diff --git a/frontend/src/components/SpeedController.vue b/frontend/src/components/SpeedController.vue index c66d92c..06ab812 100644 --- a/frontend/src/components/SpeedController.vue +++ b/frontend/src/components/SpeedController.vue @@ -4,7 +4,7 @@
Speed: {{ currentSpeed === 0 ? 'stopped' : Math.round(currentSpeed * 100) + '%' }} - Track: {{ (12 * currentSpeed).toFixed(1) }}V + Track: {{ trackVoltage.toFixed(1) }}V