motor control

42
PROJECT REPORT ON Computer Controlled Stepper Motor Submitted by: DEBRAJ ADHIKARI FUTURE INSTITUTE OF ENGINEERING AND MANAGEMENT SONARPUR STATION ROAD, KOLKATA- 700150 UNDER THE GUIDANCE OF

Upload: debraj1061

Post on 13-Nov-2014

25 views

Category:

Documents


8 download

DESCRIPTION

Controlling a stepper motor with Computer

TRANSCRIPT

Page 1: Motor Control

PROJECT REPORT

ON

Computer Controlled Stepper Motor

Submitted by:

DEBRAJ ADHIKARI

FUTURE INSTITUTE OF ENGINEERING AND

MANAGEMENT SONARPUR STATION ROAD, KOLKATA-700150

UNDER THE GUIDANCE OF

PROF. DIPANKAR BISWAS

DEPARTMENT OF RADIOPHYSICS AND ELECTRONICSUNIVERSITY OF CALCUTTA

Page 2: Motor Control

92, A.P.C ROAD, KOLKATA-700009

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.

I would like to convey my sincere thanks to Sanjib Kabi and Tushar Dhabla Das whose unconditional help and valuable suggestions proved fruitful in achieving the ultimate goal.

Date: --------------------------Place: Debraj Adhikari.

Page 3: Motor Control

UNIVERSITY COLLEGE OF TECHNOLOGYINSTITUTE OF RADIOPHYSICS AND ELECTRONICS

Telephone : (+91)(33) 23509115Telegram : INRAPHEL SISIR MITRA BHAVAN Fax : (+91)(33) 23515828 92, A.P.C Road,E-mail : [email protected] Kolkata-700 009, INDIA.

This is to certify that Mr.Debraj Adhikari, student of Computer Science and Engineering(2004-2008) from Future Institute of Engineering and Management under West Bengal University of Technology(WBUT), has completed his project entitled ‘Computer Controlled Stepper Motor‘ under my guidance and in my laboratory.

I wish him success in life.

Page 4: Motor Control

------------------------------------ Prof. Dipankar Biswas

CONTENTS

Objective Introduction Apparatus required Circuit diagram Connector diagram Transistor component Motor description Theory C Source code Bibliography

Page 5: Motor Control

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.

Page 6: Motor Control

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.

Stepper motors operate much differently from normal DC motors, which rotate when voltage is applied to their terminals. Stepper motors, on the other hand, effectively have multiple "toothed" electromagnets (a.k.a. phases) arranged around a central gear-shaped piece of iron. The electromagnets are energized by an external control circuit, such as a microcontroller. To make the motor shaft turn, first one electromagnet is given power, which makes the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus aligned to the first electromagnet, they are slightly offset from the next electromagnet. So when the next electromagnet is turned on and the first is turned off, the gear rotates slightly to align with the next one, and from there the process is repeated. Each of those slight rotations is called a "step." In that way, the motor can be turned a precise angle.

The stepper motor for this project is a unipolar stepper motor that has two windings per phase, one for each direction of current. Since in this arrangement a magnetic pole can be reversed without switching the direction of current, the commutation circuit can be made very simple

Page 7: Motor Control

(eg. a single transistor) for each winding. Typically, given a phase, one end of each winding is made common: giving three leads per phase and six leads for a typical two phase motor. Often, these two phase commons are internally joined, so the motor has only five leads.

The C program is written to power each electromagnet in turn. Thus each electromagnets are powered one after another to make a complete rotation. The ‘female D-25’ connector of the printer port is programmed for this purpose. For the motor to function properly a driver circuit has been built.

Page 8: Motor Control

APPARATUS REQUIRED

SL NO

NAME RATING

1. 4 Phase Stepper Motor TYPE KP39HM2-S07A

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

Page 9: Motor Control

CIRCUIT DIAGRAM

Connector Port D0

o/p 1

Connector Port D1

o/p 2

Connector Port D2

o/p 3

Connector Port D3

o/p 4

Page 10: Motor Control

Yellow, Brown, Orange & Black are the motor wires which are connected in sequence to make the motor rotate. The collector pins of the transistors are connected to the motor wires.

The base of the transistors are connected to the connector ports of the D-25 connector.

The emitter pins are grounded.

CONNECTOR DIAGRAM

IBM-PC's Parallel Printer Port had a total of 12 digital outputs and 5 digital inputs accessed via 3 consecutive 8-bit ports in the processor's I/O space.

8 output pins accessed via the DATA Port 5 input pins (one inverted) accessed via the STATUS

Port 4 output pins (three inverted) accessed via the

CONTROL Port The remaining 8 pins are grounded

Page 11: Motor Control

25-way Female D-Type Connector

TRANSISTOR COMPONENT

Page 12: Motor Control

BC547 Transistor Diagram

FEATURES · Low current (max. 100 mA) · Low voltage (max. 65 V).

LIMITING VALUES

Symbol

Parameter Conditions Min. Max. Unit

