Learn to write a macro that checks for missing or unreasonable data and generates an alarm.

Once your macro subprogram is working correctly you should take some time to error proof the code. The G65 line which calls the macro is shown below;

G65 P0083 X0 Z-1.1 R0.1 Q0.15 F0.012.

G65 tells the controller that a macro subprogram is being called, and that program specific information will be assigned. The P0083 states the subprogram number.

The X0 will assign a value of 0 to local variable #24, Z-1.1 will assign a value of -1.1 to local variable #26, R0.1 will assign a value of 0.1 to local variable #18, Q0.15 will assign a value of 0.15 to local variable #17 and F0.012 will assign a value of 0.012 to local variable #9.

If any of the X0 Z-1.1 R0.1 Q0.15 F0.012 are omitted in the main program G65 line, then the macro will not have all the information it requires to run and the M99 codes removes all data stored in the local variables so that information from a previous macro cannot cause a crash.

As a competent macro programmer, you should add code to check for missing or unreasonable information and if the information is missing or unreasonable generate an alarm letting the operator know what is required to fix the problem.

# Error Proofing for Missing Values in G65

There should be a unique alarm if any of the five values required are missing or contain unreasonable data. These alarms will be the first code the subprogram executes.

The error checking must look for two separate issues: if the variable has not been assigned or is empty and if the variable has unreasonable data.

For local variable #24, the X-position of the tool, the program must check to see if there is a reasonable value assigned or if the variable is empty (an empty variable is also known as a “Null” variable).

The second check is to see if a value other than zero has been stored. The X-position must be zero to drill on the center of the part. To error proof for a missing value add the following code:

