zoukankan      html  css  js  c++  java
  • 舵机驱动-GPIO MG995 STM32

    应为TIM都用光了,只能使用GPIO,使用GPIO 好处就是很好移植。程序如下:

    省略GPIO等初始化。PIN设置为

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;              
       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;

    #ifndef _MOTOR_STEP_H_
    #define _MOTOR_STEP_H_
    #define MIN_DEGREE (0)
    #define MAX_DEGREE (90)
    
    #include "stm32f10x.h"
    
    s8 MotorMoveDegree(u8 degree);
    
    #endif
    #include "motor_step.h"
    #include "ioctrl.h"
    #include "base_conf.h"
    #define US_NUM (445)
    static void Delay_100us(u16 us)//only for sysclock is 36M, Measured by OscillOscope,not a accurate delay
    {
        u16 i=US_NUM;
        while(us--)
        {
            while(i--)
            __NOP();
            i=US_NUM;
        }
    }
    
    s8 MotorMoveDegree(u8 degree)
    {
        u16 ON_us,OFF_us;
          u8 i=15;
            if(degree>MAX_DEGREE)return -1;
          ON_us = (u16)(25*degree/MAX_DEGREE);
          OFF_us = 200-ON_us;
          while(i--)
            {
                MotorStepSignal_ON();
                Delay_100us(ON_us);
                MotorStepSignal_OFF();
                Delay_100us(OFF_us);
            }
          return 0;    
    }
    void main()
    {
     //system_init();
         while(1)
        {
               MotorMoveDegree(90);
            Delay_ms(100);
            MotorMoveDegree(60);
            Delay_ms(100);
    
        }
    }
  • 相关阅读:
    FILE
    基础知识const/typedef/函数指针/回调函数
    strchr
    ftell
    rewind
    fread
    poj 2309BST解题报告
    hdoj 4004The Frog's Games解题报告
    哈理工oj 1353LCM与数对解题报告
    poj 2453An Easy Problem解题报告
  • 原文地址:https://www.cnblogs.com/ycpkbql/p/9122513.html
Copyright © 2011-2022 走看看