Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4a993eb
Fix cell temp sanitizer
KSMehta11 Jul 6, 2026
9076ab6
Add cell temp sanitizer unit tests
KSMehta11 Jul 7, 2026
fcea6e0
Add mutexes
KSMehta11 Jul 7, 2026
4bef92b
Fix hv plate pec
KSMehta11 Jul 7, 2026
eb1bfb1
Updated driver submodule
KSMehta11 Jul 7, 2026
1a90493
Fix DTI regen current polarity
KSMehta11 Jul 7, 2026
8f3269c
Fault table fixes
KSMehta11 Jul 7, 2026
36e177a
Fix cell temp sanitizer flag
KSMehta11 Jul 7, 2026
7200bb1
State machine fixes
KSMehta11 Jul 8, 2026
5dfaa23
Fix ccl enforcement fault limit polarity
KSMehta11 Jul 8, 2026
e17201a
Fix fault table
KSMehta11 Jul 8, 2026
ca1fd7f
Fix ccl fault optype
KSMehta11 Jul 8, 2026
c56cf7d
Update dcl config for p50b
KSMehta11 Jul 8, 2026
b3ceb5e
Update ccl config for p50b
KSMehta11 Jul 8, 2026
93f169b
Update submodule
KSMehta11 Jul 13, 2026
ce23e3f
Update can codegen
KSMehta11 Jul 13, 2026
d467ae6
Add dti and charger voltage can msg parsing
KSMehta11 Jul 13, 2026
fe119a0
Remove board temp printf
KSMehta11 Jul 13, 2026
1e2710a
Fix state machine balancing check
KSMehta11 Jul 13, 2026
83e8435
Fix statemachine unit test
KSMehta11 Jul 13, 2026
ce8f567
Precharge updates
KSMehta11 Jul 13, 2026
04bc7da
Fix dcl and ccl flickering
KSMehta11 Jul 13, 2026
10ea686
Fix naming
KSMehta11 Jul 14, 2026
95fc0f0
Use charger current when connected
KSMehta11 Jul 14, 2026
912d189
Add cell open wire detection
KSMehta11 Jul 14, 2026
28e62a1
Add percell can msg for S adc volts
KSMehta11 Jul 14, 2026
ea27d19
Send percell s-adc voltages
KSMehta11 Jul 14, 2026
b32e9b2
Update submodule
KSMehta11 Jul 15, 2026
f28f1e0
Final fixes
KSMehta11 Jul 15, 2026
470335e
Update odyssey
KSMehta11 Jul 15, 2026
834b63e
Merge branch 'fixes' into 118-ow-detect
KSMehta11 Jul 15, 2026
ad66231
Updated implementation
KSMehta11 Jul 15, 2026
7b4e96d
dcl and ccl can msg fix
KSMehta11 Jul 16, 2026
42379cf
Merge branch 'fixes' into 118-ow-detect
KSMehta11 Jul 16, 2026
d9ceb00
Correct OCV timing
KSMehta11 Jul 16, 2026
7fec5fb
Add balancing algorithm mutexes
KSMehta11 Jul 16, 2026
c2be4c8
Cleanup charging check
KSMehta11 Jul 16, 2026
31ff3fe
Add sm and charging algo unit tests
KSMehta11 Jul 16, 2026
7fadc68
can codegen fix
KSMehta11 Jul 16, 2026
c633f9b
Merge branch 'fixes' into 118-ow-detect
KSMehta11 Jul 16, 2026
ed23df9
Send balancing PWM duty cycle feedback
KSMehta11 Jul 17, 2026
b5d7950
Fixing mutexes
KSMehta11 Jul 17, 2026
4d634ee
Fix formatting
KSMehta11 Jul 17, 2026
0b6ab8d
Fix
KSMehta11 Jul 17, 2026
bf5b68a
Update charging unit test
KSMehta11 Jul 18, 2026
b036aee
Change balancing pwm duty cycle msg format
KSMehta11 Jul 18, 2026
d3bc141
Retry CAN TX when FIFO is busy
KSMehta11 Jul 18, 2026
f4ca72d
Submodule update
KSMehta11 Jul 18, 2026
51e941d
codegen update
KSMehta11 Jul 18, 2026
b57f29f
submodule
KSMehta11 Jul 18, 2026
33be50f
Update ow fault to critical
KSMehta11 Jul 20, 2026
1f5bd7a
Wrap PWM register read in segment API
KSMehta11 Jul 20, 2026
cfb1cd5
Fix docs
KSMehta11 Jul 20, 2026
c0ee8e9
Move boot state initialization into init_boot
KSMehta11 Jul 20, 2026
96e7194
Clean up open-wire fault detection logic
KSMehta11 Jul 20, 2026
83e9038
Update open-wire fault handling
KSMehta11 Jul 20, 2026
a6a54b4
Small fix
KSMehta11 Jul 20, 2026
7f1494f
Mutex fault flag reads
KSMehta11 Jul 20, 2026
1e960e6
dcl config update
KSMehta11 Jul 20, 2026
15c5841
Switch soc to curve based
KSMehta11 Jul 20, 2026
563ec78
Send balancing duty cycle periodically
KSMehta11 Jul 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions Core/Inc/adi6830_interation.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,37 @@ void get_avgd_cell_voltages(cell_asic chips[NUM_CHIPS],
SPI_HandleTypeDef *hspi);

