
On the shop floor, human error is one of the leading causes of crashes, broken tools, and scrapped parts. A wrong tool number, an improper spindle speed, or starting a program from the wrong state — any of these can turn into an expensive mistake in seconds.
Fanuc Macro B is not just for complex math. One of its most useful jobs is building fail-safe checks directly into your program. With variables and simple logic, you can have the machine check itself before it runs a critical move. This article walks through the core logic of Macro B and shows you how to write practical fail-safe commands on a Focus CNC machine.
Understanding Variables: Why the Variable Number Matters
In Macro B, a variable works like a drawer that holds a value temporarily. But drawers with different numbers behave differently, and picking the wrong one can break your safety logic.
1. Common Variables #100 to #199 (Volatile)
- Behavior: These values clear to null when you press the machine's [RESET] key or turn off the power.
- When to use them: Temporary calculations inside a program, or logic checks that only need to hold true for a single machining cycle.
2. Common Variables #500 to #999 (Non-Volatile)
- Behavior: These values stay in memory permanently, even after you turn off the machine, until someone changes them manually or a program overwrites them.
- When to use them: Storing safety limits — for example, a customer-defined maximum spindle speed, or a production target.
3. System Variables
- Behavior: These are fixed variable numbers reserved by the Fanuc control. They give you a live read on machine status, such as the current tool number, axis position, or the clock.
Practical Fail-Safe Program Examples
Here are a few fail-safe subprograms that catch common shop-floor mistakes. Keep in mind that variables tied to hardware signals, such as chuck pressure, usually need to be matched to the machine's PMC address.
Example 1: Tool Number Check (Using Modal System Variable #4120)
This stops an operator from running a program under the wrong tool number.
O9001 (TOOL NUMBER CHECK)
#1 = #4120 (Read the current T-code value from the system)
IF [#1 NE 0101] GOTO 10 ( If the current tool is not T0101, jump to N10)
GOTO 20 (If correct, jump to the end)
N10 #3000=1 (WRONG TOOL - PLEASE CHECK) (Trigger alarm 1 and show the message)
N20 M99
Example 2: Maximum Spindle Speed Check (Using Long-Term Variable #500)
This stops a programming mistake from setting the spindle speed too high, which can throw a workpiece or shatter an insert.
O9002 (SPINDLE SPEED CHECK)
#500 = 2500 (Set the maximum safe spindle speed for this part to 2500 RPM on the variable page)
#2 = #4119 (Read the current S-code value from the system)
IF [#2 GT #500] THEN #3000=2 (SPEED TOO HIGH) (Trigger an alarm if speed exceeds 2500)
M99
Example 3: Hardware Signal Check (Chuck Clamping Concept)
Note: Hardware interface variables are usually mapped starting at #1000 and above. The exact address depends on how your Focus CNC machine is configured at the factory (PMC mapping).
O9003 (CHUCK STATE CHECK)
IF [#1000 EQ 0] THEN #3000=3 (CHUCK UNCLAMPED) (Trigger an alarm if the chuck-clamped signal reads 0)
M99
Practical Tips for Writing Fail-Safe Programs
1. Use Long-Term Variables for Safety Limits
Store each machine's safety boundaries — axis travel limits, maximum spindle speed, and so on — in variables #500 and above. This means, every program on the machine shares the same safety standard.
2. Put the Checks at the Top of the Program
Every fail-safe check should run before any G-code motion in the main program, so the machine catches the problem before anything moves.
3. Test with Single Block on the First Run
The first time you run a program with macro logic in it, always turn on Single Block. Check the variable page yourself to confirm the values are changing the way you expect.
4. Keep Your Alarm Messages Clear
Write plain, simple wording in the message that follows #3000, so any operator on the floor can understand it right away.
With just a few lines of macro logic, you can move safety from something that depends on a person remembering to check, to something the system checks automatically every time — keeping your Focus CNC machine running steady and professional.
Building Safer CNC Programs with Macro B
Macro B gives programmers a practical way to build an additional layer of checking into everyday CNC operations. By using variables to verify tool numbers, spindle speed limits, and machine conditions before critical commands are executed, common setup or programming errors can be identified before they lead to a problem.
The exact variables and hardware signals available will depend on the Fanuc control and machine configuration. When applying Macro B to a Focus CNC machine, always verify the relevant system variables, PMC mappings, and safety conditions for the specific machine before putting the program into production.