Servo Motor library for stm32 series
-
+ ARM STM32 Series
void Init(TIM_HandleTypeDef *htim, uint32_t channel, uint16_t minPPMPulseWidth, uint16_t maxPPMPulseWidth, float maxAngle);
void SetPPMPulseWidth(uint16_t Width);
void SetAngle(float ang);
non
-
-
Initializer:
Servo(TIM_HandleTypeDef *htim, uint32_t channel, uint16_t minPPMPulseWidth, uint16_t maxPPMPulseWidth, float maxAngle);
-
Parameters:
- htim : pointer to hal timer object
- channel : PWM channel of pulse pin
- minPPMPulseWidth : minimum pulse width of pwm signal for servo
- maxPPMPulseWidth : maximum pulse width of pwm signal for servo
- maxAngle : maximum supported angle of sevo
-
Example:
Servo myMotor(&htim1, TIM_CHANNEL_4, 400, 2000, 180.0f);
-
-
-
Initializer:
Servo::Init(TIM_HandleTypeDef *htim, uint32_t channel, uint16_t minPPMPulseWidth, uint16_t maxPPMPulseWidth, float maxAngle);
-
Parameters:
- htim : pointer to hal timer object
- channel : PWM channel of pulse pin
- minPPMPulseWidth : minimum pulse width of pwm signal for servo
- maxPPMPulseWidth : maximum pulse width of pwm signal for servo
- maxAngle : maximum supported angle of sevo
-
Example:
Servo myMotor; myMotor.Init(&htim1, TIM_CHANNEL_4, 400, 2000, 180.0f);
-
myMotor.SetAngle(20);
myMotor.SetPPMPulseWidth(400);
int main()
{
//Your codes
Timer_Init(); // Initialize your timer with 1MHz frequency and 10~20ms period
Servo myMotor;
myMotor.Init(&htim1, TIM_CHANNEL_4, 400, 2000, 180.0f);
while(1)
{
if (myMotor.Angle < myMotor.MaxAngle)
{
myMotor.SetAngle(myMotor.Angle + 5);
HAL_Delay(100);
}
}
}
- Run on STM32 Fx cores