diff --git a/Core/Advance_Control/FBKW.c b/Core/Advance_Control/FBKW.c index 27713a6..90a0dc4 100644 --- a/Core/Advance_Control/FBKW.c +++ b/Core/Advance_Control/FBKW.c @@ -134,8 +134,6 @@ void FBKW_init(void) { fbkw_getters.ctx = NULL; pwm_init(&fbkw_rt, &pwm_cal_rom, &pwm_flash_rom, &fbkw_getters); - fbkw_rt.setpoint_offset = (int16_t)0xFD66; - } void FBKW_service(void) { diff --git a/Core/Advance_Control/cal_tables_rom.c b/Core/Advance_Control/cal_tables_rom.c index e401f67..5a94bb7 100644 --- a/Core/Advance_Control/cal_tables_rom.c +++ b/Core/Advance_Control/cal_tables_rom.c @@ -3,13 +3,13 @@ * @brief ROM-extracted calibration data for the VP44 PWM controller (compact). * * AUTO-GENERATED by tools/extract_calibration.py - * Source ROM: rom_eeprom_dump_004002_0x0000-40960.bin + * Source ROM: rom_eeprom_dump_0000-9FFF_004002.bin * Calibration base (RWA4): 0x9C28 * Flash anchor: 0x9618 - * Generated: 2026-04-17 22:03:12 + * Generated: 2026-04-18 13:52:55 * * DO NOT EDIT — regenerate with: - * python tools/extract_calibration.py rom_eeprom_dump_004002_0x0000-40960.bin --target compact + * python tools/extract_calibration.py rom_eeprom_dump_0000-9FFF_004002.bin --target compact */ #include "cal_tables_rom.h" @@ -119,6 +119,11 @@ const pwm_calibration_t pwm_cal_rom = { .closed_loop_gain_const = 4, /* CAL+0x0156 */ .error_persist_init_count = 100, /* CAL+0x0108 */ .recovery_rpm_threshold = 4194, /* CAL+0x011A */ + + /* Setpoint offset latched at init by FUN_8643 (0x867d): + * CAL[0x52]=2167 - CAL[0x54]=2833 = -666 + * (RAM[0x0430] always 0, so omitted). */ + .setpoint_offset = (int16_t)0xFD66, /* CAL+0x0052 - CAL+0x0054 */ }; /* ── ROM-extracted flash tables (rebased from FLASH:xxxx) ───────────── */ diff --git a/Core/Advance_Control/cal_tables_rom.h b/Core/Advance_Control/cal_tables_rom.h index 340798a..c3bf61a 100644 --- a/Core/Advance_Control/cal_tables_rom.h +++ b/Core/Advance_Control/cal_tables_rom.h @@ -3,11 +3,11 @@ * @brief Extern declarations for ROM-extracted calibration data (compact). * * AUTO-GENERATED by tools/extract_calibration.py - * Source ROM: rom_dump_0000-9FFF.bin + * Source ROM: rom_eeprom_dump_0000-9FFF_004002.bin * Calibration base (RWA4): 0x9C28 * * DO NOT EDIT — regenerate with: - * python tools/extract_calibration.py rom_dump_0000-9FFF.bin --target compact + * python tools/extract_calibration.py rom_eeprom_dump_0000-9FFF_004002.bin --target compact */ #ifndef CAL_TABLES_ROM_H #define CAL_TABLES_ROM_H diff --git a/Core/Advance_Control/pwm.c b/Core/Advance_Control/pwm.c index a3cba5a..7d36c8c 100644 --- a/Core/Advance_Control/pwm.c +++ b/Core/Advance_Control/pwm.c @@ -63,6 +63,7 @@ static void apply_calibration(pwm_runtime_t *rt, const pwm_calibration_t *c) rt->upper_integrator_gain = c->pi_upper_integrator_gain; rt->center_integrator_gain = c->pi_center_integrator_gain; rt->lower_integrator_gain = c->pi_lower_integrator_gain; + rt->setpoint_offset = c->setpoint_offset; } void pwm_init(pwm_runtime_t *rt, @@ -139,14 +140,11 @@ static void setpoint_compute(pwm_runtime_t *rt, const pwm_calibration_t *cal) rt->compensation_angle = (int16_t)(rt->compensation_angle + s_combine(cal->y_pair[2], &rt->setpoint_slot_x, &rt->setpoint_slot_y)); - //comp angle is 02b6 - - int16_t sum = (int16_t)(rt->inputs.b_fb_kw + rt->compensation_angle); int16_t half = shra16(sum, 1); /* SHRA — signed halve */ - rt->pre_offset_target = half; //this is 012a + rt->pre_offset_target = half; - int16_t t = (int16_t)(half + rt->setpoint_offset); // offset is 0150 + int16_t t = (int16_t)(half + rt->setpoint_offset); if (t < cal->target_minimum) t = cal->target_minimum; rt->target = t; } @@ -518,6 +516,7 @@ const pwm_calibration_t pwm_cal_default = { .pi_upper_integrator_gain = 1024, .pi_center_integrator_gain = 1024, .pi_lower_integrator_gain = 2048, + .setpoint_offset = 0, /* CAL+0x52 - CAL+0x54 — populated from ROM */ }; const pwm_flash_t pwm_flash_default = { diff --git a/Core/Advance_Control/pwm.h b/Core/Advance_Control/pwm.h index 4cd26bb..0cc2d6f 100644 --- a/Core/Advance_Control/pwm.h +++ b/Core/Advance_Control/pwm.h @@ -202,6 +202,12 @@ struct pwm_calibration { /* fast_recovery tuning */ int16_t error_persist_init_count; /* CAL+0x0108 */ int16_t recovery_rpm_threshold; /* CAL+0x011A */ + + /* Setpoint offset latched once at init by FUN_8643 (0x867d): + * RAM[0x0150] = CAL[0x52] - (CAL[0x54] + RAM[0x0430]) + * RAM[0x0430] is observed as always 0 at runtime, so the effective + * constant is CAL[0x52] - CAL[0x54]. */ + int16_t setpoint_offset; /* CAL+0x0052 - CAL+0x0054 (RAM 0x0150) */ }; /* ── Flash-resident tables ──────────────────────────────────────────── */