Successfully reported this slideshow.

Macro Programming


Published on

Introduction to macros

Published in: Education, Technology, Business

Macro Programming

  1. 1. Macro’s ProgrammingInformation Module
  2. 2. Introduction to macro’s• What is the difference between macro and a macrostatement• How macro’s are used• Parameter• G and M codes• Settings• Variables• Write a basic macro’s program
  3. 3. Definition• A macro is a form of sub-program that includes non-G-code commands. It is typically a common operation thatwill be called many times.• Any program that performs a common function and will beexecuted repeatedly within a g-code program.
  4. 4. Macro statements• Any non-G-code command. Includes statements suchas: IF, WHILE, GOTO, math functions, and variables.
  5. 5. Macro Enable parameter bit• Parameter 57 bit 22. This parameter allows for the entryof macro statements.• The control needs an option code to activate thisparameter.
  6. 6. Parameter 57 bit 22• This parameter is used at the time of program entry notprogram execution.• If this parameter is turned off and a macro statement isentered, the control will ignore it.• If program is loaded from a file with the parameter off, themacro statements will be converted to comments.• If the statement is loaded manually in MDI or edit modes,the control will give an alarm when the parameter is off.
  7. 7. Why use macro’s ?• A G-code program is rigid in structure and can not bealtered in mid-operation. Offset are the only means toadjust the machine path from one run to the next.• Macros add flexible with the use of additional macrostatements.• With macros you can set up families of parts, createcustom canned cycles and drive optional devices.
  8. 8. Useful G and M codes• M01 Optional Program stop• M00 Program stop• M30 Program end and reset• G04 Dwell• G65 Pxx Macro sub program call• M97 Pxx Local sub program call• M98 Pxx Sub program call• G103 P1 Block look ahead limit• M109 Interactive user input
  9. 9. Settings that can affect macro progs• #23 9xxx PROGS EDIT LOCK• #74 9xxx PROGS TRACE• #75 9xxx PROGS SINGLE BLK
  10. 10. Variables• Local variablesLocal variables range between #1 and #33. See the operator’s manual formore details.• Global variablesGlobal variables occur in three ranges #100 - #199, #500 - #699 and#800 - #899. See the operator’s manual for more details.System variablesSystem variables give the programmer the ability to interact with controlconditions. Note that some of these variables are read only.See the operator’s manual for more details.
  11. 11. G103 P1• Limiting the block look ahead is very important when programmingwith macro’s• Adding a G103 P1 in the program with a minimum of 4 end-of-blockslike the example below will limit the look ahead.O9000;G103 P1;;;;;(Add a G103 at the end of the macro program)
  12. 12. Program Syntax• ParenthesesParentheses are used to enclose comments.• BracketsBrackets are used to control the order of execution of expressions within ag-code program and are used to enclose MACRO expressions.• Line NumbersLine numbers are a way of assigning a label to a block.Line numbers can be used with sub-routine calls. Nnn indicates the targetof a M99 Pnn, M97 Pnn, or GOTOnn statement.
  13. 13. Aliasing a macro to a G- or M-code• Aliasing is the act of assigning a name (G-code) to aspecific program. Macros are typically a subprogram, nota stand-alone program.• They are called via G65 or M98. This subprogram call canbe replaced with a single M- or G-code.• The assignment of this new code to a program takes placethrough parameters 81-100. Only programs O9000 toO9019 may be aliased.• When aliased to a G-code, variables may be passed.• With an M-code, variables may not be passed.
  14. 14. Parts counter macro exampleO00001G103 P1;;;;#800= xxx (NUMBER OF PARTS)N100IF [ #801 GE #800 ] GOTO200#801= #801 + 1(ADD MAIN PROGRAM)IF [ #801 LE #800 ] GOTO100N200#801= 0M30
  15. 15. Prepared by Haas AutomationTraining DepartmentOxnard, CA 93030