SlideShare a Scribd company logo
2
Most read
6
Most read
8
Most read
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

SEMESTER PROJECT
“COMPUTER NUMERICAL CONTROLLED MACHINE”

SUBMITTED BY :
MUHAMMAD ZAIGHUM FAROOQ

SUBMITTED TO: ENGG. MEMOON SAJID
COURSE: EE341L - CONTROL SYSTEMS LAB

Page 1
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

ABSTRACT
A computer numerical control (CNC) machine is a collection of automated tools controlled by abstractly
programmed commands on a storage medium, as opposed to manual control via hand wheels or levers.
The machine is operated by stepper motors that move the controls to follow points/co-ordinates fed
into the system by a computer. In our work, we have used µ-controller AT89C51 as the storage medium,
serially receiving co-ordinates from a pc, processing that data and controlling servo motor accordingly to
reach the destination point.

Page 2
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

Table of Contents
ABSTRACT...................................................................................................................................................... 2
INTRODUCTION ............................................................................................................................................. 4
LIST OF HARDWARE USED ......................................................................................................................... 5
LIST OF SOFTWARES .................................................................................................................................. 5
STEPPER MOTOR SPECIFICATION ............................................................................................................. 5
MATLAB CODE FOR SENDING SERIAL DATA ................................................................................................. 5
CIRCUIT DIAGRAMS....................................................................................................................................... 6
H-BRIDGE CIRCUIT......................................................................................................................................... 7
FLOW CHART OF OPERATION ....................................................................................................................... 9
CODING TO IMPLEMENT THE ALGORITHM ................................................................................................ 10
UNIT OF INPUT ........................................................................................................................................ 14
MOTOR STEP SIZE ................................................................................................................................... 14
EFFICIENCY .............................................................................................................................................. 14
IMPROVEMENTS ......................................................................................................................................... 14
INPUT MATRIX

&

CUTTING DIRECTIONS ..................................................................................... 15

ACKNOWLEDGEMENTS ............................................................................................................................... 16
BIBLIOGRAPHY ............................................................................................................................................ 17

Page 3
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

INTRODUCTION
Computer numerical machines are very commonly used the days . They have
high tendency to replace the manual cutting machines as they are extremely user friendly . They give
user enough free time to be able to control more than 5 machines very easily . This ease combined with
a much greater degree of precision and accuracy sets their scope .
Our main aim of the project was to cut any shape by controlling the machine numerically but as it
was our semester project so we succeeded in cutting all the shapes that have straight edges . This
project does not cut any round shape. A motor with rotating round cutter was turned on during the
cutting process then commands are given for specific coordinates by matlab . Machine reaches that
coordinates by cutting the object in a line with any slope depending on the coordinates at present .
After that again coordinates are given to the controller through matlab and machine repeats its process
. It carries on this way and cuts a closed shape with great degree of accuracy and precision .

Page 4
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

LIST OF HARDWARE USED
Following table shows the hardware used :
CONTENT
1. µ-controller trainer with serial cable
2. H-bridge circuit1
3. 12V&5V power supply

SPECIFICATION

QUANTITY
1
2
1,1

LIST OF SOFTWARES
Following table shows the softwares used :
SOFTWARE
1. MATLAB
2. MCU 8051 IDE

PURPOSE
For entering co-ordinates and serially
communicate them
For programming the µ-controller

STEPPER MOTOR SPECIFICATION
Sequence of bits to rotate stepper motor through each consecutive step:
D1 D2 D3 D4
1
0
0
1
1
1
0
0
0
1
1
0
0
0
1
1
Moving from top to bottom will move the motor in clockwise steps. While taking the opposite sequence
will move the motor in anti-clockwise direction.

MATLAB CODE FOR SENDING SERIAL DATA
ss=serial('COM3');
ss.baudrate=9600;
fopen(ss);
ss.Terminator = 'CR';
tx =1;
fprintf(ss,'%s',tx1);
pause(1);

Page 5
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

CIRCUIT DIAGRAMS

Page 6
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

H-BRIDGE CIRCUIT
To operate the stepper motor, we need a motor driving circuit that gives enough current to move the
stepper motor in loaded conditions as present on the real CNC machine.