/**
* @brief Trigger, poll, and fetch voltages from the S-ADCs.
* @brief Trigger, poll, and fetch S-ADC voltages using an open-wire mode.
*
* @param chip Array of chips to get voltage readings from.
* @param chips Array of chips.
* @param hspi SPI handle.
* @param open_wire_mode Cell inputs on which to enable open-wire excitation.
*/
void get_s_adc_voltages(cell_asic chips[NUM_CHIPS], SPI_HandleTypeDef *hspi);
void get_s_adc_open_wire_voltages(cell_asic chips[NUM_CHIPS],
SPI_HandleTypeDef *hspi,
OW_C_S open_wire_mode);

/**
* @brief Trigger, poll, and fetch the c and s adc voltages, using instaneous redundancy.
* @brief Trigger, poll, and fetch normal S-ADC voltages.
*
* @param chips Array of chips to get voltage readings of.
* @param chips Array of chips to get voltage readings from.
*/
void get_c_and_s_adc_voltages(cell_asic chips[NUM_CHIPS],
SPI_HandleTypeDef *hspi);
void get_s_adc_voltages(cell_asic chips[NUM_CHIPS],
SPI_HandleTypeDef *hspi);

/**
* @brief Starts a continous c ADC conversion with S redundancy
*
*/
void start_c_adc_conv(cell_asic chips[NUM_CHIPS], SPI_HandleTypeDef *hspi);

/**
* @brief Start continuous S-ADC redundancy without restarting the C-ADC.
* @param chips ADBMS6830 daisy-chain devices.
* @param hspi SPI peripheral used by the daisy chain.
*/
void start_s_adc_conv(cell_asic chips[NUM_CHIPS], SPI_HandleTypeDef *hspi);

// --- END ADC POLL ---

#endif
9 changes: 7 additions & 2 deletions Core/Inc/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ void calc_pack_voltage_stats(analyzer_t *analyzer, acc_data_t *acc_data);
* cell voltages.
*
*/
void calc_open_cell_voltage(analyzer_t *analyzer, acc_data_t *acc_data,
hv_plate_t *hv_plate);
void calc_open_cell_voltage(analyzer_t *analyzer, hv_plate_t *hv_plate);

/**
* @brief Calculate cell resistances using Rin = ( Voc - V )/I
*/
void calc_cell_resistances(analyzer_t *analyzer, acc_data_t *acc_data,
hv_plate_t *hv_plate);

/**
* @brief Calculate voltage drop percentages and detect open wires.
*/
void detect_cell_open_wire(analyzer_t *analyzer, acc_data_t *acc_data,
state_machine_t *state_machine);

/**
* @brief Updates the cell status of balancing and S_C_faults based on raw cell
* data
Expand Down
4 changes: 3 additions & 1 deletion Core/Inc/bms_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#define OCV_CURR_THRESH 0.5f /* in A */

// Charging settings
#define CHARGING_CURRENT 3.5f
#define CHARGING_CURRENT 5.0f
#define CHARGE_SETL_TIMEOUT 30000 // 1 minute, may need adjustment
#define CHARGE_SETL_TIMEUP 120000 // 5 minutes, may need adjustment

Expand All @@ -68,6 +68,8 @@
#define LOW_CELL_TIME 55000
#define HIGH_TEMP_TIME 55000
#define MAX_CHIPTEMP_TIME 55000
#define COMMS_FAULT_TIME 20000
#define OW_FAULT_TIME 40000

// system wide base ADBMS sample rate
#define SAMPLE_RATE 2 /* Hz */
Expand Down
2 changes: 2 additions & 0 deletions Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#define CHARGERBOX_CANID 0x18FF50E5
#define DTI_CURRENT_CANID 0x436
#define BATTBOX_DUTY_CYCLE_CANID 0xD5
#define DTI_INPUT_VOLTAGE_CANID 0x416
#define DTI_DC_CURRENT_CANID 0x436

