Posts Tagged ‘Packet-based Interface for Stepper Motor’

The circuit diagram of the packet-based stepper motor interface is asshown in Figure. The commands to be emulated from the Hyper-Terminal and the corresponding control action are given in the program source code. The interface is based on UN2003 driver popularly used for many stepper motor control applications. It is a 7-bit, 50V 500mA TTL-input NPN Darlington driver. The drivers does not need power supply; the VDD pin is the common cathode of the seven integrated protection diodes.

stepper motor controll interface

stepper motor controll interface

Program Source Code
******************************************************
#include<REG52.h>
unsigned char mot[4] = {0x0a,0x06,0x05,0x09};
unsigned char run, clkwise;
int interpret, mode, count;
char packet[5]; /∗p[0] is control char∗/
char index; /∗others may contain data last must contain end char,
i.e., ‘z’ ∗/
void init(void);
void delay (int m);
void init()
{TMOD=0x20;
TH1=0xFD; /∗select baud rate 9600∗/
SCON=0x50;
TR1=1; /∗ start timer∗/
}

void main(void)
{int k=0;
char i;
init(); ES=1; EA=1;
run=1;
clkwise = 1;
for (i=0;i<5;i++){ packet[i]=0;
}index=0;
interpret=0;
while(1)
{while(mode==0){ /∗continues rotation∗/
while(run==1)
{if(clkwise==1){ for (i=0;i<4 ; i++) /∗ clkwise dir∗/
{ P0= mot [i];
delay(1000);
}} else
{for (i=3;i>=0 ; i−−) /∗anticlkwise dir∗/
{ P0= mot [i];
delay(1000);
}
}}
}}
while(mode==1) /∗number of step’s given by user∗/
{while((run==1)&&(count>0))
{if(clkwise==1){ for ( i=0;i<4 ; i++)
{ P0= mot [i];
delay(1000);
}
}

else
{for ( i=3;i>=0 ; i−−)
{P0= mot [i];
delay(1000);
}}
count−−;
}
}
} void delay (int m)
{ int z;
z=m;
while (m>0)
{ m−−;}
}
void serialisr() interrupt 4
{ unsigned char y;
char i;
RI=0;
y=SBUF; /∗ contents of buffer
in y∗/
TI=0; SBUF=y; while (!TI);TI=0; /∗similtaneusly
display∗/
packet[index]=y;
index++;
if (y==‘Z’) { interpret =1; /∗ indicates end of packet∗/
index = 0;
}

else interpret = 0;
if (interpret==1)
{

switch(packet[0])
{

case ‘S’:
run=0;
break;

case ‘R’:
run=1;
break;
case ‘A’:
clkwise=0;
break;
case ‘C’:
clkwise=1;
break;
case ‘D’:
if (packet[1]==’0’)
mode=0;
break;
case ‘E’:
if (packet[1]==’1’)
mode=1;
break;
case ‘F’: /∗variable size packet∗/
count=(packet[3]-0x30)+((packet[2]-0x30)∗10)+((packet[1]-
0x30)∗100);
break; /∗packet[3]=units……….∗/
} for (i=0;i<5;i++){ packet[i]=0;
}interpret=0;
}
}

******************************************************