Basic g-code theory – Smithy Ez-Trol2 User Manual

Page 56

Advertising
background image

BASIC G-CODE THEORY

CNC machine tools are controlled by instructions written in a language defined in a document from
the Electronic Industries Alliance (EIA) entitled "RS-274-D INTERCHANGE VARIABLE BLOCK
DATA CONTOURING, FORMAT FOR POSITIONING AND CONTOURING/POSITIONING
NUMERICALLY CONTROLLED MACHINES". The long name, along with the fact that the letter "G"
is frequently used, is why it's usually just referred to as G-code.

To use the rest of this chapter more effectively, it is probably best for you to first go to the
“SmithyCNC G-code Programmer’s Guide” and read the first chapter there about G-code
programming basics.

Originally, G-Code programs were punched as holes in stiff paper cards, or one-inch wide paper
tape on a roll (paper tape was very popular for a long time and is still in use some places today).
Each punched card could have several words, so several registers could be changed at once. The
CNC would read all the words on one card, then make all the changes simultaneously (like moving
an axis, turning on the spindle motor, and turning on the flood coolant pump) to make the physical
state of the machine match the numbers in the registers. Finally it would replace the old numbers
in the registers with the new ones read from the card, then read the next card. The number of
registers that could be changed at once was limited by the size of the cards. The most popular
punched card could hold 80.characters. When paper tape became popular, a special character or
characters (sometimes a dollar sign or a carriage return and line feed combination) was used to
mark the end of a group of words that was to be acted on by the CNC control. These groups of
words became known as a "block", and the special character(s) at the end are called the "end of
block" (EOB) character(s). When the CNC processes a block of code, it is said to "execute" that
block. A group of blocks is called a "part program", or just a "program", and when a CNC processes
a program it is said to "run" the program.

The same method is used today. Words are read and acted upon by the CNC control one block at a
time. The only difference is that a modern CNC control reads the part programs from an internal
disk drive rather than a paper tape reader. The program file format is plain text, one block of words
per line.

Before we start dissecting our code lets first take a look at block construction.

N1G40G49G80

(cancel dia. comp, length offset, canned cycles)

The N1 word is the block number. Scanning through the code reveals that each block
begins with an “N” and the number following the “N” organizes the selected G-code file
in a sequential order. The numbering is often found in multiples of five so that a line
can easily be inserted if necessary. The block numbering with N words is optional and
each line of code can have up to five blocks of code.

After the line number is the various words that are used to communicate with the
machine. These blocks, generally an identifying letter followed by a number are
considered individual G-code commands. They instruct the machine tool how to move
or what action to execute.

The text contained within the parenthesis is a comment. This particular comment was
supplied by the EZ-Trol CAM function to provide helpful information to the user.
EZ-Trol will also allow you to write in your own comments to document your own code
as desired.

SmithyCNC EZ-Trol II Control System

50 |

Toll Free 1-800-476-4849

Advertising