feat: 完成互补pwm输出接口
This commit is contained in:
33
app/by_motion.c
Normal file
33
app/by_motion.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "by_motion.h"
|
||||
|
||||
#include "dwt_delay.h"
|
||||
#include "by_utils.h"
|
||||
|
||||
#define DRV_ENABLE() gpio_bits_set(GPIOB, GPIO_PINS_15)
|
||||
#define DRV_DISABLE() gpio_bits_reset(GPIOB, GPIO_PINS_15)
|
||||
|
||||
void by_motion_pwm_m1(int32_t pwm_duty)
|
||||
{
|
||||
pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦
|
||||
pwm_duty += 499;
|
||||
|
||||
// 互补 pwm 输出,499 为中值
|
||||
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, pwm_duty);
|
||||
}
|
||||
|
||||
void by_motion_pwm_m2(int32_t pwm_duty)
|
||||
{
|
||||
pwm_duty = clip_s32(pwm_duty, -449, 449); // 不可以拉满哦
|
||||
pwm_duty += 499;
|
||||
|
||||
// 互补 pwm 输出,499 为中值
|
||||
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, pwm_duty);
|
||||
}
|
||||
|
||||
void by_motion_init(void)
|
||||
{
|
||||
DRV_ENABLE();
|
||||
by_motion_pwm_m1(125);
|
||||
by_motion_pwm_m2(0);
|
||||
|
||||
}
|
||||
8
app/by_motion.h
Normal file
8
app/by_motion.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _BY_MOTION_H__
|
||||
#define _BY_MOTION_H__
|
||||
|
||||
#include "at32f413.h"
|
||||
|
||||
void by_motion_init(void);
|
||||
|
||||
#endif
|
||||
7
app/by_utils.c
Normal file
7
app/by_utils.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "by_utils.h"
|
||||
|
||||
inline int32_t clip_s32(int32_t x, int32_t low, int32_t up)
|
||||
{
|
||||
return (x > up ? up : x < low ? low
|
||||
: x);
|
||||
}
|
||||
8
app/by_utils.h
Normal file
8
app/by_utils.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _BY_UTILS_H__
|
||||
#define _BY_UTILS_H__
|
||||
|
||||
#include "at32f413.h"
|
||||
|
||||
int32_t clip_s32(int32_t x, int32_t low, int32_t up);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user