jario_
Back to overview

CNC Basics · Chapter 2

Program structure

A recipe has a fixed structure: first the ingredients, then the steps, at the end "done". A CNC program also has a fixed structure. The machine reads it line by line, from top to bottom. In this chapter you learn the head of a program, how to number blocks and a second way of giving positions.

The program header

The first lines bring the machine into a known state:

  • % alone in a line marks the start of the program.
  • A comment in brackets names the program.
  • The header line G90 G21 G17: G90 means absolute dimensions, G21 millimetres instead of inches, G17 the X/Y plane, that is the top view.

The header is in every program so that nothing is left over from an earlier program.

%(PLATE 7)N10 G90 G21 G17N20 G00 X15 Y10N30 G00 X75 Y40N40 M30

Block numbers

A block number may stand in front of each block: N10, N20, N30. The machine ignores them. They help you name a block, for example when the machine reports "error in N40". You count in steps of ten so that you can insert a block later, such as N25 between N20 and N30.

Absolute: G90

With G90 every number is a place, measured from the zero point. That is like a house number: "number 50". Wherever you stand, the address stays the same.

(Absolute: every number is a place)G90 G21 G17G00 X20 Y10G00 X50 Y10   (go to X50)G00 X50 Y30M30

Incremental: G91

With G91 every number is a step from the current place. That is like a signpost: "30 m straight ahead". Negative numbers go back.

Incremental pays off for patterns that repeat, because the same lines can appear several times. You still give the start point absolutely: first G90 and go there, then G91.

(Incremental: every number is a step)G90 G21 G17G00 X20 Y10   (absolute start point)G91G00 X30       (30 mm to the right, now at X50)G00 Y20       (20 mm to the back, now at Y30)G00 X-10      (10 mm back to the left, now at X40)M30

Switching between the two

G90 and G91 stay active until you write the other one. If you mix them, write the matching word before every change and check which one is active.

(Switching between the two)G90 G21 G17G00 X10 Y10G91G00 X15 Y15   (step: now at X25 Y25)G90G00 X60 Y40   (place: X60 Y40)M30

Common mistakes

  • G91 stays active

    You switch to G91 and keep thinking in absolute places. The machine adds the numbers to the current place and ends up far outside. Usually it then shows an alarm, because the target is outside the travel range.

  • Start not absolute

    If you begin with G91 straight away, you do not know where the pattern starts, because the steps refer to the position where the tool happens to be. Move to the start point with G90 first.

  • Block numbers twice or mixed up

    The machine does not check the numbers, but you lose track. Count evenly in steps of ten and make sure each number appears only once.