CNC | G20 and G21 Codes | Imperial and Metric System

CNC Dimensional Units Introduction

Addresses in a CNC program that relate to the tool position at a given moment are called the coordinate words. Coordinate words always have a dimensional value, using currently selected units – metric or imperial. Typical coordinate words are X ,Y, Z, I, J, K, R, etc. They are the basis of all dimensions in CNC programs. Tens, hundreds, even thousands of calculations may have to be made to develop a program that will do what it is intended to do – to accurately machine a complete part.

Dimensional entries in a program assume two attributes:

  • Dimensional units : Imperial or Metric
  • Dimensional references : Absolute or Incremental

Unit of dimensions in a program can be one of two kinds – metric or imperial. The reference of dimensions can be either absolute or incremental.

Fractional values, for example 1/8, are not allowed in a CNC program and have to be converted to their decimal equivalent. In metric format, milimeters and meters are used as units, in imperial format it is inches and feet that form the basis of units. Regardless of format selected, the number of programmed decimal places can be controlled, suppression of leading and trailing zeros can be set and decimal point can be programmed or omitted, as is applicable to a particular CNC system.

CNC Imperial and Metric Units

Drawing dimensions can be used in a program in either metric or imperial units. This article uses the combined examples of both the imperial (English) system, still common in the USA, to some extent in Canada, and one or two other countries. The metric system is common in the rest of the world.With economy reaching global markets, it is important to understand both systems. The use of metric system is on the increase even in countries that still use imperial units of measurement, mainly the United States.

Machines that come equipped with Fanuc controls can be programmed in either mode. Initial CNC system selection (known as the default condition) is controlled by a parameter setting of the control system, but can be overridden by a preparatory command written in the part program. Default conditions are usually set by the machine tool manufacturer or distributor. Often, it is based on engineering design decisions, as well as the demands of their customers.

During program development, it is imperative to consider the impact of control system default conditions on program execution. Default conditions come into effect the moment a CNC machine has been turned on. Once a command is issued, in MDI mode or in a program, many default values may be overwritten and will remain changed from that point on. Dimensional unit selection in the CNC program will change the default value – that is the internal control setting. In other words, if metric unit selection is made, the control system will remain in that mode until an imperial selection command is entered. That can be done either through the MDI mode, a program block, or a system parameter. This applies even for situations when the power has been turned off and then on again!

CNC Imperial or Metric System Selection

To select a specific dimensional input, regardless of default conditions, a preparatory G command is required at the beginning of CNC program:

G20 : Selects imperial units (inches and feet)
G21 : Selects metric units (milimeters and meters)

G20 and G21 Details

Without specifying the preparatory command in the program, control system will default to the status of current parameter setting. Both preparatory command selections are modal, which means the selected G code remains active until the opposite G code is programmed – so metric units will be active until the imperial system replaces it and vice versa.

This reality may suggest a certain freedom of switching between the two units anywhere in the program, almost at random and indiscriminately. This is not true. All controls, including Fanuc, are based on the metric system, partially because of the Japanese influence, but mainly because the metric system is more accurate. Any ‘switching’ by use of the G20 or G21 command does not necessarily produce any real conversion of one unit into the other, but merely shifts the decimal point, not the actual digits. At best, only some conversions take place, not all. For example, G20 or G21 selection will convert one measuring unit to another on some – but not all – offset screens. Many controls will convert all settings, but even then it is not recommended to mix the two unit systems in the same program.

G20 and G21 Codes Examples

Following two examples will illustrate the incorrect result of changing G21 to G20 and G20 to G21 within the same program. Read the comments attached to each block – you may find a few surprises:

Example 1 – From Metric to Imperial

G21 Initial unit selection (metric)
G00 X60.0 X value is accepted as 60mm
G20 Previous value will change into 6.0 inches
(real translation is 60mm=2.3622047 inches)

Example 2 – From Imperial to Metric

G20 Initial unit selection (imperial)
G00 X6.0 X value is accepted as 6.0 inches
G21 Previous value will change into 60mm
(real translation is 6.0 inches=152.4 mm)

Both examples illustrate the possible problem caused by switching between two dimensional units in the same program. For this reason, always use only one dimensional unit in a part program. If the program calls a subprogram, the rule extends to subprograms as well:

Never mix metric and imperial units in the same program!

Things to Know

In fact, it is ill-advised to mix them, even if the results for the control system are predictable and full conversion is available. The selection of dimensional system will make a great difference how some control functions will work. The following functions will be affected by the change from one system of units to the other:

  • Dimensional words (X, Y, Z axes, I, J, K modifiers, etc.)
  • Constant Surface Speed (CSS)
    (known as cutting speed, used by CNC lathes)
  • Feedrate function (F-address)
  • Offset values (H and D offsets for milling and tool preset values for lathes)
  • Screen position display (number of decimal places)
  • Manual Pulse Generator – the HANDLE (value of divisions)
  • Some control system parameters

The initial selection of dimensional units can also be done by a system parameter setting. Control status when the power has been turned on is the same as is was at the time of last power shut off. If neither G20 nor G21 is programmed, the control accepts dimensional units selected by a parameter setting. If G20 or G21 is included in the program, the program command will always take a priority over any control system parameter setting. Programmer makes all decisions – the control system is only interpreting them, but it does not mean it is always ‘right’.

Dimensional units setting should always be in a separate block, before any axis motion, offset selection, or even setting of a coordinate system (G92, G50 and G54 to G59) – in other words, it should be in the first program block. Failure to follow this rule may produce incorrect results, particularly when frequently changing units for different jobs.

Comparable Unit Values

There are many units available in both metric and imperial systems. In CNC programming, only a very small portion of them is used. Metric units are based on a milimeter or a meter, depending on application. Imperial units are based on inches and feet, again, depending on application. Common abbreviations for different units are: