top of page
Writer's pictureMike Lynch

A Custom Macro math question

I can perform a square-root operation such as #100=SQRT[9] which of course sets the #100 to 3. However I can't for the life of me figure out how to do powers such as 3^2=9(squared) or 3^3=27(cubed). I've read thru Mazak, Hass, and Fanuc manuals but nothing is shown. How can you do this? Thanks. Chris


Response:

While custom macro B has some pretty helpful arithmetic functions, it doesn't have them all. For any arithmetic function you don't currently have, you can write your own as long as you know the logic behind the function. As you said, to square a number, you simply multiply the number by itself. The square of 4 is simply 4 * 4. Represented in custom macro as:

#101=4*4

If you come across a function that you need on a regular basis, it can be quite cumbersome to keep including the command/s in your program. Instead, you can write a separate program to perform just the arithmetic function in question. Consider, for example, taking a number to a given power. Here is a calling command in the main program that uses the function custom macro.


  • G65 P8000 B3.0 E4.0 R120.0


  • B - Base value to be raised

  • E - Value (power) to which base must be raised

  • R - return variable number (this will be the common variable available to you in the main program after this command is given) In our case #120 will have been set to 81.0 (3*3*3*3).


Here is the custom macro:

  • O8000

  • #100=1 (loop counter)

  • #[#18]=#2 (initialize #120 to B)

  • N1 If [#100 GT #8] GOTO 99 (if counter is greater than E, exit)

  • #[#18]=#[#18] * #2 (multiply #120 times B)

  • #100=#100 + 1 (step counter)

  • GOTO 1 (go back to test)

  • N99 M99 (end of custom macro)

Again, once this custom macro has been executed, the value of #120 (specified by R in the calling command) will be the function's answer and available to you back in the calling program after the G65 command.

463 views0 comments

Recent Posts

See All

Comments


bottom of page