diff --git a/mainboard/Inc/fans_buzzer.h b/mainboard/Inc/fans_buzzer.h index e179cbff..34e1f35f 100644 --- a/mainboard/Inc/fans_buzzer.h +++ b/mainboard/Inc/fans_buzzer.h @@ -12,5 +12,6 @@ extern float fans_override_value; void fans_init(); void fans_set_speed(float power_percentage); void fans_set_speed_from_temp(float temp); +void fans_loop(float temperature); void BUZ_sborati(TIM_HandleTypeDef *htim); \ No newline at end of file diff --git a/mainboard/Src/fans_buzzer.c b/mainboard/Src/fans_buzzer.c index 521f9f4b..41114bdb 100644 --- a/mainboard/Src/fans_buzzer.c +++ b/mainboard/Src/fans_buzzer.c @@ -2,6 +2,7 @@ #include "mainboard_config.h" #include "math.h" +#include "temperature.h" #include "tim.h" #include @@ -22,14 +23,21 @@ void fans_set_speed(float power) { pwm_set_duty_cicle(&HTIM_PWM, PWM_FANS_CHANNEL, 1 - power); } void fans_set_speed_from_temp(float temp) { - uint8_t thr_l = fans_speed > 0.05 ? 28 : 30; + uint8_t thr_l = fans_speed > 0.05 ? 43 : 45; if (temp < thr_l) return fans_set_speed(0); if (temp < 49) - return fans_set_speed(0.75 / 25 * (temp - 25) + 0.15); + return fans_set_speed(0.75 / 12 * (temp - 43) + 0.15); //map temps between 43-55 to duty cycle fans_set_speed(1); } +void fans_loop(float temperature) { + if (fans_override) + fans_set_speed(fans_override_value); + else + fans_set_speed_from_temp(temperature_get_max() / 2.56f - 20); +} + // credits to the master sborato PM Alex //////////////////////////////////////////////////////////////////////////////// diff --git a/mainboard/Src/peripherals/can_comm.c b/mainboard/Src/peripherals/can_comm.c index 7862fd3e..8d4926d3 100644 --- a/mainboard/Src/peripherals/can_comm.c +++ b/mainboard/Src/peripherals/can_comm.c @@ -394,12 +394,12 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { 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; + raw_temps.temp0 = ave + (rand() % 2) - 1; + raw_temps.temp1 = ave + (rand() % 2) - 1; + raw_temps.temp2 = ave + (rand() % 2) - 1; + raw_temps.temp3 = ave + (rand() % 2) - 1; + raw_temps.temp4 = ave + (rand() % 2) - 1; + raw_temps.temp5 = ave + (rand() % 2) - 1; } temperature_set_cells( diff --git a/mainboard/Src/timebase.c b/mainboard/Src/timebase.c index b2d6f05d..abe4cdfa 100644 --- a/mainboard/Src/timebase.c +++ b/mainboard/Src/timebase.c @@ -64,15 +64,11 @@ void timebase_check_flags() { flags &= ~_100MS_INTERVAL_FLAG; } if (flags & _500MS_INTERVAL_FLAG) { - if (fans_override) - fans_set_speed(fans_override_value); - else - fans_set_speed_from_temp(temperature_get_max() / 2.56f - 20); - 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); - } + fans_loop(temperature_get_max() / 2.56 - 20); + + 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); SEND_CAN_CAR_MSG(primary_ID_HV_CAN_FORWARD_STATUS); SEND_CAN_CAR_MSG(primary_ID_HV_FANS_OVERRIDE_STATUS); flags &= ~_500MS_INTERVAL_FLAG;