四方环视社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

全自动物体全景云台资料-------步进电机驱动

已有 838 次阅读2012-3-30 08:53 AM |系统分类:拍摄散记

 

AT89C2051/4051 Stepper Motor Interface Circuit

from:http://www.hobbyprojects.com/quick_circuits_reference/microcontroller_circuits/AT89C2051_stepper_motor_interface.html

 

M1 is a stepper taken from an old disk drive. There are five pins, i.e., common, coil 1, 2, 3 and 4. Resistance measured between common pin and each coil is about 75 Ohms. Driving current for each coil is then needed about 60mA at +5V supply. A Darlington transistor array, ULN2003 is used to increase driving capacity of the 2051 chip. Each output provides 500mA max at 50V. P1.4 to P1.7, four output pins are connected to the input of the ULN2003 as shown in the circuit. Four 4.7k resistors help the 2051 to provide more sourcing current from the +5V supply. The serial port is optional for your exercises. Many have provided useful technical, and application of using stepper, see the links below.

Driving Stepper Diagram
 


stepper.c

stepper.c
stepper.hex

I have changed a 10ms time base with a simple TF0 polling instead of using interrupt. The program is just to send the stepper's energizing pattern to the P1 every 10ms. Flag1 is used for intertask communication.

/*
 * STEPPER.C
 * sweeping stepper's rotor cw and cww 400 steps
 * Copyright (c) 1999 by W.Sirichote
 */

#include c:\mc51\8051io.h  /* include i/o header file */
#include c:\mc51\8051reg.h

register unsigned char j,flag1,temp;
register unsigned int cw_n,ccw_n;

unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}
#define n 400

/* flag1 mask byte
   0x01  run cw()
   0x02  run ccw()
*/

main()

{
  flag1=0;
  serinit(9600);
  disable();  /* no need timer interrupt */
  cw_n = n;    /* initial step number for cw */
  flag1 |=0x01; /* initial enable cw() */

 while(1){
  {
    tick_wait();  /* wait for 10ms elapsed */

    energize();   /* round-robin execution the following tasks every 10ms */
    cw();
    ccw();
  }
        }

}

cw(){
       if((flag1&0x01)!=0)
       {
       cw_n--;       /* decrement cw step number */
       if (cw_n !=0)
       j++;         /* if not zero increment index j */
       else
       {flag1&=~0x01; /* disable cw() execution */
       ccw_n = n;    /* reload step number to ccw counter */
       flag1 |=0x02; /* enable cww() execution */
       }
       }

}

ccw(){
       if((flag1&0x02)!=0)
       {
       ccw_n--;       /* decremnent ccw step number */
       if (ccw_n !=0)
       j--;          /* if not zero decrement index j */
       else
       {flag1&=~0x02; /* disable ccw() execution */
       cw_n = n;     /* reload step number to cw counter */
       flag1 |=0x01; /* enable cw() execution */
       }
       }

}

tick_wait(){   /* cputick was replaced by simpler ASM code 10ms wait */

    asm" JNB TCON.5,*";   /* wait for TF0 set */
    asm" CLR TCON.5";     /* clear TF0 for further set */
    asm" ORL TH0,#$DC";   /* reload TH0 with $DC, TL0 = 0 */
}

energize(){

    P1 = step[(j&0x07)];  /* only step 0-7 needed */
}

Exercises
  • change the speed showing the rotation becomes faster or slower than 10ms time delay
  • with an additional serial port, write an initializing function that receives ascii command from terminal to set the number of step for cw and ccw, say.
  • while energizing the stepper coils, write a function that read ascii character from terminal on the fly to decrease or increase rotating speed, say.

发表评论 评论 (2 个评论)

回复 阎涛 2012-3-30 08:54 AM
stepper.c

/*
* STEPPER.C
* sweeping stepper's rotor cw and cww 400 steps
* Copyright (c) 1999 by W.Sirichote
*/

#include c:\mc51\8051io.h  /* include i/o header file */
#include c:\mc51\8051reg.h

register unsigned char j,flag1,temp;
register unsigned int cw_n,ccw_n;

unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}
#define n 400

/* flag1 mask byte
   0x01  run cw()
   0x02  run ccw()
*/

main()

{
  flag1=0;
  serinit(9600);
  disable();  /* no need timer interrupt */
  cw_n = n;    /* initial step number for cw */
  flag1 |=0x01; /* initial enable cw() */

while(1){  
  {
    tick_wait();  /* wait for 10ms elapsed */

    energize();   /* round-robin execution the following tasks every 10ms */
    cw();
    ccw();
  }
        }

}

cw(){
       if((flag1&0x01)!=0)
       {
        cw_n--;       /* decrement cw step number */
        if (cw_n !=0)
         j++;         /* if not zero increment index j */
         else
         {flag1&=~0x01; /* disable cw() execution */
          ccw_n = n;    /* reload step number to ccw counter */
          flag1 |=0x02; /* enable cww() execution */
          }
       }
         
}

ccw(){
       if((flag1&0x02)!=0)
       {
        ccw_n--;       /* decremnet ccw step number */
        if (ccw_n !=0)
         j--;          /* if not zero decrement index j */
         else
         {flag1&=~0x02; /* disable ccw() executon */
          cw_n = n;     /* reload step number to cw counter */
          flag1 |=0x01; /* enable cw() execution */
          }
       }
         
}

tick_wait(){   /* cputick was replaced by simpler ASM code 10ms wait */

    asm" JNB TCON.5,*";   /* wait for TF0 set */
    asm" CLR TCON.5";     /* clear TF0 for further set */
    asm" ORL TH0,#$DC";   /* reload TH0 with $DC, TL0 = 0 */
}

energize(){

    P1 = step[(j&0x07)];  /* only step 0-7 needed */
}
回复 阎涛 2012-3-30 08:55 AM
stepper.hex

:0300000002000EED
:03000300020028D0
:20000B0002001F75810FD2AFD2A912002B80FE12001B80FB758CDC758A00050832050832F6
:20002B007400F50A748075F025C0E0C0F012013215811581120158749075F001F50C85F0B8
:20004B000DE50A4401F50A12011212011B1200621200BA02005222E50A540175F0007B0028
:20006B007C001201DD45F070030200B9E50C850DF01201C3F50C85F00D1201BAE50C850D8A
:20008B00F07B007C001201DD45F070030200A3E50904F509140200B9E50A54FEF50A74902E
:2000AB0075F001F50E85F00FE50A4402F50A22E50A540275F0007B007C001201DD45F070BC
:2000CB0003020111E50E850FF01201C3F50E85F00F1201BAE50E850FF07B007C001201DDFF
:2000EB0045F070030200FBE50914F50904020111E50A54FDF50A749075F001F50C85F00D0C
:20010B00E50A4401F50A22308DFDC28D438CDC22E509540779087A0275F00012017D898263
:20012B008A83E493F5902278FB12015B8603088604748075F0701201841201CA758921F53C
:20014B008DF58B75885975985222D2AF22C2AF22C82581C822C92581C97A0022D083D082A9
:20016B00CF2581F581CFC082C08322CF2581F581CF2229F9E5F03AFA22C002C001AAF0F9D4
:20018B007E007D007F11C3E933F9EA33FADF08F5F0E9D001D00222ED33FDEE33FEC3ED9BD9
:2001AB00F5F0EE9C40E0ADF0FED380DB1201BA04700205F0221201C314B4FF0215F02212AA
:2001CB0001C3F4C5F0F4C5F0221201E76009E4F5F0221201E760F7E4F5F00422C5F0C39C3A
:2001EB007003E5F09B22FBE493CB22FCE493FB740193CC22FAE493F9740193CA2280C0404E
:05020B0060203010909E
:00000001FF

facelist

您需要登录后才可以评论 登录 | 立即注册

QQ|手机版|网站帮助|关于我们|联系我们|四方环视社区 ( 京ICP备16029184号-5

GMT+8, 2020-1-21 11:30 AM , Processed in 0.049807 second(s), 13 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部