Macro B Reference Guide
Macro B programming may not be included on your MachMotion control. If you are not able to use these macros, contact us for an upgrade option.
1. Calling macros
Call Formats  Example  Notes  License Required 
M98 P__ Q__ L__ 
Run subroutine 0100 twice, starting at line 5 (N5) 
M98 calls the subroutine specified by P (must be 4 digits), and starts at the line number specified by Q (optional). It will repeat it the number of times passed to L (default is 1)  Any 
G65 P__ L__ A__ B__ …. 
Run macro 0150 twice, passing 5 into #1 (A) and 10 into #2 (B) 
M65 calls a nonmodal macro specified by P and passes AZ (whichever are specified) to the macro. M65 repeats a number of times set by L and does not need to be cancelled. Pound variables AZ are wiped after the macro completes.  Industrial 

Run macro 1001 with A = 12 and B = 6, then run it again with A = 10 and B = 5, then cancel the modal. 
G66 is a modal macro call. It is cancelled by G67. Any lines in between will call the same macro with whichever parameters you pass it. 
Industrial 


Cancels the modal G66 
Industrial 


Specifies end of subroutine or macro 
Any 
2. Passing Variables
You can pass variables to macros using letters AZ, which correspond to pound variables. These are not places to store important information! Once you leave a function it is unknown what will be in that pound variable. The letters G, L, N, O, and P cannot be used as variables.
Example:
% G65 P0100 A5 M30 O0100 #500 = #1 M99 % 
Pass a value of 5 to macro 0100.
Start of macro. The value of A is stored in #1, and we will save it to #500. Return from the macro. 
2.1 Variables
A 
B 
C 
D 
E 
F 
H 
I 
J 
K 
M 
Q 
R 
S 
T 
U 
V 
W 
X 
Y 
Z 
1 
2 
3 
7 
8 
9 
11 
4 
5 
6 
13 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
3. In a macro
3.1 Storage Variables
There are two ranges of pound variables for the user to store values in.
 #100#199 : Values will be cleared every time Mach starts up
 #500#1000 : Values will be saved every time Mach shuts down
3.2 Arithmetic
There are the basic add/subtract/multiply/divide functions available to the user, as well as some named functions for more advanced math. When performing arithmetic, the control follows the order of [Brackets, Functions, Multiply, Divide, Add, Subtract].
Function 
Symbol 
Example 
Notes 
Assignment 
= 
#100 = 5 
Sets #100 equal to 5 
Addition 
+ 
#100 = 2 + 3 
Sets #100 equal to the value of 2+3 (5) 
Subtraction 
 
#100 = 2 – 3 
Sets #100 equal to the value of 23 (1) 
Multiplication 
* 
#100 = 2 * 3 
Sets #100 equal to the value of 2*3 (6) 
Division 
/ 
#100 = 2 / 3 
Sets #100 equal to the value of 2/3 (0.66) 
Absolute Value 
ABS[ ] 
#100 = ABS[ 3 ] 
Sets #100 equal to the absolute value of 3 (3) 
Rounding 
ROUND[ ] 
#100 = ROUND[ 3 / 2 ] 
Sets #100 equal to the rounded value of 3/2 (2) 
Round Down (floor) 
FIX[ ] 
#100 = FIX[ 3 / 2 ] 
Sets #100 equal to the floor of 3/2 (1) 
Round Up (ceiling) 
FUP[ ] 
#100 = FUP[ 3 / 2 ] 
Sets #100 equal to the ceiling of 3/2 (2) 
Sine 
SIN[ ] 
#100 = SIN[ 45 ] 
Sets #100 equal to the sine of the value (0.707). Takes degrees. 
Cosine 
COS[ ] 
#100 = COS[ 45 ] 
Sets #100 equal to the cosine of the value (0.707). Takes degrees. 
Arc Cosine 
ACOS[ ] 
#100 = ACOS[ 0.707 ] 
Sets #100 equal to the arc cosine of the value in degrees (45) 
Tangent 
TAN[ ] 
#100 = TAN[ 45 ] 
Sets #100 equal to the tangent of the value (1). Takes degrees. 
Arc Tangent 
ATAN[ ] 
#100 = ATAN[ 1 ] 
Sets #100 equal to the arc tangent of the value in degrees (45) 
Square Root 
SQRT[ ] 
#100 = SQRT[ 9 ] 
Sets #100 equal to the square root of the value (3) 
Natural Logarithm 
LN[ ] 
#100 = LN[ 2.3 ] 
Sets #100 equal to the natural logarithm of the value (0.83) 
Exponent 
EXP[ ] 
#100 = EXP[ 3 ] 
Sets #100 equal to the constant e raised to the value passed 
Decimal Adding 
ADP[ ] 
#100 = ADP[ #3 ] 

