MachiningBlog.com

View Original

CNC Macro Programming Basics

We will cover the basics of Parameter programming. The concepts learned can be applied to many CNC projects and can be used in small shops and large shops alike. In G Code, macro programming variables are assigned values and when they are referenced and called they provide the last value that they were assigned. Some ways that variables can be used are for machining part families and for modifying work offsets and tooling offsets.



Variables

#1 To #33 are Local Variables which are variables used for temporary storage. They are used locally in a macro program. Once the power to the machine is interrupted the value will be lost.

#100 To #199 are Common Variables which once the power to the machine is turned off, the value will be lost. They are shared between main programs and sub programs.

#500 To #999 are Common Variables which store the values in the table regardless of the power being turned off. These common variables can also be set to Read Only, by setting the appropriate parameters

#1000 and Up are System Variables that are used to read and write to modify work offsets, tooling offsets and are used for automation purposes. The usage of system variables doesn’t vary in its application.

Variable Alarm Options

Variable alarms allow the programmer to tell the operator various instructions while the CNC program is running and they can also stop the program and output an alarm message for the operator.





Some example of alarm uses:

#3000=1 (Check Clamps and Vise)

The message (Check Clamps and Vise) cannot be longer than 26 characters long. The message will be displayed but the machine will keep operating.

If you desire the machine to stop when the alarm message comes up, then the Macro should be this:

#3006=1 (Check Clamps and Vise)



The alarm line might look like this format below:

N9012 #3000=12 (ALARM 12 INPUT BLANK HEIGHT)

Square Brackets

Macro B programming uses square brackets not parenthesis, because parenthesis are used only for comments inside the G code program.

The Correct Format and Usage of Square Brackets:

#100=[#105 * #106] - #110

In this instance above, the variable #100 is equal to the result of variable #105 multiplied by variable #106, then subtracted from variable #110



Brackets can also be used in other instances such as IF statements

Examples as follows:

IF[#100GT300]GOTO9012

IF[[#6NE4]AND[#6NE5]] GOTO9013



Functions in a Macro Program

Standard Operators for Math

  • + Addition

  • - Subtraction

  • * Multiplication

  • / Divide

Functions

  • ABS Absolute Value

  • ROUND Rounding Off

  • FIX Rounding Down

  • FUP Rounding Up

  • SQRT Square Root

  • OR Logical OR

  • AND Logical And

  • IF

  • THEN