The same motor logic, 40 times
Open an older program and you'll often find the same start/stop/fault rungs copied for every motor. Over the years someone changed a timer on one, added a permissive on another, and now nobody knows which copy is right. Fixing a bug means fixing it 40 times and hoping you didn't miss one.
An Add-On Instruction (AOI) fixes that. You write the logic once, give it inputs and outputs, and use it like a built-in instruction. Every motor gets its own copy of the data (its own tag), and they all share one copy of the logic.1
Design it before you build it
- Keep the interface small. Commands in, feedback in, outputs and status out. If an AOI needs 30 parameters, it's probably two AOIs.
- No direct I/O inside. Pass the I/O in as parameters. Then the same AOI works on any rack, and you can test it with simulated inputs.
- Settings as parameters with defaults. The feedback timeout here is
FbkTime_ms, default 5 seconds, so one motor that's slow to prove can be changed without editing the AOI. - Plan for versions. Put a revision and change notes in the AOI's description. Changing a definition changes every motor that uses it, so treat it like a change to every one of them.
Not a safety function
This is a standard motor control AOI. E-stops, guard interlocks and other safety functions belong in a safety-rated system (hardwired safety relays, or a safety controller's safety task with safety AOIs, which have their own rules14). Cmd_Stop here is a normal stop, not an E-stop.
A basic motor AOI
Start/stop with seal-in, a permissive, and a fail-to-start fault if the run feedback (the starter's auxiliary contact or the drive's running bit) doesn't come on in time. A made-up example; add what your plant standard needs.
Ladder
Rungs 0 to 4 are the AOI's own logic routine (FbkTmr is a local TIMER). Rungs 5 and 6 show it in use, in a normal routine of your program (numbered on here so they can be told apart). Inside the AOI, tag names are the AOI's own parameters and local tags.
Drawn the way the Studio 5000 ladder editor lays it out: inputs on the left, outputs pushed to the right rail. The small numbers with arrows are where the editor shows live values; they read 0 here because nothing is online.
On a phone, swipe sideways to see the whole rung.
Rung 0 as text
[XIC(Cmd_Start),XIC(Out_Run)]XIC(Permissive)XIO(Cmd_Stop)XIO(Faulted)OTE(Out_Run);Rung 1 as text
MOV(FbkTime_ms,FbkTmr.PRE);Rung 2 as text
XIC(Out_Run)XIO(RunFbk)TON(FbkTmr,5000,0);Rung 3 as text
XIC(FbkTmr.DN)OTL(Faulted);Rung 4 as text
XIC(Cmd_Reset)XIO(Out_Run)OTU(Faulted);Rung 5 as text
Motor_Basic(Conv1_Mtr,Conv1_StartPB,Conv1_StopPB,Conv1_Permit,Conv1_AuxCt,Conv1_Run,Conv1_Fault);Rung 6 as text
XIC(Conv1_Run)OTE(Conv1_StarterDO);All 7 rungs as text
[XIC(Cmd_Start),XIC(Out_Run)]XIC(Permissive)XIO(Cmd_Stop)XIO(Faulted)OTE(Out_Run);
MOV(FbkTime_ms,FbkTmr.PRE);
XIC(Out_Run)XIO(RunFbk)TON(FbkTmr,5000,0);
XIC(FbkTmr.DN)OTL(Faulted);
XIC(Cmd_Reset)XIO(Out_Run)OTU(Faulted);
Motor_Basic(Conv1_Mtr,Conv1_StartPB,Conv1_StopPB,Conv1_Permit,Conv1_AuxCt,Conv1_Run,Conv1_Fault);
XIC(Conv1_Run)OTE(Conv1_StarterDO);Structured Text
Below is the same motor AOI idea with its logic routine written in structured text instead of ladder. An AOI definition uses one language for its logic (ladder, function block, or structured text)1; pick one when you create it. TONR is the structured-text on-delay timer and needs an FBD_TIMER local tag; the ladder version above uses TON with a TIMER local.2 Rockwell restricts AOI local-tag types (no MSG, alarms, or motion types); TIMER and FBD_TIMER are ordinary structures and are commonly used as locals.1
// Logic routine of AOI Motor_Basic, written in structured text.
// Inputs: Cmd_Start, Cmd_Stop, Cmd_Reset, Permissive, RunFbk (BOOL)
// FbkTime_ms (DINT, default 5000)
// Outputs: Out_Run, Faulted (BOOL)
// Local: FbkTmr (FBD_TIMER here; the ladder version uses TIMER)
Out_Run := (Cmd_Start OR Out_Run) AND Permissive
AND NOT Cmd_Stop AND NOT Faulted;
FbkTmr.PRE := FbkTime_ms;
FbkTmr.TimerEnable := Out_Run AND NOT RunFbk;
TONR(FbkTmr);
IF FbkTmr.DN THEN
Faulted := 1;
END_IF;
IF Cmd_Reset AND NOT Out_Run THEN
Faulted := 0;
END_IF;
And calling one instance:
// Calling it from a structured text routine.
// Conv1_Mtr is a tag of type Motor_Basic. The instance tag goes
// first, then an argument for each Required parameter, in the
// order they are defined: Cmd_Start, Cmd_Stop, Permissive, RunFbk,
// Out_Run, Faulted. Cmd_Reset is not Required: set the member.
Conv1_Mtr.Cmd_Reset := Conv1_ResetPB;
Motor_Basic(Conv1_Mtr, Conv1_StartPB, Conv1_StopPB, Conv1_Permit,
Conv1_AuxCt, Conv1_Run, Conv1_Fault);
Conv1_StarterDO := Conv1_Run;
In this example the six parameters shown on the ladder box are marked Required and Visible, so both the ladder box and the structured text call take an argument for each, after the instance tag.3 Cmd_Reset, FbkTime_ms are optional and set through the tag's members (for example from the HMI). TONR is non-retentive: its time clears whenever TimerEnable goes false, like the ladder TON.2
Educational example. This code has not been compiled, downloaded, or tested on a controller. It is not production-ready or drop-in code. Treat it as a starting point to review, adapt, and test on your own system. It is standard control logic, not safety logic.
Keeping AOIs maintainable
- Test the AOI by itself first, with every input forced through its states, before it goes into dozens of places.
- Plan definition changes. A change to the AOI definition changes every instance at once, so schedule it like a change to every motor that uses it, with a test plan.
- Vendor AOIs (for drives, servo amplifiers, scales) save time, but read their documentation and note their revision in your project. Treat them like any other code you didn't write.
- Show the same status on the HMI for every instance. One faceplate or template per AOI type keeps screens consistent; in Ignition, a UDT and a template view per AOI type works well.
Sources
- Rockwell Automation, Logix 5000 Controllers Add-On Instructions Programming Manual, publication 1756-PM010 (parameters, local tags, languages, scan modes, safety Add-On Instructions): PDF.
- Rockwell Automation, Studio 5000 Logix Designer online help, "Timer On Delay with Reset (TONR)": rockwellautomation.com.
- Rockwell Automation, Studio 5000 Logix Designer online help, "Using an Add-On Instruction" and "Add-On Instruction Scan Modes": using, scan modes.
- Rockwell Automation, GuardLogix 5580 / Compact GuardLogix 5580 safety reference manual, "Safety Add-On Instructions": rockwellautomation.com.
Instruction details were checked against the vendor documentation linked above. Behavior can change between software and firmware versions, so check the help for the version you run.