3.3 Logic Statements
Operator GOTO, IF, and WHILE are used for decision making within a macro. Be careful not to create infinite loops.
Operator 
Example 
Notes 
N 
N5 
Labels the line with a number, which can be referenced on other lines. 
GOTO 
GOTO 5 
Skip to line 5 (line labeled N5). Can be above or below current line. 
IF 
IF [condition] GOTO 5 #100 = 1 GOTO 6 N5 #100 = 0 N6 #500 = #100 
If the condition is true, it will execute the statement on that line. If it is false, it will skip it. It is combined with GOTO to create true and false sections of code. 
WHILE 
WHILE [condition] DO 1 Statements END 1 
While the condition is true, the code will loop through the code between DO 1 and END 1. The numbers 1 correspond to each other. It can be any number as long as it is the same at both the start and the end. 
3.4 Auxiliary Functions
There are additional pound variables which have functionality that may be useful to the user.
Pound Variable 
Functionality 
Example 
#3001 
Millisecond timer. Setting it to 0 will reset the timer, and its value at any point can be stored in another pound variable. 
(This function waits 1 second) #3001 = 0 WHILE [#3001 LE 1000] DO 1 END 1 
#3002 
Hour timer. Setting it to 0 will reset the timer, and its value at any point can be stored in another pound variable. 
#100 = #3002 WHILE[condition] DO 1 Statements END 1 #101 = #3002  #100 (#101 now holds the difference in hours to run the while loop) 
#3000 
Generates alarm. Gcode will be stop and the operator must reset to continue. 
#3000 = 1 (Example Message) 
#3006 
Generates an alarm with an associated message. Requires a reset before continuing. 
#3006 = 101 (Example Message) 
#3007 
Reports the state of Mirror Image, cannot be set (use G50 or G51 to set) 
#100 = #3007 
#3004 
Set this variable with a 3digit number. Digit 0 will enable/disable feed hold, digit 1 will enable/disable feedrate override, digit 2 will enable/disable exact stop. 
#3004 = 110 (disable exact stop, disable feedrate override, and enable feed holds) 
#3005 
Changes the units of measurement between imperial and metric 
#3005 = 1 (sets units to metric) 
#3011 
Returns the current data in YYYYMMDD form 
#100 = #3011 (get date) #100 = FIX[ #100 / 10000] (#100 now has just the year) 
#3012 
Returns the current time in HHMMSS form 
#100 = #3012 
#3100 
Returns nil 
#100 = #3100 (clear #100) 
#3101 
Returns pi 
#100 = #3101 * [3 * 3] (area of a circle = pi * rsquared) 
#3102 
Returns the constant e 
#100 = #3102 
#6000 
Set bit b00X00000 to 1 to step into a subroutine or macro. Set it to 0 step over it. 
For example, use this gcode to step into a subroutine: G10 L50 
3.5 System Variables
It is not recommended that you change the values of these pound variables, though they are available to the user. Changing values can result in unexpected machine movement.
When setting modal groups, multiply the desired value by ten. For instance, to set the active motion gcode (#4001) to a feed rate move (G01), set #4001 = 10.
Modal Groups 

Pound Variable 
Description 
#4001 
Active motion Gcode 
#4002 
Active motion plane 
#4003 
Motion mode (incremental or absolute) 
#4004 
Arc center mode 
#4005 
G93 (inverse time) or G94 unit/min 
#4006 
Imperial or metric units 
#4007 
Current cutter compensation mode 
#4008 
Tool length offset 
#4009 
Canned cycles 
#4010 
Used for canned cycles, old z or rplane 
#4011 
Scale mode 
#4012 
Modal macro 
#4013 
Spindle mode 
#4014 
Coordinate systems 
#4015 
Exact path or cutting mode 
#4016 
Coordinate system rotation mode 
#4017 
Polar mode 
#4018 
Compensation mode 


Buffered Values 

Pound Variable 
Description 
#4102 
Last buffered B code value 
#4107 
Last buffered D code value 
#4108 
Last buffered E code value 
#4109 
Last buffered F code value 
#4111 
Last buffered H code value 
#4113 
Last buffered M code value 
#4114 
Last buffered N code value 
#4115 
Last buffered O code value 
#4119 
Last buffered S code value 
#4120 
Last buffered T code value 


Original Offsets 

Pound Variable 
Description 
#4140 
Original X Offset 
#4141 
Original Y Offset 
#4142 
Original Z Offset 
#4143 
Original A Offset 
#4144 
Original B Offset 
#4145 
Original C Offset 


Last Outputs 

Pound Variable 
Description 
#5001 
Last X Output 
#5002 
Last Y Output 
#5003 
Last Z Output 
#5004 
Last A Output 
#5005 
Last B Output 
#5006 
Last C Output 


Machine Positions 

Pound Variable 
Description 
#5021 
Current Mach X Position 
#5022 
Current Mach Y Position 
#5023 
Current Mach Z Position 
#5024 
Current Mach A Position 
#5025 
Current Mach B Position 
#5026 
Current Mach C Position 


Fixture Offsets 

Pound Variable 
Description 
#5030 
Fixture X Offset 
#5031 
Fixture Y Offset 
#5032 
Fixture Z Offset 
#5033 
Fixture A Offset 
#5034 
Fixture B Offset 
#5035 
Fixture C Offset 


Part Positions 

Pound Variable 
Description 
#5041 
Current X Part Position 
#5042 
Current Y Part Position 
#5043 
Current Z Part Position 
#5044 
Current A Part Position 
#5045 
Current B Part Position 
#5046 
Current C Part Position 


G92 Offsets 

Pound Variable 
Description 
#5050 
G92 X Offset 
#5051 
G92 Y Offset 
#5052 
G92 Z Offset 
#5053 
G92 A Offset 
#5054 
G92 B Offset 
#5055 
G92 C Offset 


G31 Positions 

Pound Variable 
Description 
#5061 
Probe Part X Coordinate 
#5062 
Probe Part Y Coordinate 
#5063 
Probe Part Z Coordinate 
#5064 
Probe Part A Coordinate 
#5065 
Probe Part B Coordinate 
#5066 
Probe Part C Coordinate 
#5071 
Probe Machine X Coordinate 
#5072 
Probe Machine Y Coordinate 
#5073 
Probe Machine Z Coordinate 
#5074 
Probe Machine A Coordinate 
#5075 
Probe Machine B Coordinate 
#5076 
Probe Machine C Coordinate 


Head Shift Offsets 

Pound Variable 
Description 
#5081 
X Position Head Shift 
#5082 
Y Position Head Shift 
#5083 
Z Position Head Shift 
#5084 
A Position Head Shift 
#5085 
B Position Head Shift 
#5086 
C Position Head Shift 


G76 Values (Lathe Only) 

Pound Variable 
Description 
#5140 
Minimum pass depth 
#5141 
Finish pass depth 
#5142 
Number of finish passes 
#5143 
Thread angle 
#5144 
Chamfer amount 
#5145 
Cutting method 


Cutter Compensation 

Pound Variable 
Description 
#5157 
Cutter compensation X value 
#5158 
Cutter compensation Y value 
#5159 
Cutter compensation Z value 


G30 Coordinates 

Pound Variable 
Description 
#5181 
Active G30 X Coordinate 
#5182 
Active G30 Y Coordinate 
#5183 
Active G30 Z Coordinate 
#5184 
Active G30 A Coordinate 
#5185 
Active G30 B Coordinate 
#5186 
Active G30 C Coordinate 


G30 P2 Coordinates 

Pound Variable 
Description 
#5351 
G30 P2 X Coordinate 
#5352 
G30 P2 Y Coordinate 
#5353 
G30 P2 Z Coordinate 
#5354 
G30 P2 A Coordinate 
#5355 
G30 P2 B Coordinate 
#5356 
G30 P2 C Coordinate 


G30 P3 Coordinates 

Pound Variable 
Description 
#5361 
G30 P3 X Coordinate 
#5362 
G30 P3 Y Coordinate 
#5363 
G30 P3 Z Coordinate 
#5364 
G30 P3 A Coordinate 
#5365 
G30 P3 B Coordinate 
#5366 
G30 P3 C Coordinate 


G30 P4 Coordinates 

Pound Variable 
Description 
#5371 
G30 P4 X Coordinate 
#5372 
G30 P4 Y Coordinate 
#5373 
G30 P4 Z Coordinate 
#5374 
G30 P4 A Coordinate 
#5375 
G30 P4 B Coordinate 
#5376 
G30 P4 C Coordinate 


Work Shift Offsets 

Pound Variable 
Description 
#5201 
X Work Shift 
#5202 
Y Work Shift 
#5203 
Z Work Shift 
#5204 
A Work Shift 
#5205 
B Work Shift 
#5206 
C Work Shift 


G60 Approach Distances 

Pound Variable 
Description 
#5440 
G60 X Distance 
#5441 
G60 Y Distance 
#5442 
G60 Z Distance 
#5443 
G60 A Distance 
#5444 
G60 B Distance 
#5445 
G60 C Distance 




G54 Fixture Offsets 

Pound Variable 
Description 
#5221 
X Offset 
#5222 
Y Offset 
#5223 
Z Offset 
#5224 
A Offset 
#5225 
B Offset 
#5226 
C Offset 


G55 Fixture Offsets 

Pound Variable 
Description 
#5241 
X Offset 
#5242 
Y Offset 
#5243 
Z Offset 
#5244 
A Offset 
#5245 
B Offset 
#5246 
C Offset 


G56 Fixture Offsets 

Pound Variable 
Description 
#5261 
X Offset 
#5262 
Y Offset 
#5263 
Z Offset 
#5264 
A Offset 
#5265 
B Offset 
#5266 
C Offset 


G57 Fixture Offsets 

Pound Variable 
Description 
#5281 
X Offset 
#5282 
Y Offset 
#5283 
Z Offset 
#5284 
A Offset 
#5285 
B Offset 
#5286 
C Offset 


G58 Fixture Offsets 

Pound Variable 
Description 
#5301 
X Offset 
#5302 
Y Offset 
#5303 
Z Offset 
#5304 
A Offset 
#5305 
B Offset 
#5306 
C Offset 


G59 Fixture Offsets 

Pound Variable 
Description 
#5321 
X Offset 
#5322 
Y Offset 
#5323 
Z Offset 
#5324 
A Offset 
#5325 
B Offset 
#5326 
C Offset 


G54.1 P1 

Pound Variable 
Description 
#7001 
X Offset 
#7002 
Y Offset 
#7003 
Z Offset 
#7004 
A Offset 
#7005 
B Offset 
#7006 
C Offset 


G54.1 P2 

Pound Variable 
Description 
#7021 
X Offset 
#7022 
Y Offset 
#7023 
Z Offset 
#7024 
A Offset 
#7025 
B Offset 
#7026 
C Offset 
For more information about Macro B please see the Macro B Quick Reference Guide.
Keywords: Advanced M code MCode MCode G code GCode GCode Macro B MacroB macros # pound variables