We used the above H-bridge ic named L298 .
You can also use any other H bridge circuit, commonly of transistors “Tip 122”.

Page 7
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

STEPPER MOTOR CONTROL CIRCUITRY
(REPEATED TWICE)
The circuit shown below in the diadram is the main controlling circuitry for controlling the stepper
motors.

Page 8
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

FLOW CHART OF OPERATION
Data Input

Data sending by
serial communication

MATLAB

Data received to µcontroller serial
communication

Interpreting data

Giving instruction
to motors

Control Unit

R

U

D

L

Page 9

L

U

R

D
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013
Computer interfaced with µ-controller using MATLAB.
1. Registers R₆ and R₇ to store the co-ordinate lengths entered through pc. Magnitude of R₆ and R₇
decides the no. of steps the stepper motor will move.
2. Register R₅ to hold the bit to give the direction in which the stepper motors will rotate. There
are four cases which decide the motion of stepper motor as shown in the direction.
3. For 1 unit entered stepper motor will rotate 0.5cm.
4. Each step of stepper motor covers 20µm of length. A loop of 125 cycles, whereby each cycle
consists of 2 steps is used to cover 0.5cm of length.

CODING TO IMPLEMENT THE ALGORITHM
org 00H
mov tmod,#20H
mov th1,#-3
mov scon,#50H
setb tr1
main:nop
her3: jnb ri,her3
lcall delay
mov a,sbuf
lcall delay
dec a
mov r7,a
mov p0,a
clr ri
lcall delay
here4: jnb ri,here4
lcall delay
mov a,sbuf
lcall delay
dec a
mov r6,a
mov p0,a
clr ri
lcall delay
here5: jnb ri,here5
lcall delay
mov a,sbuf
lcall delay
mov r5,a
mov p0,a
clr ri

Page
10
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013
lcall delay
tri:
mov a,r5
cjne a,#0,over
sjmp $
mov a,r5
over:cjne a,#1,over1
mov r4,#125
back6:mov a,r7
mov r1,a
mov a,r6
mov r0,a
back5:djnz r4,here2
sjmp main
mov a,r5
over1:cjne a,#2,over2
mov r4,#125
back67:mov a,r7
mov r1,a
mov a,r6
mov r0,a
back57:djnz r4,here27
sjmp main
mov a,r5
over2:cjne a,#3,over3
mov r4,#125
back68:mov a,r7
mov r1,a
mov a,r6
mov r0,a
back58:djnz r4,here28
sjmp main
mov a,r5
over3:cjne a,#4,over4
mov r4,#125
back69:mov a,r7
mov r1,a
mov a,r6
mov r0,a
back59:djnz r4,here29
over4:sjmp main

Page
11
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

here2:mov a,r1
jz too
loo:acall down
acall delay
djnz r1,loo
too:mov a,r0
jz back6
acall left
acall delay
djnz r0,too
sjmp back6
here27:mov a,r1
jz tooo
looo:acall up
acall delay
djnz r1,looo
tooo:mov a,r0
jz back67
acall right
acall delay
djnz r0,tooo
sjmp back67
here28:mov a,r1
jz toooo
loooo:acall up
acall delay
djnz r1,loooo
toooo:mov a,r0
jz back68
acall left
acall delay
djnz r0,toooo
sjmp back68
here29:mov a,r1
jz to
lo:acall down
acall delay
djnz r1,lo
to:mov a,r0
jz back69
acall right
acall delaysjmp back69

Page
12
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

down:
mov a,30h
jz soo
mov p1,#99H
lcall delay
mov p1,#0ccH
lcall delay
mov 30h,#0
sjmp haha
soo:mov p1,#66H
lcall delay
mov p1,#33H
lcall delay
mov 30h,#1
haha:
ret
up:
mov a,31h
jz soo1
mov p1,#33H
lcall delay
mov p1,#66H
lcall delay
mov 31h,#0
sjmp haha
soo1:mov p1,#0ccH
lcall delay
mov p1,#99H
lcall delay
mov 31h,#1
haha1:
ret
left:
mov a,32h
jz soo2
mov p2,#99H
lcall delay
mov p2,#0ccH
lcall delay
mov 32h,#0
sjmp haha
soo2:mov p2,#66H
lcall delay
mov p2,#33H

