ME 322 - Professor Molian's Lecture Notes on




1 Introduction

2 Elements of CNC

3 Types of Control Systems

4 Precision in CNC Machining

5 Principles of CNC

6 CNC Programming




The computer numerical control (CNC) facilitates integration of various manufacturing operations, provides flexibility to accommodate the design changes and reduces the human error thereby increasing the safety level in the manufacturing floor. In addition, CNC results in high accuracy and short production time. The drawbacks include high cost, maintenance, and the requirement of skilled part programmer.


CNC falls under the category of "Automation" which is defined as the process of performing a sequence of operations with little or no human effort using specialized equipment and devices. There are two types of automation: hard and soft. Hard or fixed automation is the design of mass-production machines to produce a standardized product such as an engine block. It is not flexible enough to modify the shapes and dimensions to a large extent. Soft of flexible automation is a process of using numerical control, adaptive control or robotic control to control the various functions of the machine. It produces parts with complex shapes and leads to the development of flexible manufacturing systems. Design changes can readily be implemented in soft automation.


CNC is a method of controlling the functions and motions of a machine tool by means of a prepared program containing instructions in the form of numerical data (numbers and letters). In the field of machining, where CNC has been applied to a large extent, CNC controls the motion of the workpiece of tool, the input parameters such as feed, depth of cut, speed, and the functions such as spindle on/off and coolant on/off.


The applications of CNC included both for machine tool as well as non-machine tool areas. In the machine tool category, CNC is widely used for lathe, drill press, milling machine, grinding unit, laser, sheet-metal press working machine, and tube bending machine. Highly automated machine tools such as turning center and machining center which change the cutting tools automatically under CNC control have been developed. In the non-machine tool category, CNC applications include welding machines (arc and resistance), coordinate measuring machine, electronic assembly, tape laying and filament winding machines for composites.


Elements of CNC

A CNC system consists of three basic components (see Figure 13.6 in the text):


  1. Computer for storing the part programs.
  2. Machine Control Unit (MCU) for processing programs.
  3. Machine Tool with Motors for physically executing the program.

 Computer Part Program

 The part program is a detailed set of commands to be followed by the machine tool. Each command specifies a position in the Cartesian coordinate system (X,Y,Z) or motion (workpiece travel or cutting tool travel), machining parameters and on/off function. Part programmers should be well versed with machine tools, machining processes, effects of process variables, and limitations of CNC controls. The part program is written for manually or p using computer-assisted language such as APT (Automated Programming Tool).

 Machine Control Unit

The machine control unit (MCU) is a microcomputer that stores the program and executes the commands into actions by the machine tool. The MCU consists of two main units: data processing unit (DPU) and the control loops unit (CLU). The DPU software includes control system software, calculation algorithms, translation software that converts the part program into a usable format for the MCU, interpolation algorithm to achieve smooth motion oh the cutter, and editing of part program (in case of errors and changes). The CLU consists of the circuits for position and velocity control loops, deceleration and backlash take up, and function controls such as spindle on/ off.

The DPU processes the data from the part program and provides it to the CLU, which operates the drives, attached to the machine leadscrews and receives feedback signals on the actual position and velocity of each one of the axes. A driver (DC motor) and a feedback device are attached to the leadscrew.

Machine Tool

The machine tool could be one of the following: lathe, milling machine, laser, plasma coordinate measuring machine, etc. A right hand coordinate system is used to describe the motions of a machine tool (See figure 1). There are three linear axes (X,Y,Z) and three rotational axes (U,V,W), and other axes such as tilt (q ) are possible. For example, a five axis machine implies that X,Y,Z,U and q .

Figure 1. Right hand coordinate system used in drill press and lathe.

Types of Control Systems

Open Loop Control Systems

The open-loop control means that there is no feedback and uses stepping motors for driving the leadscrew. A stepping motor is a device whose output shaft rotates through a fixed angle in response to an input pulse (Figure 13.17 of the text). The accuracy of the system depends on the motors ability to step through the exact number. The frequency of the stepping motor depends on the load torque. The higher the load torque, the lower the frequency. Excessive load torque may occur in motors due to the cutting forces in machine tools. Hence, this system is more suitable for cases where the tool force does not exist (Example: laser cutting).

The stepping motor is driven by a series of electrical pulses generated by the MCU. Each pulse causes the motor to rotate a fraction of one revolution. The fraction is expressed in terms of the step angle,

a = 360/N where N = number of pulses required for one revolution

If the motor receives "n" number of pulses then the total angle,

A= n (360/N) degrees

In terms of the number of revolutions, it would be (n/N)