VCBO collector-base voltage open emitter - 50 V VCEO collector-emitter voltage open base - 45 V

Page 13: Motor Control

VEBO emitter-base voltage open collector - 6 V IC collector current (DC) ICM peak collector current IBM peak base current Ptot total power dissipation Tamb 25 C; Tj junction temperature

MOTOR DESCRIPTION

Page 14: Motor Control

TYPE KP39HM2-S07A

1.8 DEG/STEP 0.16A/PHASE

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.

For Clockwise rotation the sequence is as follows:Yellow, Brown, Orange, Black. For Anti-Clockwise rotation the sequence is as follows:Black, Orange, Brown, Yellow.

The Red wire in both the cases is kept at a positive voltage.

Page 15: Motor Control

THEORY

A transistor's collector current is proportionally limited by its base current, it can be used as a sort of current-controlled

Page 16: Motor Control

switch. A relatively small flow of electrons sent through the base of the transistor has the ability to exert control over a much larger flow of electrons through the collector.

Since the motor used for this project is a 4-Phase motor, therefore only 4 of the 8 Data ports of the Female D-Type Connector(D0-D8) is used.

The 4 ports are programmed to output data in the following manner :

D0

D1

D2

D3

Port 1

1 0 0 0

Port 2

0 1 0 0

Port 3

0 0 1 0

Port 4

0 0 0 1

One port gets activated at a time followed by another. This process continues and the motor rotates. The bases of the transistors are connected to the ports (refer to Connection Diagram) which are activated to control a larger flow of current through the collector which are connected to the motor windings (refer to Connection Diagram). This in turn rotates the motor.

The rectifying diodes protect the transistors from excess current. Integrating all the components the driver circuit has been created. The program controls the working of the motor. The speed of the motor can be controlled, it can be made to rotate clockwise or anticlockwise and made to oscillate.

Page 17: Motor Control

C SOURCE CODE

Page 18: Motor Control

#include"stdio.h"#include"conio.h"#include"dos.h"

#define PORT 0x378#define CONTROL PORT+2

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();

printf("\n1. --> START THE MOTOR");printf("\n2. --> QUIT");printf("\n3. --> ACCELERATR");printf("\n4. --> DECELERATE");printf("\n5. --> OSCILLATE \n\t");

scanf("%d",&choice);

switch(choice){case 1:

printf("\nEnter Speed of Rotation(in millisec):\t");scanf("%d",&speed);

printf("\nRotate Clockwise or Anticlockwise (C/A):\t");

scanf("%s",&ch1);

Page 19: Motor Control

printf("\n\nPress any key to stop\n");getch();

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)

Page 20: Motor Control

{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);

Page 21: Motor Control

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:

Page 22: Motor Control

exit(0);

case 3:

printf("\nEnter Start Speed of Rotation(in millisec)(end_speed<start_speed):\t");

scanf("%d",&start_speed);

printf("\nEnter End Speed of Rotation(in millisec) (end_speed<start_speed):\t");

scanf("%d",&end_speed);

printf("\nRotate Clockwise or Anticlockwise (C/A):\t");

scanf("%s",&ch1);

printf("\nEnter Acceleration steps: \t ");scanf("%d",&acc_step);

printf("\nPress any key to stop\n");getch();

if(ch1=='c') {

i=1;

while(!kbhit()) {

if(i==1) { outportb(PORT,1); delay(start_speed);

}

Page 23: Motor Control

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; }

Page 24: Motor Control

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);

}

Page 25: Motor Control

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++;

Page 26: Motor Control

} //end of while(!kbhit())

} //end of if(ch1)

case 4:

printf("\nEnter Start Speed of Rotation(in millisec)(end_speed>start_speed):\t");

scanf("%d",&start_speed);

printf("\nEnter End Speed of Rotation(in millisec) (end_speed>start_speed):\t");

scanf("%d",&end_speed);

printf("\nRotate Clockwise or Anticlockwise (C/A):\t");

scanf("%s",&ch1);

printf("\nEnter Acceleration steps: \t ");scanf("%d",&acc_step);

if(ch1=='c') {

i=1;

while(!kbhit()) {

if(i==1) { outportb(PORT,1); delay(start_speed);

Page 27: Motor Control

}

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; }

Page 28: Motor Control

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);

}

Page 29: Motor Control

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++;

Page 30: Motor Control

} //end of while(!kbhit())

} //end of if(ch1)

case 5:printf("\nEnter Speed of Rotation(in millisec):\t");scanf("%d",&speed);

printf("\nEnter number of turns to oscillate: \t");scanf("%d",&oscillate);

printf("\nFirst Clockwise or Anticlockwise(C/A):\t");scanf("%s",&ch1);

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);

}

Page 31: Motor Control

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);

}

Page 32: Motor Control

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')

Page 33: Motor Control

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);

Page 34: Motor Control

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);

}

Page 35: Motor Control

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()

Page 36: Motor Control

BIBLIOGRAPHY

www.nationalelectronics.com Fundamentals of Electronics by Rakshit &

Chattopadhyay