Files
QD4C-firmware/app/by_fan_control.c

81 lines
2.4 KiB
C
Raw Normal View History

#include <stdio.h>
#include "by_fan_control.h"
#include "zf_common_headfile.h"
2024-03-28 04:24:59 +08:00
#include "jj_blueteeth.h"
2024-05-05 19:15:51 +08:00
#include "jj_motion.h"
2024-04-16 16:09:34 +08:00
#define FAN_LL_PWM_PIN TIM8_PWM_MAP1_CH1_B6 // 左升力风扇
#define FAN_RL_PWM_PIN TIM8_PWM_MAP1_CH2_B7 // 右升力风扇
// M4
2024-07-07 23:08:49 +08:00
#define FAN_RB_PWM_PIN TIM10_PWM_MAP3_CH4_D7
#define FAN_LB_PWM_PIN TIM4_PWM_MAP1_CH2_D13
2024-07-05 03:29:56 +08:00
#define FAN_LS_PWM_PIN TIM1_PWM_MAP0_CH4_A11
2024-07-07 23:08:49 +08:00
#define FAN_RS_PWM_PIN TIM1_PWM_MAP0_CH1_A8
2024-04-16 16:09:34 +08:00
int32_t pwm_duty_ls_g;
int32_t pwm_duty_rs_g;
int32_t pwm_duty_lb_g;
int32_t pwm_duty_rb_g;
2024-04-16 16:09:34 +08:00
inline static uint32_t clip_u32(uint32_t x, uint32_t low, uint32_t up)
{
return (x > up ? up : x < low ? low
: x);
}
inline static int32_t clip_s32(int32_t x, int32_t low, int32_t up)
2024-04-16 16:09:34 +08:00
{
return (x > up ? up : x < low ? low
: x);
}
inline static float clip_f32(float x, float low, float up)
2024-01-16 20:03:21 +08:00
{
return (x > up ? up : x < low ? low
: x);
}
2024-06-18 16:11:59 +08:00
#define FIX_DRIVE 0
void by_pwm_init(void)
{
2024-06-28 18:23:53 +08:00
gpio_init(D4, GPO, 1, GPO_PUSH_PULL);
gpio_init(C8, GPO, 1, GPO_PUSH_PULL);
2024-03-22 11:35:15 +08:00
pwm_init(FAN_LL_PWM_PIN, 50, 500);
pwm_init(FAN_RL_PWM_PIN, 50, 500);
2024-07-05 03:29:56 +08:00
pwm_init(FAN_LS_PWM_PIN, 50, 500);
pwm_init(FAN_RS_PWM_PIN, 50, 500);
2024-07-07 23:08:49 +08:00
pwm_init(FAN_LB_PWM_PIN, 300, 300);
pwm_init(FAN_RB_PWM_PIN, 300, 300);
}
2024-03-22 11:35:15 +08:00
/**
* @brief
*
* @param update_pwm_duty1
* @param update_pwm_duty2
*/
2024-01-16 20:03:21 +08:00
void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2)
{
2024-04-16 16:09:34 +08:00
update_pwm_duty1 = clip_u32(update_pwm_duty1, 500, 1000);
update_pwm_duty2 = clip_u32(update_pwm_duty2, 500, 1000);
2024-03-22 11:35:15 +08:00
pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1);
pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2);
}
2024-03-22 11:35:15 +08:00
2024-03-02 16:05:24 +08:00
/**
2024-03-22 11:35:15 +08:00
* @brief
*
* @param pwm_duty_ls
* @param pwm_duty_rs
* @param pwm_duty_lb
* @param pwm_duty_rb
2024-03-02 16:05:24 +08:00
*/
2024-05-05 19:15:51 +08:00
void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_duty_lb, int32_t bpwm_duty_rb)
{
bpwm_duty_ls = clip_s32(bpwm_duty_ls, 500, 1000);
bpwm_duty_rs = clip_s32(bpwm_duty_rs, 500, 1000);
2024-07-07 23:08:49 +08:00
bpwm_duty_lb = clip_s32(bpwm_duty_lb, 2500, 6000);
bpwm_duty_rb = clip_s32(bpwm_duty_rb, 2500, 6000);
2024-07-05 03:29:56 +08:00
pwm_set_duty(FAN_LS_PWM_PIN, bpwm_duty_ls);
pwm_set_duty(FAN_RS_PWM_PIN, bpwm_duty_rs);
2024-07-07 23:08:49 +08:00
pwm_set_duty(FAN_LB_PWM_PIN, bpwm_duty_lb);
pwm_set_duty(FAN_RB_PWM_PIN, bpwm_duty_rb);
}