If there is a one to one gear ratio between the motor and the leadscrew, then the leadscrew has (n/N) revolutions. If the pitch frequency, f, in pulses/sec determines the travel speed of the tool of the workpiece,

60f = N (RPM) where N = number of pulses per revolution, and where RPM = RPM of the lead screw.

The travel speed, V, is then given by

V= p (RPM) where p is pitch in in./rev.


Example 1

A stepping motor has N = 150, p= .2"/rev. If n = 2250 pulses, what is the distance traveled in the x-direction? What would be the pulse frequency for a travel speed of 16 in./min?

X = (0.2)(2250)/150 = 3"

16 = .2 (RPM), from which, RPM = 80

f = (150) (80)/60 = 200Hz


Closed Loop Control Systems

Closed loop NC systems are appropriate when there is a force resisting the movement of the tool/workpiece. Milling and turning are good examples. In these systems (Figure 13.7 of the text), the DC servomotors and feedback devices are used to ensure that the desired position is achieved. The feedback sensor used in as optical encoder shown in Figure 2. The encoder consists of a light source, a photodetector, and a disk containing a series of slots. The encoder is connected to the leadscrew. As the screw turns, the slots cause the light to be seen by the photodetector as a series of flashes which are converted into an equivalent series of electrical pulses which are then used to characterize the position and the speed. The equations remain essentially the same as open loop except that the angle between the slots in the disk becomes the step angle, a.

The input to the control loop and the feedback signals are a sequence of pulses, each pulse representing a BLU unit [Basic Length Unit (BLU) is the position resolution of the axis of motion. For example, 1 BLU = 0.0001" means that the axis will move 0.0001" for every one electrical pulse received by the motor].

The input and the feedback are correlated by a comparator that gives a signal, by means of a digital to analog converter, (a signal representing the position error), to operate the drive motor (DC servomotor).

Figure 2. Optical encoder (a) Device (b) series of pulses emitted


Example 2

Consider a CNC worktable driven by a closed-loop control system consisting of a servomotor, lead screw, and optical encoder. The lead screw has a pitch, p= 0.2" and is coupled to the motor shaft with a screw to motor gear ratio of 1:4. The encoder generates 150 pulses per revolution of the lead screw. If the number of pulses and the pulse rate received by the control system are 2250 and 200 Hz respectively, calculate:

  1. Table speed
  2. Motor speed in RPM
  3. Distance traveled by the table
  1. V = p (RPM) = 0.2(RPM) = 0.2(60f)/N = (0.2)(60)(200)/150 = 16 in./min.
  2. RPM of the leadscrew = (60)(200)/(150) = 80

RPM of the motor = 320

c. x = p(n/N) = (0.2) (2250)/(150) = 3"



