Skip to content

Commit

Permalink
i hate everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Jan 10, 2024
1 parent 6a953d0 commit c64b803
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Core/Src/analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void calc_open_cell_voltage()
/* If we are within the current threshold for open voltage measurments */
else if (bmsdata->pack_current < (OCV_CURR_THRESH * 10)
&& bmsdata->pack_current > (-OCV_CURR_THRESH * 10)) {
if (is_timer_expired(&ocvTimer)) {
if (is_timer_expired(&ocvTimer) || !is_timer_active(&ocvTimer)) {
for (uint8_t chip = 0; chip < NUM_CHIPS; chip++) {
for (uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) {
/* Sets open cell voltage to a moving average of OCV_AVG values */
Expand Down
45 changes: 23 additions & 22 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,35 @@ int _write(int file, char* ptr, int len) {

const void print_bms_stats(acc_data_t *acc_data)
{

static nertimer_t debug_stat_timer;
static const uint16_t PRINT_STAT_WAIT = 500; //ms

if(!is_timer_expired(&debug_stat_timer)) return;

if(!is_timer_expired(&debug_stat_timer) && debug_stat_timer.active) return;
HAL_UART_Transmit(&huart4, (char*)"butts", 5, 1000);
//TODO get this from eeprom once implemented
// question - should we read from eeprom here, or do that on loop and store locally?
//printf("Prev Fault: %#x", previousFault);
printf("Current: %f\n", (float)(acc_data->pack_current) / 10.0);
printf("Min, Max, Avg Temps: %ld, %ld, %d\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp);
printf("Current: %f\r\n", (float)(acc_data->pack_current) / 10.0);
printf("Min, Max, Avg Temps: %ld, %ld, %d\r\n", acc_data->min_temp.val, acc_data->max_temp.val, acc_data->avg_temp);
printf("Min, Max, Avg, Delta Voltages: %ld, %ld, %d, %d\n", acc_data->min_voltage.val, acc_data->max_voltage.val, acc_data->avg_voltage, acc_data->delt_voltage);
printf("DCL: %d\n", acc_data->discharge_limit);
printf("CCL: %d\n", acc_data->charge_limit);
printf("SoC: %d\n", acc_data->soc);
printf("Is Balancing?: %d\n", segment_is_balancing());
printf("DCL: %d\r\n", acc_data->discharge_limit);
printf("CCL: %d\r\n", acc_data->charge_limit);
printf("SoC: %d\r\n", acc_data->soc);
printf("Is Balancing?: %d\r\n", segment_is_balancing());
printf("State: ");
if (current_state == 0) printf("BOOT\n");
else if (current_state == 1) printf("READY\n");
else if (current_state == 2) printf("CHARGING\n");
else if (current_state == 1) printf("FAULTED\n");
printf("Raw Cell Voltage:\n");
if (current_state == 0) printf("BOOT\r\n");
else if (current_state == 1) printf("READY\r\n");
else if (current_state == 2) printf("CHARGING\r\n");
else if (current_state == 1) printf("FAULTED\r\n");
printf("Raw Cell Voltage:\r\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 0; cell < NUM_CELLS_PER_CHIP; cell++)
{
printf("%d\t", acc_data->chip_data[c].voltage_reading[cell]);
}
printf("\n");
printf("\r\n");
}

printf("Open Cell Voltage:\n");
Expand All @@ -145,27 +146,27 @@ const void print_bms_stats(acc_data_t *acc_data)
{
printf("%d\t", acc_data->chip_data[c].open_cell_voltage[cell]);
}
printf("\n");
printf("\r\n");
}

printf("Cell Temps:\n");
printf("Cell Temps:\r\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 17; cell < 28; cell++)
{
printf("%d\t", acc_data->chip_data[c].thermistor_reading[cell]);
}
printf("\n");
printf("\r\n");
}

printf("Avg Cell Temps:\n");
printf("Avg Cell Temps:\r\n");
for(uint8_t c = 0; c < NUM_CHIPS; c++)
{
for(uint8_t cell = 17; cell < 28; cell++)
{
printf("%d\t", acc_data->chip_data[c].thermistor_value[cell]);
}
printf("\n");
printf("\r\n");
}

start_timer(&debug_stat_timer, PRINT_STAT_WAIT);
Expand Down Expand Up @@ -213,7 +214,7 @@ int main(void)
MX_I2C1_Init();
/* USER CODE BEGIN 2 */

// segment_init();
segment_init();
/* USER CODE END 2 */

/* Infinite loop */
Expand Down Expand Up @@ -241,8 +242,8 @@ int main(void)
sm_handle_state(acc_data);

/* check for inbound CAN */
get_can1_msg();
get_can2_msg();
// get_can1_msg();
// get_can2_msg();


#ifdef DEBUG_STATS
Expand Down
13 changes: 7 additions & 6 deletions Core/Src/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ void push_chip_configuration() { LTC6804_wrcfg(ltc68041, NUM_CHIPS, local_config

void segment_init()
{
//printf("Initializing Segments...");
printf("Initializing Segments...");

ltc68041 = LTC6804_initialize(&hspi1, GPIOA, 4);
ltc68041 = malloc(sizeof(ltc_config));
LTC6804_initialize(ltc68041, &hspi1, GPIOA, 4);

// pull_chip_configuration();
pull_chip_configuration();

for (int c = 0; c < NUM_CHIPS; c++) {
local_config[c][0] = 0xF8;
Expand Down Expand Up @@ -176,7 +177,7 @@ int pull_voltages()
* just copy over the contents of the last good reading and the fault status
* from the most recent attempt
*/
if (!is_timer_expired(&voltage_reading_timer)) {
if (!is_timer_expired(&voltage_reading_timer) && voltage_reading_timer.active) {
for (uint8_t i = 0; i < NUM_CHIPS; i++) {
memcpy(segment_data[i].voltage_reading, previous_data[i].voltage_reading,
sizeof(segment_data[i].voltage_reading));
Expand Down Expand Up @@ -331,13 +332,13 @@ void segment_enable_balancing(bool balance_enable)
configure_discharge(c, DICHARGE_ALL_COMMAND);
discharge_commands[c] = DICHARGE_ALL_COMMAND;
}
//push_chip_configuration();
push_chip_configuration();
} else {
for (int c = 0; c < NUM_CHIPS; c++) {
configure_discharge(c, 0);
discharge_commands[c] = 0;
}
//push_chip_configuration();
push_chip_configuration();
}
}

Expand Down
8 changes: 3 additions & 5 deletions Core/Src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void handle_charging(acc_data_t* bmsdata)
}

/* Send CAN message, but not too often */
if (is_timer_expired(&charger_message_timer)) {
if (is_timer_expired(&charger_message_timer) || !is_timer_active(&charger_message_timer)) {
compute_send_charging_message(
(MAX_CHARGE_VOLT * NUM_CELLS_PER_CHIP * NUM_CHIPS), bmsdata);
start_timer(&charger_message_timer, CHARGE_MESSAGE_WAIT);
Expand Down Expand Up @@ -174,11 +174,9 @@ void sm_handle_state(acc_data_t* bmsdata)
state_test[0] = current_state + '0';


HAL_UART_Transmit(&huart4, (char*)state_test, 1, 1000);

/* send relevant CAN msgs */
// clang-format off
if (is_timer_expired(&can_msg_timer))
if (is_timer_expired(&can_msg_timer) || !is_timer_active(&can_msg_timer))
{
compute_send_acc_status_message(bmsdata);
compute_send_current_message(bmsdata);
Expand Down Expand Up @@ -297,7 +295,7 @@ bool sm_charging_check(acc_data_t* bmsdata)
{
if (!compute_charger_connected())
return false;
if (!is_timer_expired(&charge_timeout))
if (!is_timer_expired(&charge_timeout) && is_timer_active(&charge_timeout))
return false;

if (bmsdata->max_voltage.val >= (MAX_CHARGE_VOLT * 10000)
Expand Down

0 comments on commit c64b803

Please sign in to comment.