Skip to content

Commit 20374a7

Browse files
committed
adbms voltage getter
1 parent 49217e8 commit 20374a7

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

BMS/Core/User/Src/FEB_Commands.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,44 @@ static void cmd_canstatus_csv(int argc, char *argv[])
999999
}
10001000
}
10011001

1002+
/* ============================================================================
1003+
* Subcommand: volts - ADBMS6830 supply/reference voltages (VREF2/VA/VD/ITMP)
1004+
*
1005+
* Triggers an ADSTAT-all conversion, briefly waits, then reads STATA + STATB
1006+
* for every IC in the daisy chain and prints a per-IC table.
1007+
* ============================================================================ */
1008+
static void subcmd_volts(int argc, char *argv[])
1009+
{
1010+
(void)argc;
1011+
(void)argv;
1012+
1013+
/* Trigger ADSTAT-all (CH=0). The ADBMS6830 datasheet opcode for a status
1014+
* conversion of all channels is 0x0468. Sent directly because the repo's
1015+
* `#define ADSTAT 0x0570` in FEB_CMDCODES.h is a pre-existing mistake — it
1016+
* collides with CMD_START_AUX_ADC and is unused (ADBMS6830B_adax builds
1017+
* its own bytes). Wait ~1 ms for the conversion to settle. */
1018+
ADBMS_SendCmd(0x0468);
1019+
osDelay(pdMS_TO_TICKS(1));
1020+
1021+
FEB_Console_Printf("\r\n=== ADBMS6830 Supply Voltages ===\r\n");
1022+
FEB_Console_Printf("IC VREF2(V) VA(V) VD(V) ITMP(C)\r\n");
1023+
1024+
for (uint8_t ic = 0; ic < FEB_NUM_IC; ic++)
1025+
{
1026+
ADBMS_STATA_t a = {0};
1027+
ADBMS_STATB_t b = {0};
1028+
ADBMS_ReadReg(RDSTATA, ic, a.raw);
1029+
ADBMS_ReadReg(RDSTATB, ic, b.raw);
1030+
1031+
float vref2 = ADBMS_CodeToVoltage_mV(a.values.VREF2) / 1000.0f;
1032+
float va = ADBMS_CodeToVoltage_mV(a.values.VA) / 1000.0f;
1033+
float vd = ADBMS_CodeToVoltage_mV(b.bits.VD) / 1000.0f;
1034+
float itmp = ADBMS_CodeToTemp_C(a.values.ITMP);
1035+
1036+
FEB_Console_Printf("%-2u %7.3f %7.3f %7.3f %6.1f\r\n", (unsigned)ic, vref2, va, vd, itmp);
1037+
}
1038+
}
1039+
10021040
/* ============================================================================
10031041
* Command Descriptors
10041042
*
@@ -1088,15 +1126,20 @@ static const FEB_Console_Cmd_t bms_reg_cmd = {.name = "reg",
10881126
.handler = ADBMS_RegSubcmd,
10891127
.csv_handler = NULL,
10901128
.hidden = true};
1129+
static const FEB_Console_Cmd_t bms_volts_cmd = {.name = "volts",
1130+
.help = "ADBMS supply/reference voltages (VREF2/VA/VD/ITMP per IC)",
1131+
.handler = subcmd_volts,
1132+
.csv_handler = NULL,
1133+
.hidden = true};
10911134

10921135
/* Per-board subcommand table. cmd_bms iterates this for `BMS|<sub>` dispatch.
10931136
* Adding a subcommand: define its FEB_Console_Cmd_t above and append a pointer
10941137
* here. Registration auto-picks it up. */
10951138
static const FEB_Console_Cmd_t *const BMS_SUBCMDS[] = {
1096-
&bms_status_cmd, &bms_cells_cmd, &bms_temps_cmd, &bms_therm_raw_cmd, &bms_state_cmd,
1097-
&bms_balance_cmd, &bms_gpio_cmd, &bms_ivt_cmd, &bms_tasks_cmd, &bms_mem_cmd,
1098-
&bms_cell_cmd, &bms_spi_cmd, &bms_errors_cmd, &bms_config_cmd, &bms_ping_cmd,
1099-
&bms_pong_cmd, &bms_canstop_cmd, &bms_canstatus_cmd, &bms_cell_stats_cmd, &bms_reg_cmd,
1139+
&bms_status_cmd, &bms_cells_cmd, &bms_temps_cmd, &bms_therm_raw_cmd, &bms_state_cmd, &bms_balance_cmd,
1140+
&bms_gpio_cmd, &bms_ivt_cmd, &bms_tasks_cmd, &bms_mem_cmd, &bms_cell_cmd, &bms_spi_cmd,
1141+
&bms_errors_cmd, &bms_config_cmd, &bms_ping_cmd, &bms_pong_cmd, &bms_canstop_cmd, &bms_canstatus_cmd,
1142+
&bms_cell_stats_cmd, &bms_reg_cmd, &bms_volts_cmd,
11001143
};
11011144
#define BMS_SUBCMDS_COUNT (sizeof(BMS_SUBCMDS) / sizeof(BMS_SUBCMDS[0]))
11021145

BMS/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.1
1+
1.6.2

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.2
1+
1.6.3

0 commit comments

Comments
 (0)