The combined characteristics of machine tool and CNC controller determine the precision of positioning. Three measures of precision are:

    1. Resolution
    2. Accuracy
    3. Repeatability
    4. Control Resolution (BLU) is the distance separating two adjacent points in the axis movement (the smallest change in the position). The electromechanical components of the positioning system that affect the resolution are the lead screw pitch, the gear ration, and the step angle in the stepping motor (open loop) or the angle between the slots in the encoder (closed-loop). The control resolution for a 1:1 gear ration of a stepped motor is,

      Resolution: =P/N where p = pitch and N = 360/a

      Features smaller that the control resolution could not be produced. The programming resolution can not exceed the control resolution.

      Accuracy of a CNC system depends on the resolution, the computer control algorithms, and the machine inaccuracies. The inaccuracy due t other resolution is considered to be (1/2) BLU on the average. The control algorithm inaccuracy is due to the rounding off the errors in the computer, which is insignificant. The machine inaccuracy could be due to several reasons (described below). The designer prefers this inaccuracy to be under (1/2) BLU and hence

      Accuracy = (1/2) Resolution + Machining inaccuracy = BLU

      Machining Inaccuracy

      Cutting tool deflection, machine tool chatter, mechanical linkage between the lead screw and the tool, and thermal deformations are the chief contributing factors. The lead screw transmits the power to the table or tool holder by means of a nut that engages the lead screw. This will create what is known as "backlash" due to the friction between the screw and the nut. If the nut consists of ball bearings, the friction is reduced. Thermal deformations are significant. For example, a temperature difference of 10C along 1000 mm can cause an error of 0.01 mm.

       Repeatability is statistical term associated wit accuracy. It refers to the capability of a positioning system to return to a programmed point, and is measured in terms of the errors associated with the programmed point. The deviation from the control point (error) usually follows a normal distribution in which case the repeatability may be given as +/- 3s where s is the standard deviation. The repeatability is always better than the accuracy. The mechanical inaccuracy can be considered as the repeatability. Figure 3 shows the difference between accuracy and repeatability.

      Figure 3. Diagram showing the difference between accuracy and repeatibility

      Example 3

      What is the control resolution for a 4:1 gear ration (motor:lead screw), pitch of leadscrew 0.2 in/rev, and the motor receives 600 pulses per revolution?

      Since the motor shaft rotates 4 times faster than the lead screw, N=600/4 = 150

      Resolution =0.2/150 =0.001333"



      Point to Point Systems

      Point to Point systems are those that move the tool or the workpiece from one point to another and then the tool performs the required task. Upon completion, the tool (or workpiece) moves to the next position and the cycle is repeated (Figure 13.9 of the text). The simplest example for this type of system is a drilling machine where the workpiece moves. In this system, the feed rate and the path of the cutting tool (or workpiece) have no significance on the machining process.

      Example 4

      The XY table of a drilling machine has to be moved from the point (1,1) to the point (6,3). Each axis can move at a velocity of 0.5"/sec, and the BLU is 0.0001", find the travel time and resolution.

      Travel time in X-axis is (6-1)/0.5 = 10 sec, in Y-axis is (3-1)/0.5 = 4 sec.

      Travel time = 10 sec and Resolution = BLU = 0.0001


      Continuous Path Systems (Straight Cut and Contouring Systems)

      These systems provide continuous path such that the tool can perform while the axes are moving, enabling the system to generate angular surfaces, two-dimensional curves, or three-dimensional contours. Example is a milling machine where such tasks are accomplished (Figure 13.9 of the text). Each axis might move continuously at a different velocity. Figure 13.11 of the text illustrates point-to-point and continuous path for various machining processes.

      Example 5

      A CNC milling machine has to cut a slot located between the points (0,0) and (4,3) on the XY-plane where the dimensions are in inches. If the speed along the slot is to be 0.1 in/sec, fine the cutting time and axial velocities.

      Distance traveled along the slot = (16+9)1/2 = 5"

      Cutting Time = 5/0.1 = 50 sec, Vx = xV/(x2+y2)1/2= 4(0.1)/5 = 0.08 in/sec. Vy = yV/( x2+y2)1/2 = 3(0.1)/5 = 0.06 in/sec



      The interpolation, the movement along the path, occurs incrementally by one of the several methods shown in figure 13.10 of the text. In linear interpolation, the tool moves along a profile (could be a straight line or a curve) by steps in two or three axes. Generally this requires large amount of data for providing an accurate path. In circular interpolation, the profile is an arc and tracing requires the end points of the arc, the coordinates of the center and its radius, and the direction of the arc. In parabolic and cubic interpolation, the path is approximated by curves using higher order mathematical equations. This is generally used for 5-axis machines (mold and die sculpturing).

      Incremental and Absolute systems

      CNC systems are further divided into incremental land absolute systems (Figure 4). In incremental mode, the distance is measured from one point to the next. For example, if you want to drill five holes at different locations, the x-position commands are x+500, +200, +600 -700, -300. An absolute system is one in which all the moving commands are referred from a reference point (zero point or origin). For the above case, the x-position commands are x 500,700,1300,1000,300,0. (Figure 4). Both systems are available in most CNC systems. For an inexperienced operator, it is wise to use incremental mode.

      The absolute system ahs two significant advantages over the incremental system:

              1. Interruptions caused by, for example, tool breakage (or tool change, or checking the parts), and will not affect the position at interruption.

If a tool is to be replaced at some stage, the operator manually moves the table, exchanges the tool, and has to return the table to the beginning of the segment in which the interruption has occurred. In the absolute mode, the tool is automatically returned to the position. In incremental mode, it is almost impossible to bring it precisely to that location unless you repeat the part program.

Easy change of dimensional data