Page
13
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013
lcall delay
mov 32h,#1
haha2:
ret
right:
mov a,33h
jz soo3
mov p2,#33H
lcall delay
mov p2,#66H
lcall delay
mov 33h,#0
sjmp haha
soo3:mov p2,#0ccH
lcall delay
mov p2,#99H
lcall delay
mov 33h,#1
haha3:
ret
delay: mov r2,#40
h1:mov r3,#255
h2:djnz r3,H2
djnz r2,h1
ret
end

UNIT OF INPUT
Unit of input is 0.5 cm in the above program and can be changed by changing the number 125 in the
program. For example, if you change the number from 125 to 63 then unit of input will be 0.25cm.

MOTOR STEP SIZE
Motor step size is 500 steps/cm.

EFFICIENCY
In the above program it depends on the inputs.

IMPROVEMENTS
1: Efficiency of the above program can be improved by making more precise sub-control units.
2: Efficiency of the above program can be increased by two folds if we change the motor rotating units.

Page
14
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013
In the above program every time the motor rotate is called motor takes two steps , by changing it to
take one step efficiency will double as well as program length will decrease . Its very easy. Just take a
rom location save the 66H in it retrieve it in motor rotate routine , rotate left or right according to
routine and then save it back in the same location .
3: Currently we input from matlab the directions and lengths of coordinates, we should improve it to
entering the +,- coordinates and let the computer calculate lengths and direction .
4: Data should be received as ascii characters.
5: It should also be improved to cut the curves of different types .
6: It should also be programed to three directional cutting .

INPUT MATRIX
1

7
7

3

5

3

1

5

3

3

5

3

4

7

1

4

7

1

CUTTING DIRECTIONS

4

1

&

3

Third number in input matrix represents the direction. First two numbers are lengths.
Many others possible, they also depend on connections of motors.
Moreover above lines arrows are not according to scale.

Page
15
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

ACKNOWLEDGEMENTS
For this project, we owe our gratitude to Mr. Memoon Sajid who assigned us this project and was a
source of constant help throughout both morally and practically. We would also like to thank our
teacher Mr. Kashif Riaz who with his marvelous teaching skills made assembly language almost innate
for us. We would also like to thank Mr. Nayyar Abbas who diligently taught us the use and programming
of µ-controller. Last but not the least we would like to thank our honorable Dean (FEE) Dr. Nisar who
had been very supportive in the requisition of hardware without which this project would never have
seen the light of day.

Page
16
EE332 CONTROL SYSTEMS LAB – CNC MACHINE
SPRING 2013

BIBLIOGRAPHY
Pocketmagic.net (2009) A simple H-Bridge design « PocketMagic. [online] Available at:
http://www.pocketmagic.net/2009/03/a-simple-h-bridge-design/#.UYwLYUrMLuZ [Accessed: 9 May
2013].

Page
17

More Related Content

PPT
Cnc technology
PPT
Cnc Milling (Heidenhain ISO)
DOC
Introduction to cnc machines (1)
PPTX
introduction to cnc machines
PPT
PPTX
Cnc pgrming seminar-
Cnc technology
Cnc Milling (Heidenhain ISO)
Introduction to cnc machines (1)
introduction to cnc machines
Cnc pgrming seminar-

What's hot (20)

PDF
J4123 CNC TURNING NOTE
PPT
introduction to cnc technology
PPTX
Nc Technology
PDF
Funuc progaming
PPTX
Cnc programming
PDF
Chapter 4 cnc part programming
PPTX
Bhel haridwar summer training ppt
PPTX
Universal CNC Milling Machine
DOC
Nc Machine
PPT
Cnc technology yani punye
PPTX
Computer Numeric control(C.N.C) Machine
PPT
Nc programming
PDF
Cnc notes (1)
PPTX
PPT
Computer Numerical Control (CNC) & Manufacturing Automation
PDF
Cnc programming basics.doc
PPT
Cnc training (sahil gupta 9068557926)
PPTX
cnc machining
PPTX
nc and cnc dp
PPTX
BHEL PPT for AEI branch
J4123 CNC TURNING NOTE
introduction to cnc technology
Nc Technology
Funuc progaming
Cnc programming
Chapter 4 cnc part programming
Bhel haridwar summer training ppt
Universal CNC Milling Machine
Nc Machine
Cnc technology yani punye
Computer Numeric control(C.N.C) Machine
Nc programming
Cnc notes (1)
Computer Numerical Control (CNC) & Manufacturing Automation
Cnc programming basics.doc
Cnc training (sahil gupta 9068557926)
cnc machining
nc and cnc dp
BHEL PPT for AEI branch
Ad

