CalWest ManufacturingRobotics Fontana, CA

Call or text (818) 397-4809

FANUC background logic: what it runs and what it shouldn't

How background logic runs on an R-30iB or R-30iB Plus controller, what a background program may contain, how flags work, and the line between I/O housekeeping and the things that belong in the robot program or the safety system.

FANUC background logic runs a teach pendant program over and over, top to bottom, alongside whatever the robot is doing. It is the controller’s way to map signals, combine conditions and keep status bits current without a line in the main program. Used for that, it makes a cell easier to support. Used for motion or safety, it can’t do the job and shouldn’t be asked to.

In short

FANUC background logic is a TP program of assignment statements that the controller scans continuously, separate from the main program and unaffected by e-stops, holds or alarms. It is set up under MENU, SETUP, BG Logic, with up to eight programs in normal or high-level mode. It suits I/O mapping, status signals, edge detection and simple timers. Motion and safety functions don’t belong there.

This follows FANUC’s operator’s manual for R-30iB and R-30iB Plus controllers (Basic Function, B-83284EN). Software versions differ, so check your controller’s manual for its limits.

How FANUC background logic runs

A background program is an ordinary TP program, written in the editor and then entered on the BG Logic screen: MENU, 6 SETUP, F1 TYPE, BG Logic. Type its name in the PROGRAM column, choose a MODE and press F2 RUN. F3 STOP stops it. Up to eight programs can run this way.

Mode Scan Limit
Normal About 600 items per ITP (usually 8 ms). More items take proportionally longer: FANUC’s example is 1,600 items in 24 ms No set limit
High-level Every ITP, guaranteed 540 items across all high-level programs; more posts INTP-651

An item is a data item or an operator. Background execution takes about 1 ms of every ITP, and FANUC warns it can affect the cycle time of the main program. FANUC also says not to raise $MIX_LOGIC.$ITEM_COUNT, the number of items scanned per ITP, above its standard 600.

A few behaviors to know before you rely on it:

  • A program running in the background can’t be edited or run as a normal task. Stop it first.
  • A program of the same name can’t be loaded over it while it runs.
  • If power is cut while it runs, it starts again in the same mode at the next power-up.

What a background program may contain

FANUC limits background programs to assignment statements with a short list of extras: bracketed IF conditions, JMP LBL and LBL, RUN, SELECT and UALM. Anything else posts INTP-443 Invalid item for Mixed Logic when it runs.

Allowed in a background program
Data F[ ], M[ ] (not on the left side), DI/DO, RI/RO, SI/SO, UI/UO, WI/WO, GI/GO, AI/AO, R[ ], PR[i,j], AR[ ], constants, parameters, timers
Operators ( ), !, AND, OR, =, <>, the four comparisons, +, -, *, /, DIV, MOD
Rules Conditions need brackets: IF (DI[1]=ON),JMP LBL[1], not IF DI[1]=ON,JMP LBL[1]. A JMP can only go forward. No WAIT, no motion, no position data

Pulse works in the background too. IF (DI[1]),DO[1]=Pulse with no time gives a pulse one scan long, which makes a simple edge detector. A UALM posts its user alarm once, on the first scan the condition is true, and the background program keeps running.

Flags and markers

A flag, F[1] to F[1024], is an internal point that programs and the pendant can set and read, with no wiring behind it. Flags are shown under MENU, 5 I/O, F1 TYPE, Flag. They come back after a hot start, like outputs, and are cleared by a cold start, a controlled start, an INIT start, and a hot start after the I/O assignment or configuration has changed.

Flags can be assigned to DI, DO, UI, UO, GI and GO as rack 34, slot 1. FANUC attaches a warning to that: a flag assigned to UI lets a program or a pendant key drive UOP inputs, which means starting programs, so the system has to be designed around that with safety in mind. Our UOP signals guide covers what each UI does.

Markers, M[ ], hold the result of an expression assigned in a TP program, and the controller keeps recalculating them in the background until the expression is cleared with M[1]=(). They’re off as standard; $MIX_LOGIC.$USE_MKR turns them on, with eight markers by default.

A FANUC background logic example

 1:  F[1:PLC OK]=(DI[101:PLC CYCLE OK] AND !DI[102:PLC STOP REQ])
 2:  DO[110:ROBOT READY]=(UO[2:SYSRDY] AND UO[1:CMDENBL])
 3:  DO[111:BEACON]=(UO[6:FAULT] OR DI[121:LAMP TEST])
 4:  GO[1:ROBOT STEP]=(R[10:STEP NUM])
 5:  F[3:VAC RISE]=(DI[120:VAC OK] AND !F[2:VAC LAST])
 6:  F[2:VAC LAST]=(DI[120:VAC OK])
 7:  IF (DI[120:VAC OK]),R[30:VAC LOST]=(0)
 8:  IF (!DI[120:VAC OK]),R[30:VAC LOST]=(R[30:VAC LOST]+1)

