Welcome to 2DOF PTZ repository
MSPM0G3507 turtorials
2-DOF gimbal
1. Learning objectives
Drive 2-DOF gimbal.
2. Hardware connection
The servos used in this case are 180 and 270
MSPM0G3507 connected to servo pins
PA17 connected to 180-degree servo
PA18 connected to 270-degree servo
All modules connected together must share a common ground
3. Program description
- bsp_servo.h
xxxxxxxxxx#ifndef __BSP_SERVO_H_#define __BSP_SERVO_H_#include "ti_msp_dl_config.h"void Set_Servo270_Angle(unsigned int angle);void Set_Servo_Angle(unsigned int angle);unsigned int Get_Servo_Angle(void);unsigned int Get_Servo_Angle270(void);#endifDefine four servo control functions.
- bsp_servo.c
x
/****************************************************************** * Function name: Set_Servo270_Angle * Function description: Set 270 degree servo * Function parameter: angle = angle to be set, range 0-270 * Function return: None * 函数名称:Set_Servo270_Angle * 函数说明:设置270度舵机 * 函数形参:angle=要设置的角度,范围0-270 * 函数返回:无******************************************************************/void Set_Servo270_Angle(unsigned int angle){ uint32_t period = 400; if(angle > 270) { angle = 270; // 限制角度在0到270度之间 Limit the angle to between 0 and 270 degrees } Servo_Angle270 = angle; // 计算pwm占空比 Calculate pwm duty cycle // 0.5ms对应的计数 = 10 0.5ms corresponding count = 10 // 2.5ms对应的计数 = 50 Count corresponding to 2.5ms = 50 float min_count = 10.0f; float max_count = 50.0f; float range = max_count - min_count; float ServoAngle = min_count + (((float)angle / 270.0f) * range); DL_TimerG_setCaptureCompareValue(PWM_Servo_INST, (unsigned int)(ServoAngle + 0.5f), GPIO_PWM_Servo_C1_IDX);}unsigned int Get_Servo_Angle270(void){ return Servo_Angle270;Set_Servo270_Angle is used to set the angle of the servo motor, and Get_Servo_Angle270 is used to obtain the current angle of the servo motor.
Note: The project source code must be placed in the SDK path for compilation,
For example, the path: D:\TI\M0_SDK\mspm0_sdk_1_30_00_03\1.TB6612
