diff --git a/board/boards/black.h b/board/boards/black.h index c860d1401d..ae6e0160df 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -162,6 +162,7 @@ board board_black = { .has_spi = false, .has_canfd = false, .fan_max_rpm = 0U, + .fan_max_pwm = 100U, .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index a9ff9297ba..22f55883f4 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -29,6 +29,7 @@ struct board { const uint16_t avdd_mV; const bool fan_stall_recovery; const uint8_t fan_enable_cooldown_time; + const uint8_t fan_max_pwm; board_init init; board_init_bootloader init_bootloader; board_enable_can_transceiver enable_can_transceiver; diff --git a/board/boards/cuatro.h b/board/boards/cuatro.h index 43a5dfc505..720077def6 100644 --- a/board/boards/cuatro.h +++ b/board/boards/cuatro.h @@ -57,6 +57,10 @@ uint32_t cuatro_read_current_mA(void) { return adc_get_mV(3) * 2U; } +void cuatro_set_fan_enabled(bool enabled) { + set_gpio_output(GPIOD, 3, !enabled); +} + void cuatro_init(void) { red_chiplet_init(); @@ -93,6 +97,7 @@ void cuatro_init(void) { // fan setup set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3); + register_set_bits(&(GPIOC->OTYPER), GPIO_OTYPER_OT8); // open drain // Initialize IR PWM and set to 0% set_gpio_alternate(GPIOC, 9, GPIO_AF2_TIM3); @@ -108,7 +113,8 @@ board board_cuatro = { .has_obd = true, .has_spi = true, .has_canfd = true, - .fan_max_rpm = 6600U, + .fan_max_rpm = 12500U, + .fan_max_pwm = 99U, // it can go up to 14k RPM, but 99% -> 100% is very non-linear .avdd_mV = 1800U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 3U, @@ -121,7 +127,7 @@ board board_cuatro = { .check_ignition = red_check_ignition, .read_voltage_mV = cuatro_read_voltage_mV, .read_current_mA = cuatro_read_current_mA, - .set_fan_enabled = tres_set_fan_enabled, + .set_fan_enabled = cuatro_set_fan_enabled, .set_ir_power = tres_set_ir_power, .set_siren = unused_set_siren, .set_bootkick = tres_set_bootkick, diff --git a/board/boards/dos.h b/board/boards/dos.h index 0164f2b262..62e83c6882 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -190,6 +190,7 @@ board board_dos = { #endif .has_canfd = false, .fan_max_rpm = 6500U, + .fan_max_pwm = 100U, .avdd_mV = 3300U, .fan_stall_recovery = true, .fan_enable_cooldown_time = 3U, diff --git a/board/boards/grey.h b/board/boards/grey.h index 516d0fa70f..cbbd8e9c89 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -11,6 +11,7 @@ board board_grey = { .has_spi = false, .has_canfd = false, .fan_max_rpm = 0U, + .fan_max_pwm = 100U, .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, diff --git a/board/boards/red.h b/board/boards/red.h index 746c54b622..3a12fdb705 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -174,6 +174,7 @@ board board_red = { .has_spi = false, .has_canfd = true, .fan_max_rpm = 0U, + .fan_max_pwm = 100U, .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, diff --git a/board/boards/tres.h b/board/boards/tres.h index 91b94f68e2..fdd4cb19d5 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -76,6 +76,7 @@ board board_tres = { .has_spi = true, .has_canfd = true, .fan_max_rpm = 6600U, + .fan_max_pwm = 100U, .avdd_mV = 1800U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 3U, diff --git a/board/boards/uno.h b/board/boards/uno.h index a2e1e98354..8e86c98fac 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -197,6 +197,7 @@ board board_uno = { .has_spi = false, .has_canfd = false, .fan_max_rpm = 5100U, + .fan_max_pwm = 100U, .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, diff --git a/board/boards/white.h b/board/boards/white.h index 8d22afbc9b..08f62e5226 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -191,6 +191,7 @@ board board_white = { .has_spi = false, .has_canfd = false, .fan_max_rpm = 0U, + .fan_max_pwm = 100U, .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, diff --git a/board/drivers/fan.h b/board/drivers/fan.h index 15296079ae..e0946aac34 100644 --- a/board/drivers/fan.h +++ b/board/drivers/fan.h @@ -86,7 +86,7 @@ void fan_tick(void) { float error = fan_state.target_rpm - fan_rpm_fast; fan_state.error_integral += FAN_I * error; } - fan_state.power = CLAMP(fan_state.error_integral, 0U, 100U); + fan_state.power = CLAMP(fan_state.error_integral, 0U, current_board->fan_max_pwm); // Set PWM and enable line pwm_set(TIM3, 3, fan_state.power); diff --git a/board/stm32h7/llfan.h b/board/stm32h7/llfan.h index dce622503a..04f0fc11c8 100644 --- a/board/stm32h7/llfan.h +++ b/board/stm32h7/llfan.h @@ -8,8 +8,8 @@ void EXTI2_IRQ_Handler(void) { } void llfan_init(void) { - // 5000RPM * 4 tach edges / 60 seconds - REGISTER_INTERRUPT(EXTI2_IRQn, EXTI2_IRQ_Handler, 700U, FAULT_INTERRUPT_RATE_TACH) + // 12000RPM * 4 tach edges / 60 seconds + REGISTER_INTERRUPT(EXTI2_IRQn, EXTI2_IRQ_Handler, 1000U, FAULT_INTERRUPT_RATE_TACH) // Init PWM speed control pwm_init(TIM3, 3);