This document provides an example of using G-code subroutines in Turbo PMAC to implement G-code and M-code functionality. It defines subroutines in motion programs 1000-1002 to handle common G-codes for motion, M-codes for tools and outputs, and T-codes for tool selection and parameters. The example also switches feedrate overrides between rapid and cutting moves, enables exact stopping, and implements cutter radius compensation.
This document provides an example of using G-code subroutines in Turbo PMAC to implement G-code and M-code functionality. It defines subroutines in motion programs 1000-1002 to handle common G-codes for motion, M-codes for tools and outputs, and T-codes for tool selection and parameters. The example also switches feedrate overrides between rapid and cutting moves, enables exact stopping, and implements cutter radius compensation.
This document provides an example of using G-code subroutines in Turbo PMAC to implement G-code and M-code functionality. It defines subroutines in motion programs 1000-1002 to handle common G-codes for motion, M-codes for tools and outputs, and T-codes for tool selection and parameters. The example also switches feedrate overrides between rapid and cutting moves, enables exact stopping, and implements cutter radius compensation.
This document provides an example of using G-code subroutines in Turbo PMAC to implement G-code and M-code functionality. It defines subroutines in motion programs 1000-1002 to handle common G-codes for motion, M-codes for tools and outputs, and T-codes for tool selection and parameters. The example also switches feedrate overrides between rapid and cutting moves, enables exact stopping, and implements cutter radius compensation.
G-Code Program Example Turbo PMACs capability for accepting and executing RS-274 (G-code) programs gives the user great power and flexibility in creating and running programs that describe path motion and its associated I/O. This is important not just for classic CNC machine tool applications, but for any application that uses CAD/CAM software for the automatic generation of these programs. Since RS-274 is a loose standard, with hundreds of dialects and thousands of machine-specific implementation issues, the key to Turbo PMACs strategy for these programs is that it treats the G, M, T, and D codes within the programs as special subroutine calls. The machine integrator writes these subroutines so as to implement the features of the specific dialect and machine. How these subroutines are generated can remain hidden from the person (or software package) that generates the part program, and from the machine operator, for whom the controller simply appears as a standard G-code machine. Here we give a few examples of how this feature can be used in Turbo PMAC. A Basic Example This first case implements a bare minimum of the most standard G and M-codes. For the G04 dwell, it uses a P argument, expressed in seconds. For controlling the cutting tool, it simply uses a discrete digital output. The path is the tool-center path, so no cutter-radius compensation is used. Setup and Definitions #def i ne Bi t sPassed Q100 ; Var f or checki ng passed ar gs #def i ne Par g Q116 ; Var f or P ar gument #def i ne Pval 32768 ; Val f or checki ng i f P passed #def i ne Cut t er On M1 ; Di scr et e cut t er out put Cut t er On- >Y: $078802, 8, 1 ; Machi ne Out put 1 &1 ; Addr ess CS 1 #1- >2000X #2- >2000Y #3- >2000Z Motion Program 1000 Contains the G-code Subroutines OPEN PROG 1000 CLEAR RAPI D RETURN ; G00: Rapi d mode ( N0 i s i mpl i ed) N1000 LI NEAR RETURN ; G01: Li near i nt er pol at i on mode N2000 CI RCLE1 RETURN ; G02: Cl ockwi se ci r cl e mode N3000 CI RCLE2 RETURN ; G03: Count er cl ockwi se ci r cl e mode N4000 READ( P) ; G04: Dwel l f or P seconds I F ( Bi t sPassed&PVal > 0) ; P par amet er speci f i ed? DWELL( PAr g*1000) ; Dwel l t i me i n mi l l i seconds ENDI F RETURN N17000 NORMAL K- 1 RETURN ; G17: Speci f y XY pl ane N18000 NORMAL J - 1 RETURN ; G18: Speci f y ZX pl ane N19000 NORMAL I - 1 RETURN ; G19: Speci f y YZ pl ane N90000 ABS RETURN ; G90: Absol ut e mode N91000 I NC RETURN ; G91: I ncr ement al mode CLOSE Motion Program 1001 Contains the M-code Subroutines OPEN PROG 1001 CLEAR N3000 Cut t er On=1 RETURN ; St ar t cut t i ng t ool N5000 Cut t er On=0 RETURN ; St op cut t i ng t ool N30000 DWELL0 RETURN ; End ( execut e any pendi ng out put s) CLOSE J an-2004 Application Note 2 G-Code Processing Example Sample Part Program that uses these Subroutines OPEN PROG 5 CLEAR G17 G90 ; XY pl ane, absol ut e move spec F500 ; Cut t i ng speed 500 mm/ mi n G00 X10. 00 Y5. 00 ; Rapi d move t o ( 10, 5) M03 ; St ar t spi ndl e G04 P2. 0 ; Wai t 2 seconds G01 Z0 ; Lower cut t er X30. 25 Y5. 00 ; Li near XY move G03 X35. 25 Y10. 00 J 5 ; CCWar c move G01 X35. 25 Y50. 10 ; Li near move G03 X30. 25 Y55. 10 I - 5 ; CCWar c move G01 X10. 00 Y55. 10 ; Li near move G03 X5. 00 Y50. 10 J - 5 ; CCWar c move G01 X5. 00 Y10. 00 ; Li near move G03 X10. 00 Y5. 00 I 5 ; CCWar c move G01 Z5 ; Cut t er up M05 ; St op cut t er G00 X0 Y0 ; Rapi d move back t o home M30 ; End of pr ogr am( not act ual l y needed) CLOSE A More Elaborate Example This next example provides several elaborations. First, it adds cutter-radius compensation with the G40, G41, and G42 codes. The radius is determined by the tool-select codes T01, T02, T03, and T04, implemented in program 1002. These T-codes also select a power level for each tool, to be used as an analog voltage output. Second, there are two feedrate-override sources, one for rapid moves, and one for cutting (linear and circle) moves. When the program switches between these modes, the time-base source switches. Here it uses two results from the encoder conversion table. This example does not specify the ultimate source of these values, which could be potentiometers or switches. Finally, it permits exact stop, modally and one-shot, disabling blending particularly useful for sharp corners. Setup and Definitions #def i ne Bi t sPassed Q100 ; Var f or checki ng passed ar gs #def i ne Par g Q116 ; Var f or P ar gument #def i ne Pval 32768 ; Val f or checki ng i f P passed #def i ne Cut t i ngMode Q130 ; Fl ag f or cut t i ng/ r api d #def i ne CS1Ti meBaseAdr I 5193 ; Sour ce of over r i de #def i ne CS1Ti meBaseSl ew I 5194 ; Over r i de sl ew r at e #def i ne MaxSl ew 8388607 ; Max sl ew r at e #def i ne Nor mSl ew 1644 ; Nor mal sl ew r at e #def i ne Cut Over r i de $3504 ; 4t h ent r y i n conver si on t abl e #def i ne Rapi dOver r i de $3505 ; 5t h ent r y i n conver si on t abl e #def i ne Cut t er On M1 ; Di scr et e cut t er out put #def i ne CS1I nPos M5187 ; I n- posi t i on st at us bi t #def i ne Laser Cont r ol M402 ; Anal og l aser cont r ol Cut t er On- >Y: $078802, 8, 1 ; Machi ne Out put 1 CS1I nPos- >Y: $00203F, 17, 1 ; CS1 i n- posi t i on st at us Laser Cont r ol - >Y: $07800A, 8, 16, S ; DAC4 out put ( PMAC1) Application Note J an-2004 G-Code Processing Example 3 Motion Program 1000 Contains the G-code Subroutines OPEN PROG 1000 CLEAR RAPI D ; G00: Rapi d mode ( N0 i s i mpl i ed) I F ( Cut t i ngMode=1) ; Have been i n G01, G02, G03? DWELL0 ; Make sur e cut t i ng moves f i ni sh CS1Ti meBaseSl ew=MaxSl ew ; For i nst ant change CS1Ti meBaseAdr =Rapi dOver r i de ; Sel ect over r i de sour ce DWELL0 ; Ensur e change occur s CS1Ti meBaseSl ew=Nor mSl ew ; Rest or e nor mal sl ew r at e ENDI F Cut t i ngMode=0 ; Set f l ag CS1Ti meBaseAdr =Rapi dOver r i de ; For f i r st t i me cal l ed RETURN N1000 LI NEAR ; G01: Li near i nt er pol at i on mode GOSUB 3500 RETURN ; N2000 CI RCLE1 ; G02: Cl ockwi se ci r cl e mode GOSUB 3500 RETURN N3000 CI RCLE2 ; G03: Count er cl ockwi se ci r cl e mode GOSUB 3500 RETURN ; N3500 ; Common subr out i ne f or G01, G02, G03 I F ( Cut t i ngMode=0) ; Have been i n G00? CS1Ti meBaseSl ew=MaxSl ew ; For i nst ant change CS1Ti meBaseAdr =Cut Over r i de ; Sel ect over r i de sour ce DWELL0 ; Ensur e change occur s CS1Ti meBaseSl ew=Nor mSl ew ; Rest or e nor mal sl ew r at e ENDI F Cut t i ngMode=1 ; Set f l ag CS1Ti meBaseAdr =Cut Over r i de ; For f i r st t i me cal l ed RETURN N4000 READ( P) ; G04: Dwel l f or P seconds I F ( Bi t sPassed&PVal >0) ; P par amet er speci f i ed? DWELL( PAr g*1000) ; Dwel l t i me i n mi l l i seconds ENDI F RETURN N9000 Exact St opOneShot =1 ; G09: Exact st op ( si ngl e shot ) Post pone=1 ; Don' t do bef or e next move PRELUDE1 G61. 2 RETURN N17000 NORMAL K- 1 RETURN ; G17: Speci f y XY pl ane N18000 NORMAL J - 1 RETURN ; G18: Speci f y ZX pl ane N19000 NORMAL I - 1 RETURN ; G19: Speci f y YZ pl ane N40000 CC0 RETURN ; G40: Cut t er comp of f N41000 CC1 RETURN ; G41: Cut t er comp l ef t N42000 CC2 RETURN ; G42: Cut t er comp r i ght N61000 Exact St opOneShot =0 ; G61: Exact - st op modal PRELUDE1 G61. 1 ; Set up f or each move RETURN ; N61100 ; Exact - st op subr out i ne I F ( Post pone=1) ; Need t o wai t f or next move? Post pone=0 ; So wi l l do next move ELSE DWELL 0 ; Di sabl e bl endi ng WHI LE ( CS1I nPos=0) WAI T ; Loop unt i l i n posi t i on I F ( Exact St opOneShot =1) ; Si ngl e shot PRELUDE0 ; So wi l l not do any mor e ENDI F ENDI F J an-2004 Application Note 4 G-Code Processing Example RETURN N64000 Exact St opOneShot =1 ; G64: Cancel exact st op RETURN ; Not e del ayed unt i l af t er move N90000 ABS RETURN ; G90: Absol ut e mode N91000 I NC RETURN ; G91: I ncr ement al mode RETURN CLOSE Motion Program 1001 contains the M-code Subroutines OPEN PROG 1001 CLEAR Motion Program 1000 contains the G-code Subroutines N3000 ; St ar t l aser Laser Cont r ol =Laser Power ; Set power l evel Cut t er On=1 ; Enabl e l aser RETURN N5000 ; St op l aser Cut t er On=0 ; Di sabl e l aser Laser Cont r ol =0 ; Cl ear power l evel RETURN N30000 DWELL0 RETURN ; End ( execut e any pendi ng out put s) CLOSE Motion Program 1002 contains the T-code (Tool-Select) Routines OPEN PROG 1002 CLEAR N1000 Tool Num=1 ; T1 Laser Power =5000 ; Set power l evel t o be used CCR0. 2 ; Set r adi us f or cut t er comp RETURN N2000 Tool Num=2 ; T2 Laser Power =10000 ; Set power l evel t o be used CCR0. 4 ; Set r adi us f or cut t er comp RETURN N3000 Tool Num=3 ; T3 Laser Power =15000 ; Set power l evel t o be used CCR0. 6 ; Set r adi us f or cut t er comp RETURN N4000 Tool Num=4 ; T4 Laser Power =20000 ; Set power l evel t o be used CCR0. 8 ; Set r adi us f or cut t er comp RETURN Sample Part Program that uses these Subroutines OPEN PROG 6 CLEAR G17 G90 ; XY pl ane, absol ut e move spec T03 ; Sel ect t ool 3 G00 Z5. 00 ; Rai se t ool axi s t o r api d hei ght X10. 00 Y2. 00 ; Rapi d move t o ( 10, 2) M03 ; St ar t spi ndl e G04 P2. 0 ; Wai t 2 seconds F500 ; Cut t i ng speed 500 mm/ mi n G01 Z0. 00 ; Lower cut t er G42 X10. 00 Y5. 00 ; Tur n on comp, l ead- i n move G61 X35. 25 Y5. 00 ; Li near XY move, exact - st op mode X35. 25 Y55. 10 ; Li near move G64 X10. 00 Y55. 10 ; Li near move, bl ended mode G03 X5. 00 Y50. 10 J - 5 ; CCWar c move Application Note J an-2004 G-Code Processing Example 5 G01 X5. 00 Y10. 00 ; Li near move G03 X10. 00 Y5. 00 I 5 ; CCWar c move G40 X10. 00 Y2. 00 ; Tur n of f comp, l ead- out move G01 Z5. 00 ; Cut t er up M05 ; St op cut t er G00 X0. 00 Y0. 00 ; Rapi d move back t o home M30 ; End of pr ogr am( not act ual l y needed) CLOSE