tooling: sync bench + debug console to live STM32 protocol
The mppt-testbench Python tooling had drifted from the flashed firmware
(bundled fw e7a23a3 vs live 1b85532) and could no longer communicate:
- stm32_link.py: CRC8 -> CRC-16/CCITT-FALSE; telemetry 68B -> 78B
(btemp, cmp_outer/inner, iout_slow, vfly_ofs_applied); add PTYPE_INT16
and commands 0x12-0x18; replace PARAMS with the current 37-param map
(single dt_normal, no dt brackets; test_corr/phase_ofs, phase PI,
precharge PI, duty dither; vfly_active 0-3).
- tuner.py: retire per-bracket deadtime; sweep the single dt_normal.
- cli.py: update tune-deadtime, help/examples, btemp readout;
default ports COM11 (load) / COM4 (stm32).
- debug console TUI: sync protocol.py/app.py/status_bar/telemetry_panel
from live (new command keys, link RX/TX/loss stats, single dead-time,
new telemetry fields, param-write auto-retry); add duty_fft.py.
- README: rewrite parameter table, deadtime section, ports, keybindings.
Verified: protocol round-trip self-tests + live `bench stm32-read`
reading all 37 params over COM4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ Unified tool for testing and tuning MPPT (Maximum Power Point Tracking) converte
|
||||
+------------------+
|
||||
|
|
||||
STM32 debug
|
||||
serial (COM28)
|
||||
serial (COM4)
|
||||
|
||||
HIOKI EFF1 = P6 / P5 x 100% (output power / input power)
|
||||
```
|
||||
@@ -50,7 +50,7 @@ uv sync
|
||||
uv run bench identify
|
||||
|
||||
# Check STM32 responds (reads params + telemetry)
|
||||
uv run bench stm32-read --stm32-port COM28
|
||||
uv run bench stm32-read --stm32-port COM4
|
||||
```
|
||||
|
||||
### 2. Configure instruments for MPPT testing
|
||||
@@ -177,21 +177,23 @@ uv run bench tune-param \
|
||||
--settle 3.0
|
||||
```
|
||||
|
||||
#### Auto-optimize all deadtime brackets
|
||||
#### Optimize the global dead-time
|
||||
|
||||
Automatically sweeps deadtime for each of the 6 current brackets (0-3A, 3-5A, 5-10A, 10-20A, 20-30A, 30-45A), setting an appropriate load for each bracket.
|
||||
The firmware uses a single global dead-time (`dt_normal`). `tune-deadtime` sweeps
|
||||
it from `--dt-start` to `--dt-stop`, optionally at several `--load-values`, and
|
||||
picks the highest-efficiency value.
|
||||
|
||||
```bash
|
||||
# Sweep and report best values
|
||||
# Sweep at a single load and report the best value
|
||||
uv run bench tune-deadtime \
|
||||
--voltage 60 --current-limit 20 --load-mode CP \
|
||||
--dt-start 14 --dt-stop 50 --dt-step 1 \
|
||||
-o deadtime_results.csv
|
||||
|
||||
# Sweep, report, and apply best values to STM32
|
||||
# Sweep across several loads, then apply the best dt_normal to the STM32
|
||||
uv run bench tune-deadtime \
|
||||
--voltage 60 --current-limit 20 --load-mode CP \
|
||||
--load-values 20,50,100,250,400,600 \
|
||||
--load-values 100,300,500 \
|
||||
--apply
|
||||
```
|
||||
|
||||
@@ -213,10 +215,12 @@ For live monitoring and parameter tuning via the Textual terminal UI:
|
||||
|
||||
```bash
|
||||
cd code64
|
||||
uv run debug-console COM28
|
||||
uv run debug-console COM4
|
||||
```
|
||||
|
||||
Keybindings: `p` ping, `r` read params, `f` toggle EMA filter, `l` show log path, `q` quit.
|
||||
Keybindings: `p` ping, `f` toggle EMA filter, `s` shutoff, `x` reset, `t` 50% duty test,
|
||||
`c` relay on, `d` relay off, `h` hold converter, `g` toggle precharge, `q` quit.
|
||||
Parameter writes are auto-retried until ACKed (the MCU's RX is EMI-lossy while switching).
|
||||
|
||||
### 10. Direct instrument control
|
||||
|
||||
@@ -270,34 +274,49 @@ uv run bench [-h] [--supply-address ADDR] [--load-port PORT] [--load-baud BAUD]
|
||||
| Option | Default | Description |
|
||||
|---|---|---|
|
||||
| `--supply-address` | auto-detect | IT6500D VISA address |
|
||||
| `--load-port` | `COM1` | Prodigit 3366G serial port |
|
||||
| `--load-port` | `COM11` | Prodigit 3366G serial port |
|
||||
| `--load-baud` | `115200` | Prodigit 3366G baud rate |
|
||||
| `--meter-address` | auto-detect | HIOKI 3193-10 VISA address |
|
||||
| `--timeout` | `5000` | VISA timeout in milliseconds |
|
||||
| `--stm32-port` | `COM28` | STM32 debug serial port |
|
||||
| `--stm32-port` | `COM4` | STM32 debug serial port |
|
||||
| `--stm32-baud` | `460800` | STM32 debug baud rate |
|
||||
|
||||
## Tunable STM32 Parameters
|
||||
|
||||
Names, IDs, types and ranges mirror the firmware (`code64/debug_console/protocol.py`).
|
||||
|
||||
| Parameter | Type | Range | Description |
|
||||
|---|---|---|---|
|
||||
| `VREF` | uint16 | 3100-3700 | ADC reference voltage |
|
||||
| `vfly_kp` | float | -10 to 10 | Vfly proportional gain |
|
||||
| `vfly_ki` | float | -10 to 10 | Vfly integral gain |
|
||||
| `vfly_clamp` | uint16 | 0-10000 | Vfly integrator clamp |
|
||||
| `vfly_active` | uint8 | 0-1 | Vfly loop enable |
|
||||
| `VREF` | uint16 | 2340-3500 | ADC reference voltage |
|
||||
| `vfly_kp` | float | -10 to 10 | Vfly proportional gain (mode 1, duty asymmetry) |
|
||||
| `vfly_ki` | float | -10 to 10 | Vfly integral gain (mode 1) |
|
||||
| `vfly_kp_phase` | float | -10 to 10 | Vfly P gain (mode 2, master-phase offset) |
|
||||
| `vfly_phase_clamp` | uint16 | 0-10000 | Clamp on the master-phase offset (mode 2) |
|
||||
| `vfly_clamp` | uint16 | 0-10000 | Vfly integrator clamp (mode 1) |
|
||||
| `vfly_loop_trig` | uint16 | 1-10000 | Vfly loop counter trigger |
|
||||
| `vfly_active` | uint8 | 0-3 | Vfly mode: 0 off, 1 duty-asym PI, 2 phase P, 3 manual both |
|
||||
| `test_corr` | int16 | -3000 to 3000 | Manual duty-asymmetry correction (mode 3) |
|
||||
| `phase_ofs` | int16 | -3000 to 3000 | Master-phase offset: manual (mode 3), readback (mode 2) |
|
||||
| `cc_target` | float | 0-60000 | CC target (mA) |
|
||||
| `cc_gain` | float | -1 to 1 | CC proportional gain |
|
||||
| `cc_min_step` / `cc_max_step` | float | -1000-0 / 0-1000 | CC step clamps |
|
||||
| `cc_loop_trig` | uint16 | 1-10000 | CC loop counter trigger |
|
||||
| `cc_active` | int32 | 0-1 | CC loop enable |
|
||||
| `mppt_step` | float | 0-10000 | MPPT P&O step size (mA) |
|
||||
| `mppt_deadband` | float | 0-1 | MPPT deadband |
|
||||
| `mppt_step` | float | 1-200 | MPPT P&O step size |
|
||||
| `mppt_duty_min` / `mppt_duty_max` | float | 0-6800 | MPPT duty search bounds (CMP ticks) |
|
||||
| `mppt_loop_trig` | uint16 | 1-50000 | MPPT loop counter trigger |
|
||||
| `mppt_active` | int32 | 0-1 | MPPT loop enable |
|
||||
| `dt_0_3A` | uint8 | 14-200 | Deadtime 0-3A (HRTIM ticks) |
|
||||
| `dt_3_5A` | uint8 | 14-200 | Deadtime 3-5A |
|
||||
| `dt_5_10A` | uint8 | 14-200 | Deadtime 5-10A |
|
||||
| `dt_10_20A` | uint8 | 14-200 | Deadtime 10-20A |
|
||||
| `dt_20_30A` | uint8 | 14-200 | Deadtime 20-30A |
|
||||
| `dt_30_45A` | uint8 | 14-200 | Deadtime 30-45A |
|
||||
| `cv_threshold` / `cv_hysteresis` | float | 20000-30000 / 0-5000 | CV corner (mV) |
|
||||
| `cc_threshold` / `cc_hysteresis` | float | 0-55000 / 0-10000 | CC/Iout limit (mA) |
|
||||
| `dt_normal` | uint16 | 14-200 | Single global dead-time (dt register ticks) |
|
||||
| `override_duty` | uint16 | 716-6442 | Manual fixed-duty base (CMP ticks, D=10..90%) |
|
||||
| `manual_duty_en` | uint8 | 0-1 | Enter manual fixed-duty mode |
|
||||
| `precharge_kp` / `precharge_ki` | float | 0-100 / 0-10 | Closed-loop precharge PI gains |
|
||||
| `precharge_reg_en` | uint8 | 0-1 | Enable closed-loop precharge |
|
||||
| `dither_en` | uint8 | 0-1 | Enable duty dithering (de-stack-band avoidance) |
|
||||
| `dither_band_lo` / `dither_band_hi` | uint16 | 716-6442 | Forbidden duty band edges (CMP ticks) |
|
||||
| `dither_anear` / `dither_afar` | uint16 | 716-6442 | Out-of-band dither anchors |
|
||||
| `dither_dzero` | uint16 | 716-6442 | \|e\| fold center (D=0.5) |
|
||||
|
||||
## CSV Output Format
|
||||
|
||||
|
||||
Reference in New Issue
Block a user