#define OVERFLOW_CANID 0x6F1
#define OVERFLOW_SIZE 6
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/can_messages_rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ typedef struct {
bool launch_control;
uint8_t functional_state;
bool traction_control;
uint8_t state_transition_error;
} car_state_t;

void receive_car_state(const can_msg_t *message, car_state_t *car_state);
Expand Down
46 changes: 37 additions & 9 deletions Core/Inc/can_messages_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ uint8_t send_segment_isospi_communication_status
* BMS/Faults/Critical/High_die_temp - Die temp ts too high
* BMS/Faults/Non-Critical/Segment_Comms_fault - Lost communications with segments
* BMS/Faults/Non-Critical/HV_Plate_Comms_Fault - Lost communications with HV Plate
* BMS/Faults/Non-Critical/Cell_open_wire - Open wire detected on one or more cells
* BMS/Faults/Non-Critical/Extra - Reserved
*/
uint8_t send_fault_status
(bool dcl_enforce,bool ccl_enforce,bool low_cell_volt,bool high_cell_volt,bool high_charge_volt,bool pack_hot,bool die_temp_max,bool segment_comms,bool hv_plate_comms);
(bool dcl_enforce,bool ccl_enforce,bool low_cell_volt,bool high_cell_volt,bool high_charge_volt,bool pack_hot,bool die_temp_max,bool segment_comms,bool hv_plate_comms,bool cell_open_wire);

/**
* Contents of this message:
Expand Down Expand Up @@ -172,9 +173,11 @@ uint8_t send_shepherd_version_hash
* BMS/PerCell/Alpha/{4}/Burning/{6} - Whether cell is burning
* BMS/PerCell/Alpha/{4}/CvS/{5} - Whether C and S ADCs read too different
* BMS/PerCell/Alpha/{4}/CvS/{6} - Whether C and S ADCs read too different
* BMS/PerCell/Alpha/{4}/OW/{5} - Whether an open wire is detected on the cell
* BMS/PerCell/Alpha/{4}/OW/{6} - Whether an open wire is detected on the cell
*/
uint8_t send_alpha_cell_data_debug
(float therm,float voltage_a,float voltage_b,uint8_t chip_id,uint8_t cell_a,uint8_t cell_b,bool discharging_a,bool discharging_b,bool cvs_a,bool cvs_b);
(float therm,float voltage_a,float voltage_b,uint8_t chip_id,uint8_t cell_a,uint8_t cell_b,bool discharging_a,bool discharging_b,bool cvs_a,bool cvs_b,bool ow_a,bool ow_b);

/**
* Contents of this message:
Expand All @@ -185,9 +188,27 @@ uint8_t send_alpha_cell_data_debug
* BMS/PerCell/Beta/{4}/Burning/{6} - Whether cell is burning
* BMS/PerCell/Beta/{4}/CvS/{5} - Whether C and S ADCs read too different
* BMS/PerCell/Beta/{4}/CvS/{6} - Whether C and S ADCs read too different
* BMS/PerCell/Beta/{4}/OW/{5} - Whether an open wire is detected on the cell
* BMS/PerCell/Beta/{4}/OW/{6} - Whether an open wire is detected on the cell
*/
uint8_t send_beta_cell_data_debug
(float therm,float voltage_a,float voltage_b,uint8_t chip_id,uint8_t cell_a,uint8_t cell_b,bool discharging_a,bool discharging_b,bool cvs_a,bool cvs_b);
(float therm,float voltage_a,float voltage_b,uint8_t chip_id,uint8_t cell_a,uint8_t cell_b,bool discharging_a,bool discharging_b,bool cvs_a,bool cvs_b,bool ow_a,bool ow_b);

/**
* Contents of this message:
* BMS/PerCell/Alpha/{3}/S_Volts/{4} - S ADC cell voltage
* BMS/PerCell/Alpha/{3}/S_Volts/{5} - S ADC cell voltage
*/
uint8_t send_alpha_cell_s_adc_data
(float s_voltage_a,float s_voltage_b,uint8_t chip_id,uint8_t cell_a,uint8_t cell_b);

/**
* Contents of this message:
* BMS/PerCell/Beta/{3}/S_Volts/{4} - S ADC cell voltage
* BMS/PerCell/Beta/{3}/S_Volts/{5} - S ADC cell voltage
*/
uint8_t send_beta_cell_s_adc_data
(float s_voltage_a,float s_voltage_b,uint8_t chip_id,uint8_t cell_a,uint8_t cell_b);