The incremental mode has two advantages over the absolute mode.

    1. Inspection of the program is easier because the sum of position commands for each axis must be zero. A nonzero sum indicates an error. Such inspection is impossible with the absolute system.
    2. Mirror image programming (for example, symmetric geometry of the parts) is simple by changing the signs of the position commands.
    3. Figure 4. (a) Absolute versus incremental; In absolute positioning the move is specified by x=6, y=8; in incremental, the move is specified by x=4, y=5 for the tool to be moved from (2,3) to (6,8) (b) drilling 5-holes at different locations.


      The transfer of an engineering blueprint of a product to a part program can be performed manually using a calculator of with the assistance of a computer language. A part programmer must have an extensive knowledge of the machining processes and the capabilities of the machine tools. In this section, we describe how the part programmers execute manually the part programs.

      First, the machining parameters are determined. Second, the optimal sequence of operations is evaluated. Third, the part of the tool is calculated. Fourth, a program is written. Each line of the program, referred to as a block, contains the required data for transfer from one point to the next.

      A program for machining a line is given below.

      N100 G91 X -5.0 Y7.0 F100 S200 T01 M03


      N100 G91

      N101 G01 X-5.0 Y7.0 F100 S200 T01 M02

      The significance of each term is explained below.

      Sequence Number, N

      Consisting typically of three digits (could be one or two digits), its purpose is to identify the specific machining operation through the block number particularly when testing a part program.

      Preparatory Function, G

      It prepares the MCU circuits to perform a specific operation. The G-codes (some) are shown in Table 1. G91 implies incremental mode of operation. G01 implies linear interpolation.

      Dimension Words 

      1. Distance dimension words X,Y,Z
      2. Circular dimension words I, J, K for distances to the arc center
      3. Angular dimensions, A, B, C

In the above block, X moves a distance of 5 in. in the negative direction while Y moves a distance of 7 in. in the positive direction. Other axes remain stationary. In some systems, actual distances are used. In others, the dimension words are programmed in BLUs.

Feedrate, F

It is expressed in in/min or mm/min and is used in contouring or point-to-point or straight-cut systems. For example, a feedrate of F100 implies 100 in/min or 100 cm/min. Feed rates are independent of spindle speed. In linear motions, the feedrate of the cutting tool is not corrected for the cutter radius. But in circular motions, the feedrate should be corrected for the tool radius as follows: F =[(part contour radius tool radius)/part contour radius] (feed).

For cutting around the outside of a circle, the plus sign in the above equation is used and the feed rate is increased. For cutting around the inside of a circle, the minus sign is used and the feed rate is decreased.

Example 6

See Figure 13.9 of the text. If the required feed rate is 6 in/min, part contour radius is 1.5 in, and the cutter diameter is 1 in, what is the feed rate at the top and bottom circles?

Feedrate at the top is to be 8 in/min and at the bottom is to be 4 in/min.


 Spindle speed, S

Programmed in rev/min, it is expressed as RPM or by a three-digit code number that is related to the RPM.

Toolword, T

Consisting of a maximum of five digits, each cutting tool has a different code number. The automatic tool changer automatically selects the tool when the code number is programmed in a block.

Miscellaneous Function, M

Consisting of two digits, this word relates to the movement of the machine in terms of spindle on/off, coolant on/off, etc. shown in table 2.


A CNC controlled vertical milling machine is used to perform end milling of a simple part shown in Figure 5. A feed rate of 500 mm/min is required for machining. The rapid traverse feed rate is 2500 mm/min (can be used for moving without machining). A constant spindle peed of 100 rpm is to be used. Only one cutter with a diameter of 20 mm is used. The cutter is initially at 40 mm above the table at the start point.

Figure 5 shows the dotted line as the tool center path and solid line as the part. Dimensions are specified in mm. Flood coolant is used during milling.

Write a complete part program in the incremental system.


N100 G91 ® Incremental mode

N101 G01 X60 F2500 ® Linear interpolation, tool is moved a distance 60 mm.

N102 Z40 S1000 M03 ® Tool is turned on and moves a distance -40 mm

N103 X10 F500 M08 ® Begin the cutting with coolant on. Note the feedrate.

N104 X80 ® Machine a distance 80mm

N105 Y 64.14 ® the cutter moves in the +Y direction to the point C.

N106 X-32.93 Y32.93 ® The cutter moves to the point D.

Use the figure shown below to compute the distance BC to CD.

BC = BB' + CB' = 60 + MB' tan 22.5 = 60 = 10 tan 22.5 = 64.14 mm

CD = MN + OC =42.43 + 4.14 = 46.57

Since CD is at 450, resolve it into X and Y as 46.57/(21/2 ) = 32.93 mm

After passing the point D and prior to the start of the circular arc ED (whose center is N), use the figure shown below.

We can write

I2 + j2=100 j+y = 10, I=x=.707R=7.07

Solving all these, x=I=j=7.07mm y=2.93mm

N107 Z 0.5 (0.5 is arbitrary)

N108 G03 X-7.07 Y2.93 I7.07 J7.07

N109 Z-0.5

No cutting takes place between points D and E.

N110 X-40 Y-40 J50 F667

F is increased to 667 due to the cutter radius as given by the equation.

F=[(part contour radius + tool radius)/part contour radius](required feed rate) = 40/30(500) = 667

N111 G01 Y-60 F500

N112 X-70 Z40 F500M05 M09

N113 M02

Web page designed and maintained by: