25 lines
550 B
C
25 lines
550 B
C
#include "ServoMotor.h"
|
|
#include "Timer.h"
|
|
|
|
#define SERVO_MOTO_FREQ 50
|
|
|
|
void ServoMotor_conf(TIM_TypeDef * timer, int channel)
|
|
{
|
|
Timer_pwmo_conf(timer, channel, SERVO_MOTO_FREQ, 0);
|
|
}
|
|
|
|
void ServoMotor_start(TIM_TypeDef * timer)
|
|
{
|
|
Timer_start(timer);
|
|
}
|
|
|
|
void ServoMotor_setAngle(TIM_TypeDef * timer, int channel, int angle)
|
|
{
|
|
Timer_pwmo_setDutyCycle(timer, channel, ((float) angle) / 359.0);
|
|
}
|
|
|
|
int ServoMotor_getAngle(TIM_TypeDef * timer, int channel)
|
|
{
|
|
const float dutyCycle = Timer_pwmo_getDutyCycle(timer, channel);
|
|
return 359 * dutyCycle;
|
|
}
|