Car/Peripheral/Src/servo.c

17 lines
350 B
C
Raw Permalink Normal View History

2024-07-16 22:39:49 +08:00
#include "servo.h"
#include "tim.h"
void SERVO_Init()
{
2024-07-19 09:14:01 +08:00
__HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_4, 150);
2024-07-16 22:39:49 +08:00
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);
}
void SERVO_Rotate(uint8_t degree)
{
if (degree > 180)
degree = 180;
uint16_t compare = 200.0 / 180 * degree + 50;
__HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_4, compare);
}