Viewers also liked (20)

PPTX
CNC PROGRAMMING FOR BEGAINER Part 1
PPT
Cnc part programming 4 unit
PPTX
NC, CNC & DNC Machine
PPT
CNC Machines
PDF
Lecture 17 position systems of nc [compatibility mode]
PPTX
computer numerical control
PPTX
CNC machining
PDF
B. tech. -_mechanical_engg_-_r13_-_syllabus
PDF
A literature review on optimization of cutting parameters for surface roughne...
PDF
EXPERIMENTAL STUDY OF TURNING OPERATION AND OPTIMIZATION OF MRR AND SURFACE R...
PPT
Taguchi method-process imp
PDF
Optimization of input parameters of cnc turning operation for the given comp
PPTX
PDF
Optimization of edm process parameters using taguchi method a review
DOC
Seminar Report On Taguchi Methods2
PDF
NC part programing & Robotics
PDF
MULTIOBJECTIVE OPTIMIZATION OF MACHINING PARAMETERSFOR C-65 MATERIAL USING TA...
PDF
Kirabo cyber cafe business plan
PPTX
CNC Programming
CNC PROGRAMMING FOR BEGAINER Part 1
Cnc part programming 4 unit
NC, CNC & DNC Machine
CNC Machines
Lecture 17 position systems of nc [compatibility mode]
computer numerical control
CNC machining
B. tech. -_mechanical_engg_-_r13_-_syllabus
A literature review on optimization of cutting parameters for surface roughne...
EXPERIMENTAL STUDY OF TURNING OPERATION AND OPTIMIZATION OF MRR AND SURFACE R...
Taguchi method-process imp
Optimization of input parameters of cnc turning operation for the given comp
Optimization of edm process parameters using taguchi method a review
Seminar Report On Taguchi Methods2
NC part programing & Robotics
MULTIOBJECTIVE OPTIMIZATION OF MACHINING PARAMETERSFOR C-65 MATERIAL USING TA...
Kirabo cyber cafe business plan
CNC Programming
Ad

Similar to Computer numerical controlled machine project (20)

PPTX
Pmc basic final
PDF
Temp based fan speed control
PDF
Robotic Catching Arm using Microcontroller
PDF
IRJET- Automatic Mini CNC Machine for PCB Drawing using Arduino
PDF
Lecture 2
PDF
FOUR QUADRANT SPEED CONTROL OF DC MOTOR USING AT89S52 MICROCONTROLLER
PPT
Presentation200 (1).ppt
PDF
D0255033039
PDF
Designing and Controlling of Motor by Interfacing RS232 with Microcontroller
PPTX
Electrician Training for USAF
DOCX
Report no.6..(bipolar motor n DC motor)
DOCX
REPORT
PDF
Computer Numerical Control_2018.pdf
PPT
Tachometer using AT89S52 microcontroller with motor control
PPT
9_CNC (1).ppt
PDF
International Journal of Engineering Research and Development (IJERD)
PDF
Amp bluac5 specsheet
PDF
International Journal of Computational Engineering Research(IJCER)
PDF
Welcome to International Journal of Engineering Research and Development (IJERD)
PPT
2D Plotter Presentation
Pmc basic final
Temp based fan speed control
Robotic Catching Arm using Microcontroller
IRJET- Automatic Mini CNC Machine for PCB Drawing using Arduino
Lecture 2
FOUR QUADRANT SPEED CONTROL OF DC MOTOR USING AT89S52 MICROCONTROLLER
Presentation200 (1).ppt
D0255033039
Designing and Controlling of Motor by Interfacing RS232 with Microcontroller
Electrician Training for USAF
Report no.6..(bipolar motor n DC motor)
REPORT
Computer Numerical Control_2018.pdf
Tachometer using AT89S52 microcontroller with motor control
9_CNC (1).ppt
International Journal of Engineering Research and Development (IJERD)
Amp bluac5 specsheet
International Journal of Computational Engineering Research(IJCER)
Welcome to International Journal of Engineering Research and Development (IJERD)
2D Plotter Presentation

