90 lines
2.7 KiB
C
90 lines
2.7 KiB
C
#include <stdio.h>
|
|
#include "by_fan_control.h"
|
|
#include "zf_common_headfile.h"
|
|
|
|
#define FAN_LL_PWM_PIN TIM8_PWM_MAP0_CH1_C6 // 左升力风扇
|
|
#define FAN_RL_PWM_PIN TIM8_PWM_MAP0_CH2_C7 // 右升力风扇
|
|
#define FAN_LS_PWM_PIN TIM4_PWM_MAP1_CH4_D15 // 左侧动力风扇
|
|
#define FAN_RS_PWM_PIN TIM4_PWM_MAP1_CH3_D14 // 右侧动力风扇
|
|
#define FAN_LB_PWM_PIN TIM4_PWM_MAP1_CH2_D13 // 左后动力风扇
|
|
#define FAN_RB_PWM_PIN TIM4_PWM_MAP1_CH1_D12 // 右后动力风扇
|
|
|
|
uint32_t pwm_duty_ls_g;
|
|
uint32_t pwm_duty_rs_g;
|
|
uint32_t pwm_duty_lb_g;
|
|
uint32_t pwm_duty_rb_g;
|
|
|
|
static uint32_t myclip(uint32_t x, uint32_t low, uint32_t up)
|
|
{
|
|
return (x > up ? up : x < low ? low
|
|
: x);
|
|
}
|
|
|
|
static float myclip_f(float x, float low, float up)
|
|
{
|
|
return (x > up ? up : x < low ? low
|
|
: x);
|
|
}
|
|
|
|
void by_pwm_init(void)
|
|
{
|
|
pwm_init(FAN_LL_PWM_PIN, 50, 500);
|
|
pwm_init(FAN_RL_PWM_PIN, 50, 500);
|
|
|
|
pwm_init(FAN_LS_PWM_PIN, 4000, 0);
|
|
pwm_init(FAN_RS_PWM_PIN, 4000, 0);
|
|
pwm_init(FAN_LB_PWM_PIN, 4000, 0);
|
|
pwm_init(FAN_RB_PWM_PIN, 4000, 0);
|
|
// system_delay_ms(3000);
|
|
// // pwm_init(FAN_LS_PWM_PIN, 50, 1000); // 动力风扇左 1
|
|
// // pwm_init(FAN_RS_PWM_PIN, 50, 1000); // 动力风扇右 1
|
|
// // pwm_init(FAN_LB_PWM_PIN, 50, 1000); // 动力风扇左 2
|
|
// // pwm_init(FAN_RB_PWM_PIN, 50, 1000); // 动力风扇右 2
|
|
// // system_delay_ms(5000);
|
|
// pwm_set_duty(FAN_LS_PWM_PIN, 600);
|
|
// pwm_set_duty(FAN_RS_PWM_PIN, 600);
|
|
// pwm_set_duty(FAN_LB_PWM_PIN, 600);
|
|
// pwm_set_duty(FAN_RB_PWM_PIN, 600);
|
|
// while(1);
|
|
}
|
|
|
|
/**
|
|
* @brief 更新升力风扇占空比
|
|
*
|
|
* @param update_pwm_duty1
|
|
* @param update_pwm_duty2
|
|
*/
|
|
void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2)
|
|
{
|
|
update_pwm_duty1 = myclip(update_pwm_duty1, 500, 1000);
|
|
update_pwm_duty2 = myclip(update_pwm_duty2, 500, 1000);
|
|
pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1);
|
|
pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2);
|
|
}
|
|
|
|
/**
|
|
* @brief 更新动力风扇占空比
|
|
*
|
|
* @param pwm_duty_ls
|
|
* @param pwm_duty_rs
|
|
* @param pwm_duty_lb
|
|
* @param pwm_duty_rb
|
|
*/
|
|
void by_pwm_power_duty(uint32_t pwm_duty_ls, uint32_t pwm_duty_rs, uint32_t pwm_duty_lb, uint32_t pwm_duty_rb)
|
|
{
|
|
pwm_duty_ls = myclip(pwm_duty_ls, 0, 5000);
|
|
pwm_duty_rs = myclip(pwm_duty_rs, 0, 5000);
|
|
pwm_duty_lb = myclip(pwm_duty_lb, 0, 5000);
|
|
pwm_duty_rb = myclip(pwm_duty_rb, 0, 5000);
|
|
|
|
pwm_duty_ls_g = pwm_duty_ls;
|
|
pwm_duty_rs_g = pwm_duty_rs;
|
|
pwm_duty_lb_g = pwm_duty_lb;
|
|
pwm_duty_rb_g = pwm_duty_rb;
|
|
|
|
pwm_set_duty(FAN_LS_PWM_PIN, pwm_duty_ls);
|
|
pwm_set_duty(FAN_RS_PWM_PIN, pwm_duty_rs);
|
|
pwm_set_duty(FAN_LB_PWM_PIN, pwm_duty_lb);
|
|
pwm_set_duty(FAN_RB_PWM_PIN, pwm_duty_rb);
|
|
}
|