Line 1 combines two PLC bits into one flag the main program can test. Lines 2 and 3 send robot status to the PLC and a beacon. Line 4 sends the main program’s step number as a group output, which shows up on the operator screen when something stops. Lines 5 and 6 catch the moment vacuum comes on. Lines 7 and 8 count scans without vacuum; at a known scan time that count is a timer, the approach FANUC’s Tech Transfer video on background timers takes because WAIT isn’t allowed.

Signal numbers and names are placeholders. The main program should be the only writer to anything it controls; two programs writing one output will fight.

What belongs in background logic, and what doesn’t

Good uses

  • Mapping and combining signals between the PLC and the robot program.
  • Status and step numbers to the PLC or HMI, through DO and GO.
  • Edge detection, counters and scan-count timers.
  • Lamps and beacons that should follow robot state even when it’s stopped.
  • RUN for a short program with no motion group, such as setting registers on a request from the PLC. Trigger it on an edge, as FANUC’s manual shows; RUN repeated on consecutive scans stops the background logic with INTP-651.

Not in background logic

  • Motion. There are no motion instructions, and RUN refuses a program with a motion group: INTP-651 and the background logic stops.
  • Safety. Background logic is ordinary software that keeps running through e-stops, holds and alarms. E-stops, gate interlocks and speed or zone limits belong in hard-wired safety circuits, a safety PLC or FANUC’s Dual Check Safety. Never use background logic to hold a UOP stop input on, restart a cell after a stop, or get around an interlock.
  • Anything that moves. A valve or clamp output written from background logic changes even while the robot is e-stopped. Keep those in the main program, where a stop stops them.
  • Signals shorter than a scan. Background logic can miss a pulse shorter than its scan time.

Mixed logic limits and backups

Background programs are written in mixed logic, which works in ordinary programs too. Each statement takes about 20 items at most. Position data and palletizing data can’t be used, only PR[i,j] elements. Pulse, On+ and Off- need ordinary instructions rather than mixed logic expressions, except a pulse in a bracketed IF as shown above.

Background programs save as TP files. The BG Logic screen settings are in MIXLOGIC.SV, and flag comments and flag assignments in DIOCFGSV.IO. Back up all three; our FANUC robot backup guide covers what a full backup contains. Background programs can also write registers and PR elements, which other programs may rely on; our position registers guide covers why shared registers need care.

Keep background logic short and commented, with each signal written by one program, and keep the cell sequence in the robot program and the PLC program. Our FANUC robot programming page covers how we write and support robot programs, including ones we didn’t build.

Common questions

Can FANUC background logic move the robot?
No. A background program may only contain assignment statements and a few control items, none of them motion. Its RUN instruction can start another program, but FANUC's manual says that program can't have a motion group; trying it posts INTP-651 and stops the background logic. Motion belongs in the main TP program, started through the robot's normal program selection.
Does background logic keep running during an e-stop?
Yes. FANUC's manual says background execution is not influenced by emergency stops, holds or alarms. That is useful for status and lamp logic, and it is exactly why background logic is no place for safety functions or for driving anything that moves. Outputs it writes keep changing while the robot is stopped.
Why do I get INTP-443 when I run a background program?
INTP-443 Invalid item for Mixed Logic means the program holds something background logic can't run: a WAIT, a motion line, a CALL or a jump back to an earlier label. Background programs take assignment statements, IF conditions in brackets, forward JMP LBL, LBL, RUN, SELECT and UALM. Rewrite the line in that form or move it to the main program.
What is the difference between a flag and a marker?
A flag, F[ ], is an internal on or off point that programs and the pendant can set and read, like a Boolean variable. A marker, M[ ], holds the result of an expression assigned to it in a TP program, and the controller keeps recalculating it in the background until the expression is cleared. Markers are off as standard and switched on with $MIX_LOGIC.$USE_MKR.
How fast does FANUC background logic scan?
In normal mode the controller scans about 600 items per ITP, usually 8 ms, so a short program scans every ITP and a long one takes proportionally longer. High-level mode runs every ITP but is limited to 540 items in total. The current normal mode scan time is shown at the top of the BG Logic screen.

Sources

  1. FANUC America: Robot support and manuals (R-30iB/R-30iB Plus Operator's Manual, Basic Function, B-83284EN: 4.19 Mixed Logic Instruction, 9.12 Background Logic; via the Customer Resource Center)
  2. FANUC Tech Transfer: Background Logic
  3. FANUC Tech Transfer: Background Logic Timers
  4. FANUC Tech Transfer: Advanced TPP Programming, Mixed Logic and Background Tasks

Start a project

Bring us the process. We'll bring the cell.

Send a phone video of the manual process, or a part drawing, by text or email. We come back with a cell concept and a plan: robot, tooling, controls and code.

Call or text
Call or text
(818) 397-4809
Email
sales@calwestmfg.com
Shop
13815 Arrow Rte, Fontana, CA 92335
Hours
Mon–Fri 7:00am – 3:45pm

FANUC Authorized System Integrator (ASI). Part of CalWest Manufacturing, founded 2012: AS9100D and ISO 9001 certified, ITAR registered.