这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 步进电机驱动

共2条 1/1 1 跳转至

步进电机驱动

院士
2006-09-17 18:14:16     打赏
步进电机驱动



关键词: 步进     电机     驱动    

院士
2006-12-22 22:43:00     打赏
2楼
问 我用52单片机和uln2003做步进电机驱动!电机是四相六线的,每步7。5度
作出脉冲信号来,只能驱动一个方向转动!另一个方向只是震动
那位高手大哥给分析一下原因啊!
小弟感激不尽!  1: 不好弄52产生的脉冲好像不怎么样。驱动步进电机的脉冲频率有一定范围,波形也有影响。要翻转好像还要进行一些编程处理的。单片机io出来脉冲,波形不好。总之,比较复杂。 2: 还有没有好办法!谢谢这位仁兄,那有没有相关的资料啊?给提供一下啊!我刚刚搞单片机
还有没有好的方法驱动步进电机啊?谢谢! 3: 呵呵 ,偶写的程序,楼主自己去改一下应该可以了#include<reg51.h>

sbit P3_2 = P3 ^ 2;  //启动电机正转
sbit P3_4 = P3 ^ 4;  //制动电机
sbit P3_5 = P3 ^ 5;  //电机反转

bit sw1 = 0;
bit sw2 = 0;
bit sw3 = 0;

void Delay(unsigned char Delay)
{
    unsigned int i;
    for(; Delay > 0; Delay--)
    {
        for(i = 0; i < 125; i++);  //1ms
    }
}

void Run(void)   //电机运行,送显
{
        P0 = 0x6d;
        P2 = 0x00;
        Delay(1);

        P0 = 0x50;  //r
        P2 = 0x04;
        Delay(1);
        
        P0 = 0x1c;  //u
        P2 = 0x02;
        Delay(1);

        P0 = 0x54;  //n
        P2 = 0x01;
        Delay(1);

}

void Stop(void)   //电机停止运行,送显!
{
//    unsigned char x = 200;
//    while(--x != 0)
//    {
        P1 = 0xff;
    
        P0 = 0x6d;//s
        P2 = 0x08;
        Delay(2);

        P0 = 0x31;//t
        P2 = 0x04;
        Delay(2);
        
        P0 = 0x3f;//o
        P2 = 0x02;
        Delay(2);

        P0 = 0x73;//p
        P2 = 0x01;
        Delay(2);

        P2 = 0;        
//    }
}

void main(void)
{
    unsigned char a;
    //单相4拍方式控制:A->B->C->D;
       //unsigned char code plus[ ] = {0xfe, 0xfd, 0xfb, 0xf7}; //正转
    //unsigned char code minu[ ] = {0xf7, 0xfb, 0xfd, 0xfe}; //反转

    //4相8拍方式:A->AB->B->BC->C->CD->D->DA;
    unsigned char code plus[ ] = {0xfe, 0xfc, 0xfd, 0xf9, 0xfb, 0xf3, 0xf7, 0xf6};//正转
  //unsigned char code minu[ ] = {0xf6, 0xf7, 0xf3, 0xfb, 0xf9, 0xfd, 0xfc, 0xfe};//反转

    //双4拍工作方式,AB->BC->CD->DA;
    //unsigned char code plus[ ] = {0xfc, 0xf9, 0xf3, 0xf6};//正转
    //unsigned char code minu[ ] = {0xf6, 0xf3, 0xf9, 0xfc};//反转
    while( 1 )
    {
        P2 = 0;

        if(P3_2 == sw1)  
        {
            Delay(10);  //delay 10ms
            if(P3_2 == sw1)
            {
                sw1 = 0;
                   while(1)
                 {
                    for(a = 0; a < 8; a++)  //正转
                    {
                        P1 = plus[ a ];
                           Delay(5);
                        P1 = 0x00;
                        Delay(1);
                        Run( ); //显示RUN
                    }

                    if(P3_4 == sw2)
                    {
                        
                        Delay(10);
                        if(P3_4 == sw2)
                        {
                            sw1 = 1;
                            while(1)
                            {
                                Stop( );//停止

                                if(P3_2 == 0)
                                {
                                    Delay(10);
                                    if(P3_2 == 0)
                                    {
                                        sw1 = 0;
                                        break;
                                    }
                                }
                            }//while
                        }
                    }
                }//while
            }
        }//if

    /*    for(b = 0; b < 255; b++)  //反转
        {
            for(a = 0; a < 8; a++)
            {
                  P1 = minu[ a ];
                   Delay(5);
                P1 = 0x00;
                Delay(1);

                Run(); //显示RUN
            }
        }
            
        Stop();    //停止*/
    }//while
}

4: 买驱动器我花钱买了驱动器,加上电机一共380。通过单片机的一个io给脉冲驱动器,驱动器就会根据脉冲产生电机的驱动脉冲了。这是最简单的方法了。正转反转,电机驱动器的说明书会讲。

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]