简体   繁体   English

使用 STM32 和 Mbed 库控制经典伺服电机

[英]Control classic Servo Motor with STM32 and Mbed library

I'm using STM32 F401RE board and i'm trying to do a very simple thing.我正在使用STM32 F401RE板,我正在尝试做一件非常简单的事情。 I want to control a servo (0-180).我想控制伺服(0-180)。 The problem is that it looks like it doesn't respound to my commands.问题是它看起来不像我的命令。

#include "mbed.h"

PwmOut myServo(D9);

int main() {
    myServo.period_ms(20);    

    while(1)
    {
        myServo.pulsewidth_ms(1);
    }
}

The Servo Motor i'm using.我正在使用的伺服电机 At the beginning i though something is wrong with my board pinout or pinout meaning , but it seems like D9 is the same with PC_7 .一开始我虽然我的电路板引脚排列引脚排列含义有问题,但似乎D9PC_7相同。 My servo is properly installed and is supplyed by 5V source.我的伺服器安装正确,由 5V 电源供电。 I tried many tutorials i've found online but no one worked.我尝试了很多我在网上找到的教程,但没有一个有用。 This is the class with all methods.是具有所有方法的 class。

If i generate the same PWM with an oscilloscope it does work.如果我用示波器生成相同的 PWM,它确实可以工作。

I figured out what the problem was.我弄清楚了问题所在。 I didn't had all grounds connected together because i was powering the STM32 via USB.我没有将所有接地连接在一起,因为我通过 USB 为STM32供电。 When i was testing, the STM was connected to PC so the ground of the servo was different from the ground of the STM32.我在测试时,STM连接到PC,所以伺服的接地与STM32的接地不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM