Motor Control
Motor Control
ON
Submitted by:
DEBRAJ ADHIKARI
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to Prof. Dipankar
Biswas of Department of Radiophysics and Electronics,
University College of Science and Technology, University of
Calcutta. Without his able guidance and patience, this
project would not have been completed.
Date:
--------------------------
Place: Debraj
Adhikari.
UNIVERSITY COLLEGE OF TECHNOLOGY
INSTITUTE OF RADIOPHYSICS AND ELECTRONICS
------------------------------------
Prof. Dipankar Biswas
CONTENTS
• Objective
• Introduction
• Apparatus required
• Circuit diagram
• Connector diagram
• Transistor component
• Motor description
• Theory
• C Source code
• Bibliography
OBJECTIVE
The aim of this project is to drive a stepper motor through
port programming in C. The serial printer port is
programmed to monitor the control of the stepper motor.
The motor can be controlled to rotate clockwise or
anticlockwise, to accelerate and decelerate and to oscillate.
INTRODUCTION
A stepper motor is brushless, synchronous electric motor
that can divide a full rotation into a large number of steps.
The motor's position can be controlled precisely, without any
feedback mechanism (see open loop control). Stepper
motors are similar to switched reluctance motors , which are
very large stepping motors with a reduced pole count, and
generally are closed-loop commutated.
1.8 DEG/STEP
0.16A/PHASE
2. Female D-25 Connector
3. BC 547 Transistor
4. Rectifying Diodes
5. Power Supply +5V,1.5A
CIRCUIT DIAGRAM
CONNECTOR DIAGRAM
TRANSISTOR COMPONENT
BC547 Transistor Diagram
FEATURES
LIMITING VALUES
MOTOR DESCRIPTION
TYPE KP39HM2-S07A
In the above figure the stepper motor has five wires namely
Yellow, Brown, Orange, Black and Red. To make the motor
rotate in a particular direction (clockwise or anticlockwise),
the wires are needed to be connected in a sequence.
D D D D
0 1 2 3
Port 1 0 0 0
1
Port 0 1 0 0
2
Port 0 0 1 0
3
Port 0 0 0 1
4
void main()
{
int i=1,choice,start_speed,end_speed,acc_step;
int speed=10,oscillate,k,l;
char ch,ch1;
clrscr();
while(1)
{ clrscr();
scanf("%d",&choice);
switch(choice)
{
case 1:
if(ch1=='c')
{
i=1;
while(!kbhit())
{
if(i==1)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
i=0;
}
i++;
} //end of while(!kbhit())
} //end of if(ch1)
if(ch1=='a')
{
i=1;
while(!kbhit())
{
if(i==1)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
i=0;
}
i++;
} //end of while(!kbhit())
} //end of if(ch1)
break;
case 2:
exit(0);
case 3:
if(ch1=='c')
{
i=1;
while(!kbhit())
{
if(i==1)
{
outportb(PORT,1);
delay(start_speed);
}
if(i==2)
{
outportb(PORT,2);
delay(start_speed);
if(i==3)
{
outportb(PORT,4);
delay(start_speed);
if(i==4)
{
outportb(PORT,8);
delay(start_speed);
}
if(end_speed<start_speed)
{
start_speed-=acc_step;
printf("\n%d",start_speed);
}
else
{
printf("\nAcceleration Ends");
break;
}
if(i==4)
{
i=0;
}
i++;
} //end of while(!kbhit())
} //end of if(ch1)
if(ch1=='a')
{
i=1;
while(!kbhit())
{
if(i==1)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(end_speed<start_speed)
{
start_speed-=acc_step;
}
else
{
printf("\nAcceleration Ends");
break;
}
if(i==4)
{
i=0;
}
i++;
} //end of while(!kbhit())
} //end of if(ch1)
case 4:
if(ch1=='c')
{
i=1;
while(!kbhit())
{
if(i==1)
{
outportb(PORT,1);
delay(start_speed);
}
if(i==2)
{
outportb(PORT,2);
delay(start_speed);
}
if(i==3)
{
outportb(PORT,4);
delay(start_speed);
}
if(i==4)
{
outportb(PORT,8);
delay(start_speed);
}
if(end_speed>start_speed)
{
start_speed+=acc_step;
}
else
{
printf("\nAcceleration Ends");
break;
}
if(i==4)
{
i=0;
}
i++;
} //end of while(!kbhit())
} //end of if(ch1)
if(ch1=='a')
{
i=1;
while(!kbhit())
{
if(i==1)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(end_speed>start_speed)
{
start_speed+=acc_step;
}
else
{
printf("\nDeceleration Ends");
break;
}
if(i==4)
{
i=0;
}
i++;
} //end of while(!kbhit())
} //end of if(ch1)
case 5:
printf("\nEnter Speed of Rotation(in millisec):\t");
scanf("%d",&speed);
L1:
if(ch1=='a')
{
i=1; k=0; l=0;
for(k=0;k<=oscillate;k++)
{
if(i==1)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
i=0;
}
i++;
}
i=1;
for(l=0;l<=oscillate;l++)
{
if(i==1)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
i=0;
}
i++;
}
while(!kbhit())
goto L1;
} //end of if(ch1=='a')
L2:
if(ch1=='c')
{
i=1; k=0; l=0;
for(k=0;k<=oscillate;k++)
{
if(i==1)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
i=0;
}
i++;
}
i=1;
for(l=0;l<=oscillate;l++)
{
if(i==1)
{
outportb(PORT,8);
printf("\n%d",i);
delay(speed);
}
if(i==2)
{
outportb(PORT,4);
printf("\n%d",i);
delay(speed);
}
if(i==3)
{
outportb(PORT,2);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
outportb(PORT,1);
printf("\n%d",i);
delay(speed);
}
if(i==4)
{
i=0;
}
i++;
}
while(!kbhit())
goto L2;
} //end of if(ch1=='c')
} //end of switch
} //end of while(1)
} //end of main()
BIBLIOGRAPHY
• www.nationalelectronics.com
• Fundamentals of Electronics by Rakshit &
Chattopadhyay