• 进电机之两相双极性步进电机仿真


    两相双极性步进电机

      有幸能从报废的机器的光驱中拆除几个电机,大概是像下方图片中那样的。但是这个电机只有四根外接的引脚,之前对不仅电机不是很懂,这两天通过查阅资料,了解到这个电机被称为两相双极性步进电机

       在此大概叙述下两相双极性电机的工作原理。如下图所示,步进电机只有两相(即两组定子),双极性代表两个定子缠绕的线圈可以两个方向通电。

      简单用图片表示下90度两相双极性步进电机转一圈的过程。1表示相1正向通电,1~表示相1方向通电。

      上面只是简单叙述了下两相双极性步进电机的工作原理,下面进入正题,使用proteus进行仿真Arduino来控制电机。

      仿真:使用L298(U3)驱动四线两相双极性步进电机。

      代码:MotorTwo为两相双极性电机驱动。

    /* Main.ino file generated by New Project wizard
     *
     * Created:   Thu Sep 5 2013
     * Processor: ATmega328P
     * Compiler:  Arduino AVR
     */
    
     #define LED ( 13 )
     #define MOTOR_PIN0 ( 0 )
     #define MOTOR_PIN1 ( 1 )
     #define MOTOR_PIN2 ( 2 )
     #define MOTOR_PIN3 ( 3 )
     #define MOTOR_PIN4 ( 4 )
     #define MOTOR_PIN5 ( 5 )
     #define MOTOR_PIN6 ( 6 )
     #define MOTOR_PIN7 ( 7 )
     #define MOTOR_ENA ( 8 )
     #define MOTOR_ENB ( 9 )
     
    void setup()
     { // put your setup code here, to run once:
       pinMode( LED, OUTPUT );
       pinMode( MOTOR_PIN0, OUTPUT );
       pinMode( MOTOR_PIN1, OUTPUT );
       pinMode( MOTOR_PIN2, OUTPUT );
       pinMode( MOTOR_PIN3, OUTPUT );
       pinMode( MOTOR_PIN4, OUTPUT );
       pinMode( MOTOR_PIN5, OUTPUT );
       pinMode( MOTOR_PIN6, OUTPUT );
       pinMode( MOTOR_PIN7, OUTPUT );
       pinMode( MOTOR_ENA, OUTPUT );
       pinMode( MOTOR_ENB, OUTPUT );
     }
    
     void MotorOne()
     {
       static int i = 3;
       
       switch( i-- )
       {
          case 0:
         digitalWrite( MOTOR_PIN0, HIGH );
         digitalWrite( MOTOR_PIN1, LOW );
         digitalWrite( MOTOR_PIN2, LOW );
         digitalWrite( MOTOR_PIN3, LOW );
         break;
          case 1:
         digitalWrite( MOTOR_PIN0, LOW );
         digitalWrite( MOTOR_PIN1, HIGH );
         digitalWrite( MOTOR_PIN2, LOW );
         digitalWrite( MOTOR_PIN3, LOW );
         break;
          case 2:
         digitalWrite( MOTOR_PIN0, LOW );
         digitalWrite( MOTOR_PIN1, LOW );
         digitalWrite( MOTOR_PIN2, HIGH );
         digitalWrite( MOTOR_PIN3, LOW );
         break;
          case 3:
         digitalWrite( MOTOR_PIN0, LOW );
         digitalWrite( MOTOR_PIN1, LOW );
         digitalWrite( MOTOR_PIN2, LOW );
         digitalWrite( MOTOR_PIN3, HIGH );
         break;
          default:
         break;
       }
       
       if( 0 > i )
          i = 3;
     }
     
     void LedLight()
     {
       static int i = 0;
       if( 0 == i++ )
          digitalWrite( LED, HIGH );
       else
          digitalWrite( LED, LOW );
          
       if( 2 <= i )
          i = 0;
     }
     
     void MotorTwo()
     {
       static int i = 0;
       
       switch( i++ )
       {
          case 0:
         digitalWrite( MOTOR_PIN4, HIGH );
         digitalWrite( MOTOR_PIN5, LOW );
         digitalWrite( MOTOR_PIN6, LOW );
         digitalWrite( MOTOR_PIN7, LOW );
         break;
          case 1:
         digitalWrite( MOTOR_PIN4, LOW );
         digitalWrite( MOTOR_PIN5, HIGH );
         digitalWrite( MOTOR_PIN6, LOW );
         digitalWrite( MOTOR_PIN7, LOW );
         break;
          case 2:
         digitalWrite( MOTOR_PIN4, LOW );
         digitalWrite( MOTOR_PIN5, LOW );
         digitalWrite( MOTOR_PIN6, HIGH );
         digitalWrite( MOTOR_PIN7, LOW );
         break;
          case 3:
         digitalWrite( MOTOR_PIN4, LOW );
         digitalWrite( MOTOR_PIN5, LOW );
         digitalWrite( MOTOR_PIN6, LOW );
         digitalWrite( MOTOR_PIN7, HIGH );
         break;
          default:
         break;
       }
       
       if( 4 <= i )
          i = 0;
     }
     
    void loop()
     { // put your main code here, to run repeatedly:
     
       MotorOne();
       LedLight();
       MotorTwo();
       
       delay(500);
       
     }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    一切伟大的思想和行动,都有一个微不足道的开始!

  • 相关阅读:
    VS中的路径宏
    Eigen3
    Python3.6 import源文件与编译文件的关系
    使用C语言扩展Python3
    mysql.connector 事务总结
    C++ -- STL泛型编程(一)之vector
    JSP -- include指令与include动作的区别
    Rails -- 关于Migration
    ruby -- 进阶学习(八)自定义方法route配置
    ruby -- 进阶学习(七)strong parameters之permitted.has_key
  • 原文地址:https://www.cnblogs.com/zhanghang-BadCoder/p/8728087.html
Copyright © 2020-2023  润新知