#include "PWM_control.h" #include uint8_t powerground_status; uint8_t battery_cooling_status; //uint32_t powerground1_CCR, powerground2_CCR, battery_cooling_CCR; TIM_HandleTypeDef powerground1, powerground2, battery_cooling; /* Pulse width modulation mode allows for generating a signal with a frequency determined by the value of the TIMx_ARR register and a duty cycle determined by the value of the TIMx_CCRx register. */ void PWM_control_init(TIM_HandleTypeDef powerground1, TIM_HandleTypeDef powerground2, TIM_HandleTypeDef battery_cooling){ powerground_status = 0; battery_cooling_status = 0; HAL_TIM_PWM_Start(&powerground1, 1); //TIM15CH1 HAL_TIM_PWM_Start(&powerground2, 2); //TIM15CH2 HAL_TIM_PWM_Start(&battery_cooling, 3); //TIM1CH3 } /* controls the duty cycle of the fans by setting the CCR of the channel percent/100 = x/ARR */ void PWM_powerground_control(uint8_t percent){ if (percent > 100 || percent < 0) return; powerground_status = percent/100; TIM15->CCR1 = (TIM15->ARR*POWERGROUND_MAX_DUTY_CYCLE-TIM15->ARR*POWERGROUND_MIN_DUTY_CYCLE) * (percent/100) + TIM15->ARR*POWERGROUND_MIN_DUTY_CYCLE; TIM15->CCR2 = TIM15->CCR1; /* *1.01 or *0.99 if the speeds of the fans are different*/ } void PWM_battery_cooling_control(uint8_t percent){}