Skip to content

Commit

Permalink
working implementation running in Varano
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebone00 committed Jul 21, 2022
1 parent 692b981 commit d375d4e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions mainboard/Inc/fans_buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 10 additions & 2 deletions mainboard/Src/fans_buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "mainboard_config.h"
#include "math.h"
#include "temperature.h"
#include "tim.h"

#include <string.h>
Expand All @@ -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
////////////////////////////////////////////////////////////////////////////////

Expand Down
12 changes: 6 additions & 6 deletions mainboard/Src/peripherals/can_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 5 additions & 9 deletions mainboard/Src/timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d375d4e

Please sign in to comment.