Skip to content

Commit

Permalink
split up debug data, vpv vmv fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Jan 24, 2025
1 parent 082fe4e commit 790d164
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
7 changes: 6 additions & 1 deletion Core/Inc/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ void segment_init(acc_data_t *bmsdata);
/**
* @brief Pulls all cell data from the segments and returns all cell data
*
* @todo make sure that retrieving cell data doesn't block code too much
*/
void segment_retrieve_data(acc_data_t *bmsdata);

/**
* @brief Fetch extra data for segment
*
*/
void segment_retrieve_debug_data(acc_data_t *bmsdata);

/**
* @brief Disables balancing for all cells.
*
Expand Down
17 changes: 11 additions & 6 deletions Core/Src/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void set_cell_discharge(cell_asic *chip, uint8_t cell, bool discharge);
void init_chip(cell_asic *chip)
{
set_REFON(chip, PWR_UP);
set_volt_adc_comp_thresh(chip, CVT_22_5mV);
// WARNING, THE ENUM IS WRONG, CHECK TABLE 102
set_volt_adc_comp_thresh(chip, CVT_45mV);
chip->tx_cfga.flag_d = 0;

// Short soak on ADAX
Expand Down Expand Up @@ -189,6 +190,7 @@ void segment_monitor_flts(cell_asic chips[NUM_CHIPS])
write_clear_flags(chips);
}

// ensure stuff used is in the correctfunction
void segment_retrieve_data(acc_data_t *bmsdata)
{
// read from ADC convs
Expand All @@ -197,14 +199,17 @@ void segment_retrieve_data(acc_data_t *bmsdata)
// check our fault flags
segment_monitor_flts(bmsdata->chips);

// check the RDSTAT, then clear it

// The GPIOs in the AUX registers contain voltage readings from the therms.
read_status_aux_registers(bmsdata->chips);

// read all therms using AUX 2
adc_and_read_aux2_registers(bmsdata->chips);
}
void segment_retrieve_debug_data(acc_data_t *bmsdata)
{
// poll stuff like vref, etc.
adc_and_read_aux_registers(bmsdata->chips);

// read the above into status registers
read_status_registers(bmsdata->chips);
}

bool segment_is_balancing(cell_asic chips[NUM_CHIPS])
{
Expand Down
14 changes: 8 additions & 6 deletions Core/Src/shep_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void vDebugMode(void *pv_params)

// read_serial_id(bmsdata->chips);

adc_and_read_aux2_registers(bmsdata->chips);
segment_retrieve_debug_data(bmsdata);

for (int chip = 0; chip < NUM_CHIPS; chip++) {
uint8_t num_cells =
Expand Down Expand Up @@ -149,7 +149,7 @@ void vDebugMode(void *pv_params)
(bmsdata->chips[chip].tx_cfgb.dcc >>
(cell + 1)) &
1);
osDelay(6);
osDelay(1000 / NUM_CHIPS);
}

// Send chip status messages
Expand All @@ -171,10 +171,11 @@ void vDebugMode(void *pv_params)
.stata.itmp) /
0.0075) -
273,
10000 * getVoltage(
10000 * 20 *
getVoltage( // VPV is ra_code 11 w/ different scale
bmsdata->chips[chip]
.raux
.ra_codes[9]));
.ra_codes[11]));
compute_send_beta_status_b_message(
10000 * getVoltage(
bmsdata->chips[chip]
Expand All @@ -186,10 +187,11 @@ void vDebugMode(void *pv_params)
chip,
10000 * getVoltage(bmsdata->chips[chip]
.statb.vr4k),
10000 * getVoltage(
10000 * 20 *
getVoltage( // VMV is ra_code 10
bmsdata->chips[chip]
.raux
.ra_codes[8]));
.ra_codes[10]));
} else {
compute_send_alpha_status_a_message(
bmsdata->chip_data->on_board_temp, chip,
Expand Down

0 comments on commit 790d164

Please sign in to comment.