/**
* Contents of this message:
Expand Down Expand Up @@ -311,12 +332,12 @@ uint8_t send_hv_plate_diagnostics

/**
* Contents of this message:
* BMS/Plate/Diagnostics/EPAD - Exposed pad
* BMS/Plate/Diagnostics/VDIG - Internal digital 3V supply
* BMS/Plate/Diagnostics/VDD - VDD power supply pin
* BMS/Plate/Diagnostics/TMP2 - Secondary internal temperature sensor
* BMS/Plate/Diagnostics/VDIV -
* BMS/Plate/Diagnostics/Extra - Reserved
* BMS/HV_Plate/Diagnostics/EPAD - Exposed pad
* BMS/HV_Plate/Diagnostics/VDIG - Internal digital 3V supply
* BMS/HV_Plate/Diagnostics/VDD - VDD power supply pin
* BMS/HV_Plate/Diagnostics/TMP2 - Secondary internal temperature sensor
* BMS/HV_Plate/Diagnostics/VDIV -
* BMS/HV_Plate/Diagnostics/Extra - Reserved
*/
uint8_t send_hv_plate_diagnostics_second
(float epad,float vdig,float vdd,float tmp2,float vdiv);
Expand Down Expand Up @@ -402,6 +423,13 @@ uint8_t send_hv_plate_voltages_adbms
uint8_t send_pack_current_and_shunt_temp_adbms
(float pack_current,float shunt_temp);

/**
* Contents of this message:
* BMS/Control/CellBalancing/PWMDutyCycle - Current cell balancing PWM duty cycle
*/
uint8_t send_current_cell_balancing_pwm_duty_cycle
(float balancing_pwm_duty_cycle);

/**
* Contents of this message:
* BMS/Commands/Max_AC_Current_Target - This value determines the maximum allowable drive current on the AC side
Expand Down
22 changes: 11 additions & 11 deletions Core/Inc/cell_temp_sanitizer.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include <stdbool.h>
#include "timer.h"
#include "datastructs.h"

#ifndef CELL_TEMP_SANITIZER_H
#define CELL_TEMP_SANITIZER_H

#define TOO_DIFF_THRESHOLD 0.20

/**
* @brief Creates a grid of therm_t.
* @param sanitizer Struct containing sanitized therm data
* @brief Initializes the temperature sanitizer state.
*
* @param sanitizer Pointer to the sanitizer data structure.
*/
void temp_sanitizer_init(sanitizer_t *sanitizer);

/**
* @brief Given a grid of cell temperatures, updates the given grid of sanitized cell temperatures.
* Should be run periodically.
* @param sanitizer Struct containing sanitized therm data
* @param analyzer Struct containing analyzer data
* @brief Processes and sanitizes cell temperature readings.
*
* Valid samples update the tracked minimum and maximum temperatures while
* invalid samples are filtered and tracked using the fault counter.
*
* @param sanitizer Pointer to the sanitizer data structure.
* @param analyzer Pointer to the analyzer containing raw temperature data.
*/
void temp_sanitizer_run(sanitizer_t *sanitizer, analyzer_t *analyzer);
void temp_sanitizer_run(sanitizer_t *const sanitizer, const analyzer_t *const analyzer);

void vSanitizer(ULONG thread_input);

Expand Down
7 changes: 7 additions & 0 deletions Core/Inc/charging.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
void pwm_duty_cycle_set(uint8_t duty_cycle_req_get);

/**
* @brief get the selected ADBMS duty cycle
*
* @returns the selected duty cycle percentage
*/
float pwm_duty_cycle_setting_get(void);

/**
* @brief get the duty cycle (atomic)
*
Expand Down
6 changes: 3 additions & 3 deletions Core/Inc/current_limit_algo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#define DCL_TEMP_RAMP_DOWN_START_C (50.0f)
#define DCL_TEMP_MAX_C (60.0f)
#define DCL_OCV_MIN_V (3.0f)
#define DCL_OCV_DERATE_THRESH (3.7f)
#define DCL_MAX_CURRENT_A (135.0f)
#define DCL_OCV_DERATE_THRESH (3.2f)
#define DCL_MAX_CURRENT_A (180.0f)
#define DCL_MIN_CURRENT_A (30.0f)
#define DCL_PULSE_PERCENT (1.1f)
#define DCL_COOLDOWN_PERCENT (0.9f)
Expand All @@ -35,7 +35,7 @@
#define CCL_TEMP_MAX_C (60.0f)
#define CCL_OCV_MAX_V (4.2f)
#define CCL_OCV_DERATE_THRESH (4.0f)
#define CCL_MAX_CURRENT_A (30.0f)
#define CCL_MAX_CURRENT_A (60.0f)
#define CCL_MIN_CURRENT_A (0.0f)
#define CCL_PULSE_PERCENT (1.1f)
#define CCL_COOLDOWN_PERCENT (0.9f)
Expand Down
25 changes: 24 additions & 1 deletion Core/Inc/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef struct {
float cell_resistance[NUM_CELLS_PER_CHIP];
float open_cell_voltage[NUM_CELLS_PER_CHIP];
float cell_voltages[NUM_CELLS_PER_CHIP];
/* S-ADC voltages */
float s_cell_voltages[NUM_CELLS_PER_CHIP];

