Files
BC2D-firmware/app/by_motion.c
CaoWangrenbo 8408ab1cf3 feat: 移植 lwprintf
feat: 创建 can 发送接口
feat: 添加编码器读数接口
2024-04-19 17:16:24 +08:00

50 lines
1.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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)
int16_t speed_m1;
int16_t speed_m2;
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);
}
int16_t by_motion_get_speed_m1(void)
{
speed_m1 = (int16_t)tmr_counter_value_get(TMR2);
tmr_counter_value_set(TMR2, 0);
return speed_m1;
}
int16_t by_motion_get_speed_m2(void)
{
speed_m2 = (int16_t)tmr_counter_value_get(TMR3);
tmr_counter_value_set(TMR3, 0);
return speed_m2;
}
void by_motion_init(void)
{
DRV_ENABLE();
by_motion_pwm_m1(-125);
by_motion_pwm_m2(0);
}