feat: 更新风扇驱动接口
This commit is contained in:
@@ -3,25 +3,39 @@
|
|||||||
#include "zf_common_headfile.h"
|
#include "zf_common_headfile.h"
|
||||||
#include "jj_blueteeth.h"
|
#include "jj_blueteeth.h"
|
||||||
|
|
||||||
#define FAN_LL_PWM_PIN TIM8_PWM_MAP0_CH1_C6 // 左升力风扇
|
#define FAN_LL_PWM_PIN TIM8_PWM_MAP1_CH1_B6 // 左升力风扇
|
||||||
#define FAN_RL_PWM_PIN TIM8_PWM_MAP0_CH2_C7 // 右升力风扇
|
#define FAN_RL_PWM_PIN TIM8_PWM_MAP1_CH2_B7 // 右升力风扇
|
||||||
#define FAN_LS_PWM_PIN TIM4_PWM_MAP1_CH4_D15 // 左侧动力风扇
|
// M4
|
||||||
#define FAN_RS_PWM_PIN TIM4_PWM_MAP1_CH3_D14 // 右侧动力风扇
|
#define FAN_LS_PWM_A_PIN TIM10_PWM_MAP3_CH1_D1 // 左侧动力风扇
|
||||||
#define FAN_LB_PWM_PIN TIM4_PWM_MAP1_CH2_D13 // 左后动力风扇
|
#define FAN_LS_PWM_B_PIN TIM10_PWM_MAP3_CH2_D3 // 左侧动力风扇
|
||||||
#define FAN_RB_PWM_PIN TIM4_PWM_MAP1_CH1_D12 // 右后动力风扇
|
// M1
|
||||||
|
#define FAN_RS_PWM_A_PIN TIM4_PWM_MAP1_CH1_D12 // 右侧动力风扇
|
||||||
|
#define FAN_RS_PWM_B_PIN TIM4_PWM_MAP1_CH2_D13 // 右侧动力风扇
|
||||||
|
// M3
|
||||||
|
#define FAN_LB_PWM_A_PIN TIM10_PWM_MAP3_CH3_D5 // 左后动力风扇
|
||||||
|
#define FAN_LB_PWM_B_PIN TIM10_PWM_MAP3_CH4_D7 // 左后动力风扇
|
||||||
|
// M2
|
||||||
|
#define FAN_RB_PWM_A_PIN TIM4_PWM_MAP1_CH3_D14 // 右后动力风扇
|
||||||
|
#define FAN_RB_PWM_B_PIN TIM4_PWM_MAP1_CH4_D15 // 右后动力风扇
|
||||||
|
|
||||||
uint32_t pwm_duty_ls_g;
|
int32_t pwm_duty_ls_g;
|
||||||
uint32_t pwm_duty_rs_g;
|
int32_t pwm_duty_rs_g;
|
||||||
uint32_t pwm_duty_lb_g;
|
int32_t pwm_duty_lb_g;
|
||||||
uint32_t pwm_duty_rb_g;
|
int32_t pwm_duty_rb_g;
|
||||||
|
|
||||||
static uint32_t myclip(uint32_t x, uint32_t low, uint32_t up)
|
inline static uint32_t clip_u32(uint32_t x, uint32_t low, uint32_t up)
|
||||||
{
|
{
|
||||||
return (x > up ? up : x < low ? low
|
return (x > up ? up : x < low ? low
|
||||||
: x);
|
: x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float myclip_f(float x, float low, float up)
|
inline static uint32_t clip_s32(int32_t x, int32_t low, int32_t up)
|
||||||
|
{
|
||||||
|
return (x > up ? up : x < low ? low
|
||||||
|
: x);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static float clip_f32(float x, float low, float up)
|
||||||
{
|
{
|
||||||
return (x > up ? up : x < low ? low
|
return (x > up ? up : x < low ? low
|
||||||
: x);
|
: x);
|
||||||
@@ -32,10 +46,14 @@ void by_pwm_init(void)
|
|||||||
pwm_init(FAN_LL_PWM_PIN, 50, 500);
|
pwm_init(FAN_LL_PWM_PIN, 50, 500);
|
||||||
pwm_init(FAN_RL_PWM_PIN, 50, 500);
|
pwm_init(FAN_RL_PWM_PIN, 50, 500);
|
||||||
|
|
||||||
pwm_init(FAN_LS_PWM_PIN, 4000, 0);
|
pwm_init(FAN_LS_PWM_A_PIN, 4000, 0);
|
||||||
pwm_init(FAN_RS_PWM_PIN, 4000, 0);
|
pwm_init(FAN_LS_PWM_B_PIN, 4000, 0);
|
||||||
pwm_init(FAN_LB_PWM_PIN, 4000, 0);
|
pwm_init(FAN_RS_PWM_A_PIN, 4000, 0);
|
||||||
pwm_init(FAN_RB_PWM_PIN, 4000, 0);
|
pwm_init(FAN_RS_PWM_B_PIN, 4000, 0);
|
||||||
|
pwm_init(FAN_LB_PWM_A_PIN, 4000, 0);
|
||||||
|
pwm_init(FAN_LB_PWM_B_PIN, 4000, 0);
|
||||||
|
pwm_init(FAN_RB_PWM_A_PIN, 4000, 0);
|
||||||
|
pwm_init(FAN_RB_PWM_B_PIN, 4000, 0);
|
||||||
// system_delay_ms(3000);
|
// system_delay_ms(3000);
|
||||||
// // pwm_init(FAN_LS_PWM_PIN, 50, 1000); // 动力风扇左 1
|
// // pwm_init(FAN_LS_PWM_PIN, 50, 1000); // 动力风扇左 1
|
||||||
// // pwm_init(FAN_RS_PWM_PIN, 50, 1000); // 动力风扇右 1
|
// // pwm_init(FAN_RS_PWM_PIN, 50, 1000); // 动力风扇右 1
|
||||||
@@ -57,8 +75,8 @@ void by_pwm_init(void)
|
|||||||
*/
|
*/
|
||||||
void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t 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_duty1 = clip_u32(update_pwm_duty1, 500, 1000);
|
||||||
update_pwm_duty2 = myclip(update_pwm_duty2, 500, 1000);
|
update_pwm_duty2 = clip_u32(update_pwm_duty2, 500, 1000);
|
||||||
pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1);
|
pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1);
|
||||||
pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2);
|
pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2);
|
||||||
}
|
}
|
||||||
@@ -71,19 +89,47 @@ void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2)
|
|||||||
* @param pwm_duty_lb
|
* @param pwm_duty_lb
|
||||||
* @param pwm_duty_rb
|
* @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)
|
void by_pwm_power_duty(int32_t pwm_duty_ls, int32_t pwm_duty_rs, int32_t pwm_duty_lb, int32_t pwm_duty_rb)
|
||||||
{
|
{
|
||||||
pwm_duty_ls = myclip(pwm_duty_ls, 0, 8000);
|
pwm_duty_ls = clip_s32(pwm_duty_ls, 0, 8000);
|
||||||
pwm_duty_rs = myclip(pwm_duty_rs, 0, 8000);
|
pwm_duty_rs = clip_s32(pwm_duty_rs, 0, 8000);
|
||||||
pwm_duty_lb = myclip(pwm_duty_lb, 0, 8000);
|
pwm_duty_lb = clip_s32(pwm_duty_lb, 0, 8000);
|
||||||
pwm_duty_rb = myclip(pwm_duty_rb, 0, 8000);
|
pwm_duty_rb = clip_s32(pwm_duty_rb, 0, 8000);
|
||||||
|
|
||||||
pwm_duty_ls_g = pwm_duty_ls;
|
pwm_duty_ls_g = pwm_duty_ls;
|
||||||
pwm_duty_rs_g = pwm_duty_rs;
|
pwm_duty_rs_g = pwm_duty_rs;
|
||||||
pwm_duty_lb_g = pwm_duty_lb;
|
pwm_duty_lb_g = pwm_duty_lb;
|
||||||
pwm_duty_rb_g = pwm_duty_rb;
|
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);
|
if (pwm_duty_ls >= 0) {
|
||||||
pwm_set_duty(FAN_LB_PWM_PIN, pwm_duty_lb);
|
pwm_set_duty(FAN_LS_PWM_A_PIN, pwm_duty_ls);
|
||||||
pwm_set_duty(FAN_RB_PWM_PIN, pwm_duty_rb);
|
pwm_set_duty(FAN_LS_PWM_B_PIN, 0);
|
||||||
|
} else {
|
||||||
|
pwm_set_duty(FAN_LS_PWM_A_PIN, 0);
|
||||||
|
pwm_set_duty(FAN_LS_PWM_B_PIN, -1 * pwm_duty_ls);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pwm_duty_rs >= 0) {
|
||||||
|
pwm_set_duty(FAN_RS_PWM_A_PIN, pwm_duty_rs);
|
||||||
|
pwm_set_duty(FAN_RS_PWM_B_PIN, 0);
|
||||||
|
} else {
|
||||||
|
pwm_set_duty(FAN_RS_PWM_A_PIN, 0);
|
||||||
|
pwm_set_duty(FAN_RS_PWM_B_PIN, -1 * pwm_duty_rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pwm_duty_lb >= 0) {
|
||||||
|
pwm_set_duty(FAN_LB_PWM_A_PIN, pwm_duty_lb);
|
||||||
|
pwm_set_duty(FAN_LB_PWM_B_PIN, 0);
|
||||||
|
} else {
|
||||||
|
pwm_set_duty(FAN_LB_PWM_A_PIN, 0);
|
||||||
|
pwm_set_duty(FAN_LB_PWM_B_PIN, -1 * pwm_duty_lb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pwm_duty_rb >= 0) {
|
||||||
|
pwm_set_duty(FAN_RB_PWM_A_PIN, pwm_duty_rb);
|
||||||
|
pwm_set_duty(FAN_RB_PWM_B_PIN, 0);
|
||||||
|
} else {
|
||||||
|
pwm_set_duty(FAN_RB_PWM_A_PIN, 0);
|
||||||
|
pwm_set_duty(FAN_RB_PWM_B_PIN, -1 * pwm_duty_rb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "ch32v30x.h"
|
#include "ch32v30x.h"
|
||||||
|
|
||||||
extern uint32_t pwm_duty_ls_g;
|
extern int32_t pwm_duty_ls_g;
|
||||||
extern uint32_t pwm_duty_rs_g;
|
extern int32_t pwm_duty_rs_g;
|
||||||
extern uint32_t pwm_duty_lb_g;
|
extern int32_t pwm_duty_lb_g;
|
||||||
extern uint32_t pwm_duty_rb_g;
|
extern int32_t pwm_duty_rb_g;
|
||||||
|
|
||||||
extern void by_pwm_init(void);
|
extern void by_pwm_init(void);
|
||||||
extern void by_pwm_update_duty(uint32_t update_pwm_duty1,uint32_t update_pwm_duty2);
|
extern void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2);
|
||||||
extern void by_pwm_power_duty(uint32_t power_pwm_duty_l1, uint32_t power_pwm_duty_r1,uint32_t power_pwm_duty_l2, uint32_t power_pwm_duty_r2);
|
extern void by_pwm_power_duty(int32_t pwm_duty_ls, int32_t pwm_duty_rs, int32_t pwm_duty_lb, int32_t pwm_duty_rb);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -124,7 +124,7 @@ void sport_motion(void)
|
|||||||
pwm_duty_lb = (uint32_t)myclip_f(1.f * out_speed + out_gyro, 0.0f, 8000.f);
|
pwm_duty_lb = (uint32_t)myclip_f(1.f * out_speed + out_gyro, 0.0f, 8000.f);
|
||||||
pwm_duty_rb = (uint32_t)myclip_f(1.f * out_speed - out_gyro, 0.0f, 8000.f);
|
pwm_duty_rb = (uint32_t)myclip_f(1.f * out_speed - out_gyro, 0.0f, 8000.f);
|
||||||
|
|
||||||
by_pwm_power_duty(pwm_duty_ls, pwm_duty_rs, pwm_duty_lb, pwm_duty_rb);
|
by_pwm_power_duty((int32_t)pwm_duty_ls, (int32_t)pwm_duty_rs, (int32_t)pwm_duty_lb, (int32_t)pwm_duty_rb);
|
||||||
} else {
|
} else {
|
||||||
by_pwm_power_duty(0, 0, 0, 0);
|
by_pwm_power_duty(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user