Recently uploaded (20)

PPTX
Principles of Marketing, Industrial, Consumers,
PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PPTX
Lecture (1)-Introduction.pptx business communication
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
Nidhal Samdaie CV - International Business Consultant
PDF
Chapter 5_Foreign Exchange Market in .pdf
PDF
Laughter Yoga Basic Learning Workshop Manual
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PPTX
5 Stages of group development guide.pptx
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
How to Get Business Funding for Small Business Fast
PDF
Business model innovation report 2022.pdf
DOCX
Business Management - unit 1 and 2
PDF
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
Principles of Marketing, Industrial, Consumers,
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
Ôn tập tiếng anh trong kinh doanh nâng cao
Lecture (1)-Introduction.pptx business communication
New Microsoft PowerPoint Presentation - Copy.pptx
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Nidhal Samdaie CV - International Business Consultant
Chapter 5_Foreign Exchange Market in .pdf
Laughter Yoga Basic Learning Workshop Manual
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
5 Stages of group development guide.pptx
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
COST SHEET- Tender and Quotation unit 2.pdf
How to Get Business Funding for Small Business Fast
Business model innovation report 2022.pdf
Business Management - unit 1 and 2
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
ICG2025_ICG 6th steering committee 30-8-24.pptx

Computer numerical controlled machine project

  • 1. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 SEMESTER PROJECT “COMPUTER NUMERICAL CONTROLLED MACHINE” SUBMITTED BY : MUHAMMAD ZAIGHUM FAROOQ SUBMITTED TO: ENGG. MEMOON SAJID COURSE: EE341L - CONTROL SYSTEMS LAB Page 1
  • 2. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 ABSTRACT A computer numerical control (CNC) machine is a collection of automated tools controlled by abstractly programmed commands on a storage medium, as opposed to manual control via hand wheels or levers. The machine is operated by stepper motors that move the controls to follow points/co-ordinates fed into the system by a computer. In our work, we have used µ-controller AT89C51 as the storage medium, serially receiving co-ordinates from a pc, processing that data and controlling servo motor accordingly to reach the destination point. Page 2
  • 3. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 Table of Contents ABSTRACT...................................................................................................................................................... 2 INTRODUCTION ............................................................................................................................................. 4 LIST OF HARDWARE USED ......................................................................................................................... 5 LIST OF SOFTWARES .................................................................................................................................. 5 STEPPER MOTOR SPECIFICATION ............................................................................................................. 5 MATLAB CODE FOR SENDING SERIAL DATA ................................................................................................. 5 CIRCUIT DIAGRAMS....................................................................................................................................... 6 H-BRIDGE CIRCUIT......................................................................................................................................... 7 FLOW CHART OF OPERATION ....................................................................................................................... 9 CODING TO IMPLEMENT THE ALGORITHM ................................................................................................ 10 UNIT OF INPUT ........................................................................................................................................ 14 MOTOR STEP SIZE ................................................................................................................................... 14 EFFICIENCY .............................................................................................................................................. 14 IMPROVEMENTS ......................................................................................................................................... 14 INPUT MATRIX & CUTTING DIRECTIONS ..................................................................................... 15 ACKNOWLEDGEMENTS ............................................................................................................................... 16 BIBLIOGRAPHY ............................................................................................................................................ 17 Page 3
  • 4. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 INTRODUCTION Computer numerical machines are very commonly used the days . They have high tendency to replace the manual cutting machines as they are extremely user friendly . They give user enough free time to be able to control more than 5 machines very easily . This ease combined with a much greater degree of precision and accuracy sets their scope . Our main aim of the project was to cut any shape by controlling the machine numerically but as it was our semester project so we succeeded in cutting all the shapes that have straight edges . This project does not cut any round shape. A motor with rotating round cutter was turned on during the cutting process then commands are given for specific coordinates by matlab . Machine reaches that coordinates by cutting the object in a line with any slope depending on the coordinates at present . After that again coordinates are given to the controller through matlab and machine repeats its process . It carries on this way and cuts a closed shape with great degree of accuracy and precision . Page 4
  • 5. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 LIST OF HARDWARE USED Following table shows the hardware used : CONTENT 1. µ-controller trainer with serial cable 2. H-bridge circuit1 3. 12V&5V power supply SPECIFICATION QUANTITY 1 2 1,1 LIST OF SOFTWARES Following table shows the softwares used : SOFTWARE 1. MATLAB 2. MCU 8051 IDE PURPOSE For entering co-ordinates and serially communicate them For programming the µ-controller STEPPER MOTOR SPECIFICATION Sequence of bits to rotate stepper motor through each consecutive step: D1 D2 D3 D4 1 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1 Moving from top to bottom will move the motor in clockwise steps. While taking the opposite sequence will move the motor in anti-clockwise direction. MATLAB CODE FOR SENDING SERIAL DATA ss=serial('COM3'); ss.baudrate=9600; fopen(ss); ss.Terminator = 'CR'; tx =1; fprintf(ss,'%s',tx1); pause(1); Page 5
  • 6. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 CIRCUIT DIAGRAMS Page 6
  • 7. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 H-BRIDGE CIRCUIT To operate the stepper motor, we need a motor driving circuit that gives enough current to move the stepper motor in loaded conditions as present on the real CNC machine. We used the above H-bridge ic named L298 . You can also use any other H bridge circuit, commonly of transistors “Tip 122”. Page 7
  • 8. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 STEPPER MOTOR CONTROL CIRCUITRY (REPEATED TWICE) The circuit shown below in the diadram is the main controlling circuitry for controlling the stepper motors. Page 8
  • 9. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 FLOW CHART OF OPERATION Data Input Data sending by serial communication MATLAB Data received to µcontroller serial communication Interpreting data Giving instruction to motors Control Unit R U D L Page 9 L U R D
  • 10. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 Computer interfaced with µ-controller using MATLAB. 1. Registers R₆ and R₇ to store the co-ordinate lengths entered through pc. Magnitude of R₆ and R₇ decides the no. of steps the stepper motor will move. 2. Register R₅ to hold the bit to give the direction in which the stepper motors will rotate. There are four cases which decide the motion of stepper motor as shown in the direction. 3. For 1 unit entered stepper motor will rotate 0.5cm. 4. Each step of stepper motor covers 20µm of length. A loop of 125 cycles, whereby each cycle consists of 2 steps is used to cover 0.5cm of length. CODING TO IMPLEMENT THE ALGORITHM org 00H mov tmod,#20H mov th1,#-3 mov scon,#50H setb tr1 main:nop her3: jnb ri,her3 lcall delay mov a,sbuf lcall delay dec a mov r7,a mov p0,a clr ri lcall delay here4: jnb ri,here4 lcall delay mov a,sbuf lcall delay dec a mov r6,a mov p0,a clr ri lcall delay here5: jnb ri,here5 lcall delay mov a,sbuf lcall delay mov r5,a mov p0,a clr ri Page 10
  • 11. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 lcall delay tri: mov a,r5 cjne a,#0,over sjmp $ mov a,r5 over:cjne a,#1,over1 mov r4,#125 back6:mov a,r7 mov r1,a mov a,r6 mov r0,a back5:djnz r4,here2 sjmp main mov a,r5 over1:cjne a,#2,over2 mov r4,#125 back67:mov a,r7 mov r1,a mov a,r6 mov r0,a back57:djnz r4,here27 sjmp main mov a,r5 over2:cjne a,#3,over3 mov r4,#125 back68:mov a,r7 mov r1,a mov a,r6 mov r0,a back58:djnz r4,here28 sjmp main mov a,r5 over3:cjne a,#4,over4 mov r4,#125 back69:mov a,r7 mov r1,a mov a,r6 mov r0,a back59:djnz r4,here29 over4:sjmp main Page 11
  • 12. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 here2:mov a,r1 jz too loo:acall down acall delay djnz r1,loo too:mov a,r0 jz back6 acall left acall delay djnz r0,too sjmp back6 here27:mov a,r1 jz tooo looo:acall up acall delay djnz r1,looo tooo:mov a,r0 jz back67 acall right acall delay djnz r0,tooo sjmp back67 here28:mov a,r1 jz toooo loooo:acall up acall delay djnz r1,loooo toooo:mov a,r0 jz back68 acall left acall delay djnz r0,toooo sjmp back68 here29:mov a,r1 jz to lo:acall down acall delay djnz r1,lo to:mov a,r0 jz back69 acall right acall delaysjmp back69 Page 12
  • 13. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 down: mov a,30h jz soo mov p1,#99H lcall delay mov p1,#0ccH lcall delay mov 30h,#0 sjmp haha soo:mov p1,#66H lcall delay mov p1,#33H lcall delay mov 30h,#1 haha: ret up: mov a,31h jz soo1 mov p1,#33H lcall delay mov p1,#66H lcall delay mov 31h,#0 sjmp haha soo1:mov p1,#0ccH lcall delay mov p1,#99H lcall delay mov 31h,#1 haha1: ret left: mov a,32h jz soo2 mov p2,#99H lcall delay mov p2,#0ccH lcall delay mov 32h,#0 sjmp haha soo2:mov p2,#66H lcall delay mov p2,#33H Page 13
  • 14. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 lcall delay mov 32h,#1 haha2: ret right: mov a,33h jz soo3 mov p2,#33H lcall delay mov p2,#66H lcall delay mov 33h,#0 sjmp haha soo3:mov p2,#0ccH lcall delay mov p2,#99H lcall delay mov 33h,#1 haha3: ret delay: mov r2,#40 h1:mov r3,#255 h2:djnz r3,H2 djnz r2,h1 ret end UNIT OF INPUT Unit of input is 0.5 cm in the above program and can be changed by changing the number 125 in the program. For example, if you change the number from 125 to 63 then unit of input will be 0.25cm. MOTOR STEP SIZE Motor step size is 500 steps/cm. EFFICIENCY In the above program it depends on the inputs. IMPROVEMENTS 1: Efficiency of the above program can be improved by making more precise sub-control units. 2: Efficiency of the above program can be increased by two folds if we change the motor rotating units. Page 14
  • 15. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 In the above program every time the motor rotate is called motor takes two steps , by changing it to take one step efficiency will double as well as program length will decrease . Its very easy. Just take a rom location save the 66H in it retrieve it in motor rotate routine , rotate left or right according to routine and then save it back in the same location . 3: Currently we input from matlab the directions and lengths of coordinates, we should improve it to entering the +,- coordinates and let the computer calculate lengths and direction . 4: Data should be received as ascii characters. 5: It should also be improved to cut the curves of different types . 6: It should also be programed to three directional cutting . INPUT MATRIX 1 7 7 3 5 3 1 5 3 3 5 3 4 7 1 4 7 1 CUTTING DIRECTIONS 4 1 & 3 Third number in input matrix represents the direction. First two numbers are lengths. Many others possible, they also depend on connections of motors. Moreover above lines arrows are not according to scale. Page 15
  • 16. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 ACKNOWLEDGEMENTS For this project, we owe our gratitude to Mr. Memoon Sajid who assigned us this project and was a source of constant help throughout both morally and practically. We would also like to thank our teacher Mr. Kashif Riaz who with his marvelous teaching skills made assembly language almost innate for us. We would also like to thank Mr. Nayyar Abbas who diligently taught us the use and programming of µ-controller. Last but not the least we would like to thank our honorable Dean (FEE) Dr. Nisar who had been very supportive in the requisition of hardware without which this project would never have seen the light of day. Page 16
  • 17. EE332 CONTROL SYSTEMS LAB – CNC MACHINE SPRING 2013 BIBLIOGRAPHY Pocketmagic.net (2009) A simple H-Bridge design « PocketMagic. [online] Available at: http://www.pocketmagic.net/2009/03/a-simple-h-bridge-design/#.UYwLYUrMLuZ [Accessed: 9 May 2013]. Page 17