arduino驱动MG996舵机+stm32f103驱动舵机

2020/12/16更新stm32f103驱动舵机方式

舵机基本信息

arduino驱动MG996舵机+stm32f103驱动舵机_第1张图片

arduino驱动MG996舵机+stm32f103驱动舵机_第2张图片
舵机的控制信号周期为20MS的脉宽调制(PWM)信号,其中脉冲宽度从0.5-2.5MS,相对应的舵盘位置为0-180度。也就是说周期20Ms的脉冲,实际起作用的脉宽只有0.5-2.5MS。
arduino驱动MG996舵机+stm32f103驱动舵机_第3张图片

arduino驱动舵机

  • 接线
    arduino驱动MG996舵机+stm32f103驱动舵机_第4张图片
  • arduino自带舵机控制示范程序,运行过一次没细究
#include 

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
     
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
     
  for (pos = 0; pos <= 180; pos += 1) {
      // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) {
      // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

stm32驱动舵机方式

系统时钟配置为72MHz
定时器2的配置如下
arduino驱动MG996舵机+stm32f103驱动舵机_第5张图片

  • 主程序(每2秒切换一次角度)
    arduino驱动MG996舵机+stm32f103驱动舵机_第6张图片
  • 补充stm32时钟的理解
    arduino驱动MG996舵机+stm32f103驱动舵机_第7张图片

你可能感兴趣的:(arduino,arduino)