Lead/lag pump ladder logic from an L5X export
This example is an L5X program export, shaped the way Studio 5000® writes one: controller tags in context, program-scope setpoints, a main routine and an alarm routine it calls with JSR. It pumps a tank down with a lead pump and brings in a lag pump when the lead cannot keep up.

The program
// Routine Main // Lead pump starts on high level and seals in until the tank draws down. 0: XIC(PumpsEnabled)GEQ(TankLevel,StartLevel)OTL(LeadPump); // Stop on low level, or whenever the station is disabled. 1: [LEQ(TankLevel,StopLevel),XIO(PumpsEnabled)]OTU(LeadPump); // Lag pump assists once the lead pump cannot keep up. 2: XIC(LeadPump)GEQ(TankLevel,LagLevel)OTE(LagPump); // Accumulate lead-pump run time for maintenance. 3: XIC(LeadPump)RTO(RunHours,?,?); // Alarm handling lives in its own routine. 4: JSR(Alarms,0); // Routine Alarms 0: GRT(TankLevel,90)OTE(HighLevelAlarm); 1: XIO(PumpsEnabled)OTE(PumpsOffAlarm);
The rungs from the L5X export, routine by routine. Run it to see the full file import, tags and scopes included.
How it works
Rung 0 latches LeadPump on (OTL) when the station is enabled and TankLevel reaches StartLevel (60). Rung 1 unlatches it (OTU) when the level falls to StopLevel (20), or whenever PumpsEnabled goes off. Between those two levels the pump keeps whatever state it has, so it does not cycle on and off around one setpoint.
Rung 2 runs LagPump while the lead pump is on and the level is still at or above LagLevel (80). At that point the tank is filling faster than one pump can draw it down.
Rung 3 accumulates lead-pump run time in RunHours, a retentive timer (RTO). Unlike a TON it keeps its accumulated value when the pump stops, which is what you want for maintenance hours.
Rung 4 calls the Alarms routine with JSR. It raises HighLevelAlarm above 90 and PumpsOffAlarm whenever the station is disabled.
StartLevel, StopLevel, LagLevel and RunHours are program-scope tags, so they stay inside P_PumpStation; the levels, pumps and alarms are controller-scope. The import keeps that split, and the import report lists every rung that came across.
Try this
In the simulator, an input changes when you click it in the tag list: click once to turn it on and again to turn it off. To press a button, turn it on; to release it, turn it off; to pulse it, do both.
- Set TankLevel to 65: LeadPump latches on. Bring it down to 40 and it stays on.
- Raise TankLevel to 85: LagPump joins in. Drop to 70 and the lag pump stops while the lead keeps running.
- Turn PumpsEnabled off. LeadPump unlatches, PumpsOffAlarm comes on, and RunHours.ACC holds its value.
Tags
| TAG | ROLE |
|---|---|
| TankLevel | DINT, controller scope. The tank level. |
| PumpsEnabled | BOOL, controller scope. Station enable. |
| LeadPump, LagPump | BOOL outputs, controller scope. |
| StartLevel, StopLevel, LagLevel | DINT, program scope. 60, 20 and 80. |
| RunHours | TIMER (RTO), program scope. Lead-pump run time. |
| HighLevelAlarm, PumpsOffAlarm | BOOL, set by the Alarms routine. |
More examples
Conveyor with dwell
Ladder (NT)The belt runs, a 5-second timer gives it time to get up to speed, and only then does the ready lamp light. Watch the accumulator climb.
Tank level alarms
Structured TextLevel alarms with hysteresis, in Structured Text. Each alarm sets at one level and clears at another.
Read more about running L5X files without a PLC, or see all examples.