IF [#24 EQ #0] THEN #3000 = 0 (X IS MISSING FROM THE G65).

An alarm message may not exceed 26 characters in length (spaces count as characters). The alarm above is twenty five characters and will check to see if local variable #24 is empty. The second alarm, as shown below, will verify that X0 is programmed:

IF [#24 NE 0] THEN #3000 = 1 (X IS NOT ZERO).

The second alarm does check for both conditions, but if the X is missing the operator may not realize that this is the true problem.

If your machine has crashed, it may require that the drill be slightly off center and not at X0. For this scenario change the alarm to the following:

IF [#24 GT A] THEN #3000 = 1 (X IS INCORRECT).

A is the value needed for your machine to drill on center.

Keep in mind that on many controllers there is a limit of two hundred alarms, numbered sequentially from 0 through to 199.

The series #3000 alarms are considered hard alarms because all machine movement ceases when these alarms are generated. There are also soft alarms which do not stop the machine movement and they will be addressed shortly.

The remaining alarms to check if none of the required values are empty would be as shown below:

IF [#26 EQ #0] THEN #3000 = 2 (Z IS MISSING FROM THE G65)

IF [#18 EQ #0] THEN #3000 = 3 (R IS MISSING FROM THE G65)

IF [#17 EQ #0] THEN #3000 = 4 (Q IS MISSING FROM THE G65)

IF [#9 EQ #0] THEN #3000 = 5 (F IS MISSING FROM THE G65)

# Error Proofing Against Unreasonable Values in G65

The next error proofing consideration is for values that are not reasonable, such as a positive Z value being programmed as the drilling depth.

This time we’ll use a different style of alarm generation.

Again, to generate the alarm an IF statement will be added at the beginning of the macro program. Since this macro has the part zero on the front, the Z depth must be negative for a hole to be produced. To check for a non-negative Z drilling depth the following code could be added:

IF [#26 GE 0] GOTO 100.

For this style of alarm generation, the actual alarm will be on line N100, this line will be added after the N14 M99 line and would be as follows:

N14 M99

N100 #3000 = 6 (YOUR Z MUST BE NEGATIVE).

Placing the alarms after the M99 code is a common practice and should only be used for the hard #3000 series alarms which stop all machine functioning.

This alarm method is not better or worse than the previous method, it is just different and each programmer will develop their own style. Keep in mind there are numerous ways to reach the end goal as long as we get there.

It is also useful to have many tools in your tool belt, because one day one of these methods may not work but the other one will.

Currently, the macro contains all of the alarms for situations where it would be dangerous to let the drill run because of missing information.

What if information placed on the G65 line is questionable?

In such cases we may or may not want the machine to run the programmed code, but we do want the operator to verify the data as programmed is correct. This style of error proofing uses “soft” alarms.

Soft alarms will generate an alarm warning the operator of a potentially unsafe condition and allow them to choose if the program can continue to be executed or should be stopped.

Below is a summary of the entire macro thus far, using the While [ ] Do logic.

O0083

IF [#24 EQ #0] THEN #3000 = 0 (X IS MISSING FROM THE G65)

IF [#24 NE 0] THEN #3000 = 1 (X IS NOT ZERO)

IF [#26 EQ #0] THEN #3000 = 2 (Z IS MISSING FROM THE G65)

IF [#18 EQ #0] THEN #3000 = 3 (R IS MISSING FROM THE G65)

IF [#17 EQ #0] THEN #3000 = 4 (Q IS MISSING FROM THE G65)

IF [#9 EQ #0] THEN #3000 = 5 (F IS MISSING FROM THE G65)

IF [#26 GE 0] GOTO 100

N1 (PECK DRILLING FULL RETRACT TO R)

N2 #100 = ABS[#26-#18] (TOTAL INCREMENTAL DISTANCE)

N3 #101 = #18 – #17 (FIRST PECK POSITION)

N4 #100 = #100 – #17

N5 WHILE [#100 GT 0] DO1

N6 G01 Z#101 F#09

N7 G00 Z#18

N8 Z = #101 + 0.03

N9 #101 = #101 – #17

N10 #100 = #100 – #17

N11 END1

N12 G01 Z#26 F#09

N13 G00 Z#18

N14 M99

N100 #3000 = 6 (YOUR Z MUST BE NEGATIVE)

Since this macro program has been designed to work in any material using any acceptable speeds and feeds, the error proofing can be difficult. The cutting conditions may be reasonable for some materials and unreasonable for others.

Due to the possibility of questionable data we want to program an alarm that will ask the operator to verify the programmed information is correct when it seems unreasonable.

When we have the program ask the operator for data verification we do not want to use the hard alarms, #3000 series, because they stop all machine operations. Instead we require an alarm code which will generate an alarm which may or may not be ignored by the operator.

These alarms are the #3006 series alarms.lity or questionable data we want to program an alarm that will ask the operator to verify the programmed informat

# Programming G65 #3006 Alarms

The R0.1 Q0.15 F0.012 values should be error checked for unreasonable data using a #3006 series alarm.

The R value must be a positive number, to check for this condition the following code would be required:

IF [#18 LE 0] GOTO 110.

Again line 110 will be located after the N14 M99 and will be as follows:

N110 #3000 = 7 (YOUR R MUST BE POSITIVE).

The order the error codes are placed after the M99 does not matter and the numbers need not be sequential.

When the error condition is true the machine will search down through the program until it finds the first instance of the line number, the M99 will not be executed because it is searching for the line number. Once it finds the line number that line of code will be executed.

If the R value is too far away from the end of the part, the macro will drill the hole but waste a great deal of time machining air in front of the part. This is usually a decimal place error in the code.

However, it is always possible that this is what the user intended, so a soft alarm is again required. This soft alarm could be programmed as follows:

IF [#18 GT 0.15] THEN #3006 = 8 (IS THE VALUE FOR R CORRECT)

In this case, an R value greater than 0.15 is considered unreasonable and allowing the program to run with a larger value is a waste of time and money. Therefore, it is only acceptable when you are annoyed with the boss.

Similar lines of code should be added to check for unreasonable or unexpected values for Q and F. In the case of the Q value, we should check for a negative value or too large of a pecking amount for the drill size and matwing the program to run with a larger value is a wasteerial.

This error proofing line will include the “OR” condition. With an OR statement one **or** the other condition must be true for the IF logic to be executed. If a negative pecking value or a value larger than 0.5 is unacceptable for the part then the alarm code would be:

IF [#18 LE 0] OR [#18 GT 0.5] THEN #3006 = 8 (IS THE VALUE FOR R CORRECT)

The F – feed rate value should also be checked for a negative or unreasonable number. If we assume that a feed rate greater than 0.025 inches per revolution would be unreasonable, then the alarm would be:

IF [#9 GT 0.025] OR [#9 LT 0] THEN #3006 = 10 (IS YOUR FEED CORRECT)

The final program with the error proofing will be as follows (it does not matter that some lines do not have line numbers and some do, or that the line numbers are not sequential):

O0083

IF [#24 EQ #0] THEN #3000 = 0 (X IS MISSING FROM THE G65)

IF [#24 NE 0] THEN #3000 = 1 (X IS NOT ZERO)

IF [#26 EQ #0] THEN #3000 = 2 (Z IS MISSING FROM THE G65)

IF [#18 EQ #0] THEN #3000 = 3 (R IS MISSING FROM THE G65)

IF [#17 EQ #0] THEN #3000 = 4 (Q IS MISSING FROM THE G65)

IF [#9 EQ #0] THEN #3000 = 5 (F IS MISSING FROM THE G65)

IF [#26 GE 0] GOTO 100

IF [#18 LE 0] GOTO 110

IF [#18 LE 0] OR [#18 GT 0.5] THEN #3006 = 8 (IS THE VALUE FOR R CORRECT)

IF [#9 EQ 0] THEN #3000 = 9 (YOUR FEED IS ZERO)

IF [#9 GT 0.025] OR [#9 LT 0] THEN #3006 = 10 (IS YOUR FEED CORRECT

N1 (PECK DRILLING RETRACT TO R)

N2 #100=ABS[#26 – #18] (TOTAL INCREMENTAL DISTANCE)

N3 #101 = #18 – #17 (FIRST PECK POSITION)

N4 #100 = #100 – #17

N5 WHILE [#100 GT 0] DO1

N6 G01 Z#101 F#09

N7 G00 Z#18

N8 Z = #101 + 0.03

N9 #101 = #101 – #17

N10 #100 = #100 – #17

N11** **END1

N12 G01 Z#26 F#09

N13 G00 Z#18

N14 M99

N110 #3000 = 7 (YOUR R MUST BE POSITIVE)

N100 #3000 = 6 (YOUR Z MUST BE NEGATIVE)

**About the Author**

*Fred Fulkerson is a graduate of the Faculty of Education, University of Western Ontario, and of the general machining program at Conestoga College in Ontario. He is a Canadian Red Seal certified general machinist and CNC programmer and a certified Mastercam and SOLIDWORKS instructor. *