/* Maximum temperature of on-board therms.*/
float on_board_temp[NUM_ONBOARD_THERMS_PER_CHIP];
Expand All @@ -56,6 +58,7 @@ typedef struct {
/* Chip and Cell Diagnostic Data */
bool is_balancing[NUM_CELLS_PER_CHIP];
bool cs_fault[NUM_CELLS_PER_CHIP];
bool ow_fault[NUM_CELLS_PER_CHIP];

float vpv;
float vmv;
Expand Down Expand Up @@ -85,6 +88,8 @@ typedef struct {
typedef struct {
float last_temp;
bool valid;
bool initialized;
uint8_t fault_count;
} therm_state_t;

/**
Expand All @@ -104,6 +109,12 @@ typedef enum {
FAULT_TIMER_EXPIRED,
} fault_timer_status_t;

typedef enum {
FAULT_NONE,
FAULT_ONGOING,
FAULT_TRIGGERED,
} fault_state_t;

/**
* @brief Data needed for the therm temp sanitizer
*/
Expand Down Expand Up @@ -211,6 +222,7 @@ typedef struct {
*/
typedef enum {
SOC_STATE_INIT_FROM_OCV,
SOC_STATE_OCV_ESTIMATION,
SOC_STATE_COULOMB_COUNTING
} soc_state_t;

Expand Down Expand Up @@ -240,7 +252,7 @@ typedef struct {
crit_cellval_t max_voltage;
crit_cellval_t min_voltage;
float avg_voltage;
float delt_voltage;
float delta_voltage;

// OCV timer
nertimer_t ocvTimer;
Expand Down Expand Up @@ -373,6 +385,7 @@ typedef struct {

bool segment_comms_fault_flag;
bool hv_plate_comms_fault_flag;
bool cell_open_wire_fault_flag;

bool balancing_active;
bool is_charger_connected;
Expand Down Expand Up @@ -422,6 +435,14 @@ typedef struct {
peripherals_t *peripherals;
} state_machine_args_t;

/**
* @brief args for vCanReceive
*/
typedef struct {
state_machine_args_t *state_machine_args;
hv_plate_t *hv_plate;
} can_receive_args_t;

/**
* @brief args for vAnalyzer
*/
Expand All @@ -438,6 +459,7 @@ typedef struct {
typedef struct {
acc_data_t *acc_data;
state_machine_t *state_machine;
analyzer_t *analyzer;
} acc_data_args_t;

/**
Expand Down Expand Up @@ -492,6 +514,7 @@ typedef enum {

HV_PLATE_COMMS_FAULT,
SEGMENT_COMMS_FAULT,
CELL_OPEN_WIRE_FAULT,

NUM_FAULTS, /* NUM_REACTIONARY_FAULTS = NUM_FAULTS - NUM_CONDITIONAL_FAULTS - 1 */

Expand Down
3 changes: 3 additions & 0 deletions Core/Inc/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void segment_configure_balancing(
PWM_DUTY discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP],
SPI_HandleTypeDef *hspi);

void segment_read_pwm_registers(cell_asic chips[NUM_CHIPS],
SPI_HandleTypeDef *hspi);

/**
* @brief Returns if any cells are balancing. Must read back config register B and PWM registers.
*
Expand Down
4 changes: 3 additions & 1 deletion Core/Inc/shep_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include "tx_api.h"
#include "datastructs.h"

#define NO_LOG

// #define DEBUG_HV_PLATE
// #define DEBUG_RAW_VOLTAGES
// #define DEBUG_OCV_VOLTAGES
// #define DEBUG_TEMPS
// #define DEBUG_AlGOS
// #define DEBUG_ALGOS

/* Initializes all ThreadX threads.
* Calls to create_thread() should go in here
Expand Down
Loading
Loading