Link protocol v2 receiver, ESP-NOW leg, Patrol gauge outputs, gear pulse
- protocol header v2 copied byte-identical from the 5B repo - uart_receiver: processFrame() shared by the UART framing task and ESP-NOW, version check, dedupe on packet_id+timestamp, per-transport liveness, CONFIG cache with sequence number - espnow_receiver: STA mode, channel hopping while silent, locks on frames - gauge_outputs: tach on IO7 (LEDC ch2, 14-bit), coolant PWM on IO8 (LEDC ch4, 8-bit), config cached in NVS, overrides applied but not saved - main: gear label from lever + engaged/target (pulses while shifting, red on mismatch), icons driven by A's alert bits, gauge update at 5 Hz, link stats - wiki: temp_stage.cfd (user's old CANNY program) decoded as prior art; controller-link, link-redundancy, patrol-gauge-outputs, open-questions updated with the bench-verified v2 results and calibration procedure Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -16,15 +16,18 @@ Controller A (5B) has no free native GPIO on any header: the RGB LCD, I2C, CAN,
|
||||
|
||||
| Gauge | What the cluster expects | What B must generate | Status |
|
||||
|---|---|---|---|
|
||||
| Tachometer | a pulse train whose **frequency** tracks engine speed; the source and pulses-per-revolution depend on the cluster variant | variable-frequency square wave at ~50 % duty, on one LEDC channel with its **own timer** | source data (RPM from CAN 0x0AA) verified on A `(sibling: 5B wiki → can-id-candidates)`; **not yet in the packet** |
|
||||
| Tachometer | a pulse train whose **frequency** tracks engine speed — **4 pulses per revolution** on this cluster (user, 2026-09-21; not yet bench-verified) | variable-frequency square wave at ~50 % duty, on one LEDC channel with its **own timer** | source data (RPM from CAN 0x0AA) verified on A `(sibling: 5B wiki → can-id-candidates)`; **not yet in the packet** |
|
||||
| Coolant temp | a moving-coil/bimetal gauge that reads the **resistance to ground** of the sender | fixed-frequency PWM with variable **duty** into a low-side switch, so the gauge integrates it as an average resistance | coolant already in the packet as 0.1 °C |
|
||||
|
||||
The two need separate LEDC timers because one varies frequency and the other varies duty. ESP32-S3 LEDC has 8 channels on 4 timers `(unverified — datasheet figure from memory, confirm)`.
|
||||
|
||||
## Proposed pin assignment (unverified — proposal only)
|
||||
## Pin assignment (implemented 2026-09-21)
|
||||
|
||||
- **IO7** → tachometer pulse output
|
||||
- **IO8** → coolant gauge PWM output
|
||||
- **IO7** → tachometer pulse output — LEDC channel 2 (timer 1), **14-bit** resolution so the divider reaches low frequencies (~4.8 Hz .. ~4.9 kHz; 8-bit could not even do 100 Hz), 50 % duty
|
||||
- **IO8** → coolant gauge PWM output — LEDC channel 4 (timer 2), 8-bit duty at `temp_pwm_hz` (default 1 kHz)
|
||||
- LEDC channels 0/1 (timer 0) belong to the display backlight; never reuse them `(repo)`
|
||||
|
||||
**Bench-verified 2026-09-21** `(verified)`: with A's default 89 °C coolant, B drives IO8 at duty 183/255 (1.5·89 + 50); `cfg override rpm 2000` on A's console produced 133.3 Hz on IO7 (2000 × 4 / 60), and clearing it dropped the output. Both outputs stay low with no link or no valid value. Still unverified: the **needle** — nothing is connected to the cluster yet and the external driver stage does not exist.
|
||||
|
||||
Both on the right header, adjacent to GND-free pins, so add a ground wire from the left header. IO3 deliberately avoided (strapping pin). IO1 stays the UART RX.
|
||||
|
||||
@@ -36,11 +39,73 @@ Both on the right header, adjacent to GND-free pins, so add a ground wire from t
|
||||
- **Temp gauge**: sender wire goes to ground through the sender's thermistor. Emulate it with a logic-level N-MOSFET (or NPN) pulling the sender wire to ground under PWM, plus a series resistor sized so 100 % duty corresponds to the hottest resistance you want to show. The gauge's thermal/mechanical lag averages the PWM; use a few hundred Hz to 1 kHz so nothing flickers. Calibration is a lookup table from °C → duty, built empirically against the needle.
|
||||
- Optocouplers between B and the 12 V cluster side are cheap insurance; the 5B's own DO stage (PC817 → transistor) is a reasonable pattern to copy.
|
||||
|
||||
## Characterising the gauges (procedure, unverified until run)
|
||||
|
||||
The coolant gauge is a **current meter, not a pulse input** — there is no pulse count to find. The sender is a thermistor to ground; the needle follows the current through the gauge coil, which follows the sender's resistance. What has to be measured is the resistance → needle curve.
|
||||
|
||||
Coolant gauge, ignition on, engine off, sender disconnected:
|
||||
1. 1 kΩ linear pot (or decade box, or fixed 47/100/220/470 Ω) from the sender wire to chassis ground. Sweep; record the resistance at the cold mark, middle, hot mark and start of the red zone (read the pot disconnected).
|
||||
2. At each point also record the sender-wire voltage. Constant regardless of resistance → regulated supply, bimetal gauge. Proportional drop → plain series coil.
|
||||
3. Needle lag of seconds → bimetal; near-instant → air core. Both average PWM; bimetal is more forgiving.
|
||||
4. Series current at the hot-mark resistance = the peak the MOSFET stage must sink (expect tens of mA).
|
||||
|
||||
PWM drive from the curve:
|
||||
- Logic-level N-MOSFET low side, drain to the sender wire through a fixed resistor equal to the hottest resistance ever to be shown; 100 % duty = hottest reading, the gauge integrates lower duties.
|
||||
- 500 Hz – 2 kHz. Older Nissan clusters feed gauges from a chopped instrument voltage regulator at a few Hz `(unverified)`; PWM near that rate beats against it. Scope the sender wire once to see whether the chopper exists.
|
||||
- Build the °C → duty lookup from where the needle actually lands at each duty step, not from any sender datasheet.
|
||||
|
||||
Tachometer, 4 ppr: f = rpm × 4 / 60 → ~47 Hz at 700 rpm, ~267 Hz at 4000 rpm. Before wiring: measure the tach input's open-circuit voltage with ignition on — battery voltage means the cluster has its own pull-up (open-collector output suffices); near zero means add a pull-up to 12 V. Verify the needle at two known LEDC frequencies before trusting the scaling.
|
||||
|
||||
## Prior art: the user's CANNY 5.3 pico program (source: temp-stage-cfd)
|
||||
|
||||
The user drove this gauge before, from the BMW CAN bus, with a CannyLab program → [[temp-stage-cfd]]. Recovered from the file:
|
||||
|
||||
- Same decode the 5B later verified: CAN 0x1D0 byte 0, raw − 48 °C.
|
||||
- **Duty = 1.5 × T + 50 on a 0–255 scale**, i.e. 110/255 at 40 °C, 200/255 at 100 °C, saturating near 137 °C. Duty *rises* with temperature (NTC sender emulation).
|
||||
- Output only enabled above a minimum temperature (constant 0 in the file, 40 °C in the comment).
|
||||
- Output was the controller's own push-pull pin with PWM pull-up enabled; the external circuit and the PWM frequency are **not** in the file.
|
||||
|
||||
Starting point for the LEDC implementation: 8-bit duty, `duty = clamp(1.5·T + 50, 0, 255)`, output disabled while the coolant value is invalid or the link is down. Verify against the needle before trusting it — the old drive circuit may differ from the new MOSFET stage, which shifts the whole curve.
|
||||
|
||||
## Tuning parameters — declared on A, executed on B (implemented 2026-09-21)
|
||||
|
||||
Calibration lives on Controller A (NVS; the **Gauge Tuning touchscreen page** — Home → right → Driveline → right — or the `cfg` serial console) and is pushed to B in CONFIG frames; B executes and caches the last config in its own NVS. `link_config_t` in the shared protocol header:
|
||||
|
||||
| Group | Parameter | Default | Note |
|
||||
|---|---|---|---|
|
||||
| Tach | pulses per rev | 4 | user figure |
|
||||
| Tach | fine trim % | 0 | needle reads N % off at a known rpm |
|
||||
| Tach | min / max output Hz | tbd | clamp against bad rpm values |
|
||||
| Temp | PWM frequency Hz | **unknown** | from the CANNY measurement ([[temp-stage-cfd]]) |
|
||||
| Temp | duty slope, offset (fixed-point) | 1.5, 50 | from the CANNY law |
|
||||
| Temp | min temperature gate °C | 40 | output off below |
|
||||
| Temp | duty clamp | 255 | |
|
||||
| Both | output enable | on | per gauge |
|
||||
| Both | **calibration override** | off | force a fixed rpm / fixed duty from A's screen and watch the needle |
|
||||
|
||||
Transport: CONFIG frames in protocol v2, sent on start, on every change (`cfg_version` bump) and every 5 s; overrides are pushed but never saved on either side. Console: `cfg show`, `cfg set <name> <value>`, `cfg override rpm <n> | duty <n> | both <rpm> <duty> | off`, `cfg reset` → [[controller-link]].
|
||||
|
||||
Measuring the CANNY's PWM without a scope: use a free 1.3 header GPIO with the ESP32 pulse-counter peripheral as a frequency/duty meter (resistor divider if the CANNY output exceeds 3.3 V). Same sketch later verifies B's own outputs. Planned as a separate PlatformIO environment in this repo.
|
||||
|
||||
## Calibration procedure (touchscreen or console)
|
||||
|
||||
Tachometer, with the driver stage on the tach wire:
|
||||
1. Force 1000 rpm (override). The needle should read 1000.
|
||||
2. A constant-factor error means the wrong pulses/rev — change it until 1000 reads 1000.
|
||||
3. Force 3000 rpm; a small residual is the trim (%).
|
||||
4. Override off.
|
||||
|
||||
Coolant gauge, with the MOSFET stage on the sender wire:
|
||||
1. Force duty 110 (the CANNY program's 40 °C point) and note the needle; sweep 140 / 170 / 200 / 230.
|
||||
2. From two marks (Tc at duty A, Th at duty B): slope = (B − A)/(Th − Tc), offset = A − slope × Tc; enter slope × 100 and offset.
|
||||
3. Needle flicker or wander → raise PWM frequency. No response at all → driver stage / pull-up, not the numbers.
|
||||
4. Override off. Values are saved on A and pushed to B at once.
|
||||
|
||||
## What must be established before any of this is wired
|
||||
|
||||
1. **Which Patrol cluster** (Y60/Y61, petrol vs diesel). Diesel clusters were fed from the alternator W-terminal at a much higher frequency and often have a calibration trimmer; petrol clusters expect ~3 pulses/rev for a 6-cylinder from the ignition system `(unverified)`. This fixes the frequency range and therefore the LEDC resolution/prescaler. → [[open-questions]]
|
||||
1. **Which Patrol cluster** (Y60/Y61, petrol vs diesel). User states **4 pulses/rev** (2026-09-21); confirm on the bench with the procedure above, since diesel clusters fed from an alternator W-terminal and petrol clusters fed from ignition differ `(unverified)`. This fixes the frequency range and therefore the LEDC resolution/prescaler. → [[open-questions]]
|
||||
2. Whether the cluster's tach input has an internal pull-up, and to what voltage (meter it).
|
||||
3. The temp sender's resistance-vs-temperature curve as the gauge sees it (meter the original sender at cold/hot, or sweep a pot until the needle sits at known marks).
|
||||
3. The temp sender's resistance-vs-temperature curve as the gauge sees it (meter the original sender at cold/hot, or sweep a pot until the needle sits at known marks). The CANNY-era duty law in [[temp-stage-cfd]] is the starting table; it still needs a needle check with the new driver stage, plus the old circuit's series resistor and PWM frequency.
|
||||
4. Protocol change: add `engine_rpm` (u16, 1/min) and a `valid_flags` bit to the packet; bump the version on both repos → [[controller-link]].
|
||||
5. The outage policy: what the needles do when the link is lost → [[link-redundancy]].
|
||||
|
||||
|
||||
Reference in New Issue
Block a user