Gauge drive day: CANNY comparison, cluster signal research, serial tools

Wiki: two new pages - canny-5-3-pico-gauge-drive (why the CANNY's 12V
negative output moved the needles and 3.3V push-pull could not; 2SK3069
low-side stage) and patrol-instrument-cluster (tach 2 ppr + trim -13
calibration, NTC temp sender curve, 20 kHz PWM flutter fix, and the
four-layer steppy-needle diagnosis ending at the cluster's ~150 rpm
count quantization, defeated with adaptive dither on B).

Tools: serial_logger.py (multi-port capture to wiki/raw), serial_cmd.py
(one-shot cfg commands to A), dual_serial_capture.py (bench snapshots),
tach_ramp.py / tach_ramp2.py (synthetic rpm sweeps via cfg override).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-23 11:12:20 +02:00
parent 974082cb3e
commit e9fc24778a
9 changed files with 360 additions and 21 deletions
+60
View File
@@ -0,0 +1,60 @@
---
type: synthesis
tags: [hardware, gauges, nissan-patrol, controller-b, electronics]
updated: 2026-09-22
---
# CANNY 5.3 pico vs ESP32-S3: driving the Patrol cluster
Why the user's old CANNY-based setup moves the Patrol tach and our ESP32 (Controller B, IO7) does not. Researched 2026-09-22 after the first in-car test of the dual-controller rig: temp needle parked mid-scale, tach dead ([[dual-controller-architecture]]).
## The working reference setup `(verified)`
The user previously drove this same instrument cluster with a **CANNY 5.3 pico** (Russian visual-PLC automotive controller, cannylogic.com / canny.ru), using **"Default Negative Output" in DIO mode on IO channel 8** (contact 4 — the channel that also carries the high-resolution PWM function). The cluster's needles respond in that setup — this is our known-good electrical reference.
## What the CANNY output stage is (source: cannylogic.com/docs/c53pico, canny.ru)
- Channels are **12 V-domain**: "output operating voltage on the controller channels matches the supply voltage" (7–16 V, 18 V abs max).
- Each channel is a **configurable-polarity switch**: "positive" mode connects the line to +12 V (high-side source), **"negative" mode connects the line to GND (low-side sink)**. Two strengths: weak ~1 mA (pull) and strong 100 mA.
- Rated for inductive/resistive/capacitive loads, 100 mA per channel, 300 mA total, automatic shutoff on over-current.
- "Negative output" therefore produces the classic automotive sender signal: the line is **pulled to ground when active and floats up to the cluster's own internal pull-up (~battery) when released** — a 0 ↔ ~12 V swing without the controller ever sourcing voltage.
## What our ESP32-S3 GPIO is
- **3.3 V push-pull** logic pin, absolute max ~3.6 V, source/sink a few tens of mA, no protection `(unverified — standard ESP32-S3 datasheet values)`.
- LEDC PWM on B's IO7 (tach square wave) and IO8 (temp duty) drives the line **actively to 3.3 V and 0 V** `(repo)`.
## Why this explains the test-day symptoms `(verified 2026-09-22 for the tach — needle tracks rpm through the 2SK3069 low-side stage; see [[patrol-instrument-cluster]] for calibration)`
- The Patrol tach input expects negative-going pulses on a line it pulls up internally toward battery. With the ESP32 push-pull output attached, the "high" half of every cycle is **3.3 V instead of ~12 V** — likely below the input threshold, so the tach sees no edges at all → dead needle, exactly what the CANNY's negative output provides and we don't.
- The temp gauge input is a sender-resistance-to-ground circuit. A 3.3 V push-pull PWM can bias it to some fixed effective level — a needle that parks at one position and ignores duty changes is consistent with this (mid-scale at 89 °C may have been coincidence, not the duty law working). Re-test after the drive stage is fixed before trusting the temp calibration in [[dual-controller-architecture]].
- **It is not PWM polarity in firmware**: a 50 % square wave is its own inverse, and inverted temp duty would move the needle backwards, not freeze it.
## The fix (per channel): replicate "negative output"
Small low-side switch between the ESP32 pin and the gauge line:
```
gauge line ──────────────┬──── (cluster's internal pull-up to ~12 V)
│
D (drain/collector)
ESP32 IOx ──[R ~1k]── G/B N-MOSFET (logic-level, e.g. 2N7002/AO3400) or NPN (2N2222 + base R)
S (source/emitter)
│
GND (common with cluster!)
```
- ESP32 high → line pulled to GND; ESP32 low → line released to the cluster's pull-up. This **inverts the logic**: tach unaffected (50 % square), temp duty becomes 255 − duty at the gauge — recalibrate `temp_slope`/`temp_offset` ([[dual-controller-architecture]] tunables) or invert in B's firmware.
- If the cluster input turns out to have no internal pull-up, add an external ~4.7–10 kΩ to +12 V.
- On hand (2026-09-22): a **2SK3069** (N-ch, 60 V / 75 A, 4 V-drive class) — hugely oversized but suitable; planned for the tach channel with 220 Ω gate series + 10 kΩ gate pulldown `(source: alltransistors.com 2SK3069)`.
- **Never** connect the 12 V-pulled gauge line directly to an ESP32 pin, including in open-drain mode — the pin is not 12 V tolerant.
- Grounds must be common: cluster GND ↔ Controller B GND.
## Open items
- Scope or multimeter the tach line at rest: does it float high (~12 V) with nothing attached? Confirms the internal pull-up assumption.
- After the transistor stage: re-run the override test (Force tach rpm / Force coolant duty on A's tuning screen) and re-derive the temp duty law; promote this page's hypothesis to `(verified)`.
## Related
[[dual-controller-architecture]] · [[nissan-patrol-swap]] · [[open-questions]]
+55
View File
@@ -0,0 +1,55 @@
---
type: entity
tags: [hardware, gauges, nissan-patrol, controller-b, electronics]
updated: 2026-09-22
---
# Patrol instrument cluster — signal expectations
What the target vehicle's cluster ([[nissan-patrol-swap]]) needs on its tach and temp inputs, from the first day of driving it with Controller B's outputs through the low-side FET stage ([[canny-5-3-pico-gauge-drive]]). Patrol generation still unidentified — Y60/GQ vs Y61/GU matters for gauge internals → [[open-questions]].
## Tachometer
- **Empirical calibration `(verified 2026-09-22)`: 2 pulses per revolution.** With the firmware's original `tach_ppr=4` the cluster read double; `cfg` ppr set to 2 makes it track the BMW's CAN rpm. Signal: 50 % square wave, low-side switched (2SK3069), i.e. 3000 rpm → 100 Hz.
- Background on what these clusters normally get `(source: patrol4x4.com / nissanpatrol.com.au threads)`:
- TD42 diesels had **no factory tach signal**; aftermarket/factory tachs run from the **alternator W terminal** (a phase tap — frequency scales with pulley ratio × pole pairs, far more than 2/rev, usually via an adapter box).
- A clean **2 ppr** expectation matches an **ECU-driven 4-cylinder-style tach input** (e.g. ZD30-era Y61) `(unverified)` — a hint the cluster may be from that generation, worth checking against the actual vehicle.
- Practical consequence: the doubled reading at ppr=4 was calibration, not a signal-quality problem. The FET stage works.
- **Scale calibration `(verified 2026-09-23, override ramps)`**: with ppr=2 the cluster over-reads by a factor that shrinks with rpm — ×1.20 at 1000–2000, ×1.15 at 6000 (commanded 6000 with trim −20 read exactly 5500). The response is mildly nonlinear, so a linear trim cannot be exact everywhere; **`tach_trim = −13 %` chosen as the realistic compromise** (user-tuned on the dial). Saved on A, pushed in CONFIG.
### The steppy-needle saga (2026-09-22/23) — resolved
Observed on the road: needle holds then jumps 200–500 rpm. Diagnosis took four firmware iterations on B, each eliminating one layer `(repo, verified by override ramp tests with ignition on / engine off)`:
1. **5 Hz staircase**: B refreshed the tach frequency once per 200 ms packet. Added a slew limiter (glide 25 %/20 ms). *Result: worse* — because of layer 2.
2. **LEDC restarts**: Arduino 2.x `ledcChangeFrequency()` re-inits the timer and truncates the waveform mid-period; calling it 50×/s corrupted the counting window constantly. Replaced LEDC with an esp_timer toggling IO7. *Result: better, not smooth* — because of layer 3.
3. **Task-dispatch jitter**: esp_timer callbacks run in a task; WiFi/ESP-NOW bursts on core 0 delay edges by ms and bunch them. Replaced with a **hardware-timer ISR** (1 MHz, auto-reload): phase-continuous, immune to scheduling. *Result: rock-steady at fixed rpm, but ramps still stepped* — because of layer 4, which is the cluster itself.
4. **Cluster count quantization** — the floor: on a clean 25 rpm/40 ms synthetic ramp the needle jumped alternately +100/+200 → the cluster counts pulses in **~150 rpm quanta** on a dial that rounds to 100. A perfectly stable synthetic frequency parks on a quantum and snaps to the next; a real engine's pulse jitter straddles the boundary so the damped needle averages in between — factory setups are smooth *because* their signal is dirty. Emulated with **random dither ±45 rpm (±1.2 Hz) per 20 ms tick**, with an **adaptive envelope** (full while the target moves, fades to zero within ~1.2 s at rest) so steady rpm stays flicker-free.
Final state (2026-09-23): sweep and hold "fairly good" per user; possible future refinement of dither constants (`DITHER_HZ`, envelope times in B's `gauge_outputs.cpp`). Also explains the CANNY's high-rpm jumpiness ([[canny-5-3-pico-gauge-drive]]): a PLC toggling on a ms-resolution timer gets coarse at ≥100 Hz output `(unverified)`.
## Temperature gauge
- The stock sender is an **NTC thermistor to ground** `(source: patrol4x4.com forum, sensorgal.com)`:
| Coolant | Sender resistance |
|---|---|
| 20 °C | 2.1–2.9 kΩ |
| 50 °C | 0.68–1 kΩ |
| 90 °C | 236–260 Ω |
The gauge is a current-measuring device; its useful span is roughly the "tens of Ω to a few kΩ" region. Duty-cycle PWM through a low-side switch emulates an average conductance in this range `(repo)`.
- **Needle flutter at `temp_pwm_hz` = 1 kHz — RESOLVED at 20 kHz `(verified 2026-09-22)`.** At 1 kHz the needle fluttered at any duty between the endpoints (steady at 0 and 255 — i.e. it was following the chopping itself); raising `temp_hz` to 20000 (the current firmware clamp) removed the fluctuation completely. Matches community experience that PWM-driven automotive gauges need tens-of-kHz `(source: allaboutcircuits.com, pjrc forum)`.
- Lesson from the same session: a **missing chassis/board common ground makes the gauge read nothing at all** — check grounds before debugging frequencies.
- Still open as optional hardening: a series resistor in the FET drain (~100–240 Ω) to bound the current swing to the sender's real range (full-on duty = dead short, i.e. "hotter than the sender can ever read").
- After the flutter is fixed, re-derive `temp_slope`/`temp_offset` against the sender table above (the FET inverts duty sense vs the direct-drive law used before).
## Open items
- Identify the Patrol generation / cluster origin (2 ppr hint above; ask the user / photograph the cluster).
- Temp law recalibration table (duty ↔ needle position ↔ implied °C) — gauge works and is stable at 20 kHz; the slope/offset mapping to real °C has not been re-derived since the FET stage inverted the duty sense.
- Tach dither constants may deserve another tuning pass ("maybe in the future we will get back to RPMs" — user, 2026-09-23).
## Related
[[canny-5-3-pico-gauge-drive]] · [[nissan-patrol-swap]] · [[dual-controller-architecture]] · [[open-questions]]