top of page
Search

# Special calculation programs

As you know, with custom macro B you have a computer programming language built right into your CNC control. And along with many CNC related features, custom macro B gives you the ability to do some pretty amazing things. Almost all of the applications we've shown for custom macro have been CNC-intensive. That is, custom macro commands are usually included in CNC programs that actually machine workpieces.

But what about using custom macro B for more computer-programming-like applications? Applications that may not be related (at least not directly) to CNC programs that machine workpieces. While I freely admit that you won't be able to bring the pizzazz of Virtual Basic to your CNC control, you may be surprised at how may good and workable applications you can come up with.

Start by studying your setup people and operators - and watch for times they use a calculator. With simple operations like addition and subtraction, and especially when the formulae they are applying are simple, maybe a custom macro won't help much. But when you spot a more complicated calculation - and when people don't know the related formulae - you have found a great application for custom macro B.

### Input and output

Any computer program requires input from the user. It takes the input, does the programmed calculations, and provides answers (output). Most computers, of course will print the output - right on the screen or to a printer.

Unfortunately, custom macro be cannot "print" output in a very friendly manner. And of course, you don't have a printer connected to your CNC machine tool's control (though keep in mind that you can "print" to any serial device through the communications port with DPRNT commands). So we must find another way to provide the output to the setup person or operator. I recommend using the Stop With Message command that will place a short message on the screen that tells the setup person or operator where to look for the answer. And I recommend that you place the answers in common variables (#100 series variables). Consider, for example, this simple application that converts an inch value to a metric value:

• O0001 (Calculations program);

• N1 (INCH TO METRIC);

• #101=1.5 (ENTER INCH VALUE);

• #100=#101 * 25.4 (Conversion command);

• #3006=100 (LOOK IN #100 TO FIND ANSWER);

• M30 (End of program);

Admittedly this application is pretty simple, but it nicely stresses how to specify input values and how to get output. To convert an inch value to a metric value, the user must specify the inch value (1.5 in our case). To do this, they must edit the third command in this program.

When a person runs this program, the metric equivalent will be placed in #100. I recommend using the same output location (#100) for every application so the user will always know where to look for the answer. The stop with message command (#3006 command) tells the user to look in #100 to find the answer.

Again this is a simple application. Even so, any time a person wants to convert from inch to metric, this program will keep them from having to look up the conversion factor (25.4).

### Multiple applications

When you think about it, you will probably come up with many times when you can apply this technique. But you won't want to create a separate program for every application. Doing so will be cumbersome - and the setup person or operator may spend as much time trying to find the appropriate program as they would looking up the needed formula.

I recommend keeping all of your calculation applications in one program, separating each application with a blank space and an M30. Consider this example:

• O0001 (Calculations program);

• (N1: INCH TO METRIC);

• (N2: METRIC TO INCH);

• (N3: DEGREES PER MINUTE FEEDRATE);

• ;

• N1 (INCH TO METRIC);

• #101=1.5 (ENTER INCH VALUE);

• #100=#101 * 25.4 (Conversion command);

• #3006=100 (LOOK IN #100 TO FIND ANSWER);

• M30 (End of program);

• ;

• N2 (METRIC TO INCH);

• #101=350.0 (ENTER METRIC VALUE);

• #100=#101 / 25.4 (Conversion command);

• #3006=100 (LOOK IN #100 TO FIND ANSWER);

• M30 (End of program);

• ;

• N3 (DETERMINE DEGREES- PER-MINUTE FEEDRATE);

• #101=10.0 (ENTER DESIRED IPM FEEDRATE);

• #102=90.0 (ENTER ANGULAR ROTATION);

• #103=5.0 (ENTER LENGTH OF CUT);

• #100=#102 / [#103/#101] (Conversion command);

• #3006=100 (LOOK IN #100 TO FIND ANSWER);

• M30 (End of program);

Notice that the program begins with a kind of table-of-contents. Make it as easy as possible for the person to find the needed calculation. In our example, there are only three different calculations being done and this kind of documentation may not be necessary. But for longer programs, this can really help. With our technique, a person can easily scan to the sequence number (N word) that begins each calculation.

Each separate calculation begins with a blank line (semi-colon by itself) and a sequence number. Then the input command/s. Then the calculation, storing the answer in #100. Then a stop-with-message command to specify where the answer can be found. Finally an M30 ends each calculation routine.