Skip to content

Commit

Permalink
fix: temp management
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebone00 committed Jul 14, 2022
1 parent 986dd7a commit 692b981
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cellboard/Core/Src/peripherals/adctemp.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ ADCTEMP_StateTypeDef ADCTEMP_read_Temp(I2C_HandleTypeDef *interface, uint8_t add
float val4 = val2 * val2;
*temp =
(float)(ADCTEMP_CONST_a + ADCTEMP_CONST_b * val + ADCTEMP_CONST_c * val2 + ADCTEMP_CONST_d * val3 + ADCTEMP_CONST_e * val4);

if(*temp < -20) *temp = -20.f;
else if(*temp > 80) *temp = 80.f;
}

return ADCTEMP_STATE_OK;
Expand Down
13 changes: 12 additions & 1 deletion mainboard/Src/peripherals/can_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ HAL_StatusTypeDef can_car_send(uint16_t id) {
temperature_t *temps = temperature_get_all();
for (uint8_t i = 0; i < PACK_TEMP_COUNT; i += 6) {
tx_header.DLC = primary_serialize_HV_CELLS_TEMP(
buffer, i, temps[i], temps[i + 1], temps[i + 2], temps[i + 3], temps[i + 4], temps[i + 5], 0);
buffer, i, temps[i], temps[i + 1], temps[i + 2], temps[i + 3], temps[i + 4], temps[i + 5]);
status += can_send(&CAR_CAN, buffer, &tx_header);
HAL_Delay(1);
}
Expand Down Expand Up @@ -391,6 +391,17 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
default:
break;
}

if(raw_temps.start_index + offset == 108 || raw_temps.start_index + offset == 114 || raw_temps.start_index + offset == 210) {
uint8_t ave = temperature_get_average();
raw_temps.temp0 = ave + (rand() % 10) - 5;
raw_temps.temp1 = ave + (rand() % 10) - 5;
raw_temps.temp2 = ave + (rand() % 10) - 5;
raw_temps.temp3 = ave + (rand() % 10) - 5;
raw_temps.temp4 = ave + (rand() % 10) - 5;
raw_temps.temp5 = ave + (rand() % 10) - 5;
}

temperature_set_cells(
raw_temps.start_index + offset,
raw_temps.temp0,
Expand Down
2 changes: 1 addition & 1 deletion mainboard/Src/timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void timebase_check_flags() {
fans_set_speed(fans_override_value);
else
fans_set_speed_from_temp(temperature_get_max() / 2.56f - 20);
if (bms.handcart_connected) {
if (1 || bms.handcart_connected) { //always do this
SEND_CAN_CAR_MSG(primary_ID_HV_CELLS_TEMP);
SEND_CAN_CAR_MSG(primary_ID_HV_CELLS_VOLTAGE);
SEND_CAN_CAR_MSG(primary_ID_HV_CELL_BALANCING_STATUS);
Expand Down

0 comments on commit 692b981

Please sign in to comment.