5. Introduction
CNC Machine
Computer numerical control (CNC) machines are automated
milling machines that make industrial components without
human assistance. This is possible because CNC machines are
fed a series of instructions that are delivered to an internal
computer controller. These instructions are in the form of
codes that belong to the numerical control programming
language.
The code used to program CNC machines is generically called
G-code. However, G-code instructions are only part of the
programming language. Specifically, G-codes give CNC
machines the coordinates .
6. Introduction
Project Idea
• Automation of 3 Motors to control the
coordinates (X,Y,Z)of a pen with flexible
head can be used as Plotter.
7. History
The first commercial NC
machines were built in
the 1950's, and ran from
punched tape.
CNC, and later CNC,
allowed for tremendous
increases in productivity
for machine tools
because the machines
could be run
automatically without
The first commercial NC requiring constant
www.cnccookbook.com attention from their
operator.
9. System Features
• Rapid speed positioning using G00
• Plot line using G01
• Plot Circles using G02,G03 clockwise or
anti-clock wise.
• Manual Mode control the position of the
Plotter using Keyboard
• Programming Mode write full program
includes moving plotter, Arithmetic
operation and decisions instructions
13. System Architecture cont
Software Subsystem
There are 6 Main Software Modules
• MotorLib.h : Configure, Monitor and Move Motors.
• TimersLib.h : Configure periodic task.
• Interperter.h : Parse G-line program separate tokens and
execute instruction
– [simple Arithmetic instructions ADD MUL].
– [Motor Instructions Operation G00,G01,G02,G03].
– [Decision instruction JEQ,JNE].
14. System Architecture cont.
Software Subsystem cont.
• UART.h
– Serial communication port driver to send the G-code
program and control instruction to the machine
• BresenhamLineDrawing.h
• MidPointCircleDrawing.h
15. System Architecture
Mechanical Subsystem
3 Motors each one attached to AXIS (X,Y,Z)
Stepper Motor with the following Description
Step angle 1.8°
Holding Torque: 3.9 Kg.cm (40 N.cm)
Current 2 A
leads: 6 wires (4 per coils 2 COM)
16. System Architecture cont
CNC Machine Mechanical Design:
Figure-1 Different views of Our CNC Machine
17. System Architecture cont
Electronic Subsystem
It consists of 8 bit At mega 328P microcontroller and stepper
motor control drivers BAL 35 for controlling all the three
stepper motors. Microcontroller generates necessary STEP and
DIRECTION signals for each stepper motor controller to
achieve desired speed and rotation. A RS 232 is used for
communicating data between PC and microcontroller.
18. Control Modes
• We have three types of control mode:
-Calibration Mode (CL).
-Load Mode (LD).
-Execution Mode (EXE).
19. Control Mode instruction
Command Description
CL Manual Mode
LD Program Mode
START Executed the program stored on RAM
EXE Read G_Line from serial and executed it immediately and
acknowledge the next instruction
RESET Reset the machine to the initial X_co,Y_co_Z_co coordinates
SETBX Set border of our board on X-axis
SETBY Set border of our board on Y-axis
SETBZ Set border of our board on Z-axis
21. Machine Language Program instruction
Command Description
G00 Rapid speed X,Y,Z Vector.
G01 .linear interpolation between 2 points Bresenham line drawing
G02 Clockwise circular interpolation.
G03 Anti Clockwise circular interpolation.
ADD ADD operand [2] and operand [3] then put result set on
Operand [1].
MUL MUL operand [2] and operand [3] then put result on Operand
[1].
JEQ Jump if flag is set.
JNE Jump if flag is reset.
CMP Compare operand [1] and operand [2] and set Equal flag.
EOP End of program.
26. Bresenham Line Drawing
G01 Implementation
• Algorithm which determines which points
in an n-dimensional raster should be
plotted in order to form a close
approximation to a straight line between
two given points. It is commonly used to
draw lines on a computer screen, as it
uses only integer addition, subtraction and
bit shifting, all of which are very cheap
operations in standard computer
architectures.
27. Similarities between computer
screen and Our board
• Computer screen is divided into
very small units called pixels and
out board is divided into small
movements called steps and we
replaced the function of
put pixel(X,Y); with step(Motor);
Figure-2 Sub-pixel display
http://en.wikipedia.org/wiki/Pixel
28. Example
Code written for screen Code written for Out machine
)Put _pixel(X+1,Y+1 );Set_Direction(MotorX,Positive
);Set_Direction(MotroY,Positive
);parallerStep(MotorX,MotorY
)put_pixel(X+1,Y Set_Direction(MotorX,Positive);
Step(&MotorX);
put_pixel(X,Y+1) Set_Direction(MotorY,Positive);
Step(&MotorY);
)Put_pixel(X-1,Y );Set_Direction(MotorX,Negative
);Step(&MotorX
29. Example of Bresenham Line
Drawing
Bresenham for drawing Line
7° 60° 30° 45°
Figure 3 our Implementation of Bresenham line
drawing on Console Screen Different slope
30. Midpoint Algorithm
G02,G03 Implementation
• the Midpoint circle algorithm is an
algorithm used to determine the points
needed for drawing a circle actually
drawing one octant but we draw the other
using mirroring. The algorithm is a variant
of Bresenham's line algorithm, and is thus
sometimes known as Bresenham's circle
algorithm.
31. Midpoint Algorithm Example
Bresenham's Circle algorithm
Figure-3 Rasterisation of a circle by the Bresenham algorithm
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
32. G00 Implementation
• Implementation phases
– Enable Interrupt handler of Each Timer[0,1,2]
– Configure Timer to trigger event
(On_TimerOverFlow)(void**); when Timer
overflow
• The foreground program is free to do
useful work as it is occasionally
interrupted output operations.
33. Context switching between
Motors on G00 command
Foreground
Foreground Step Step Step
Time process
process MotoX MotoZ MotoY
Figure-4
Context switching between
Step(&MotorX),
Step(&MotorY) and
Step(&MotorZ)
35. Testing and Simulations…
(PROTEUS)
• We simulate the behavior of motors
[#of performed step, frequency of the pulses] using
PROTEUS simulator. It enables us to test and debug
faster than the physical level.
• DEMO OF PROTEUS