LIFO Unload LFU

At the right of a rung in a program's ladder routine. Not in a Logic Class. Place a LIFO Load first; it takes that load's control tag.

TagAfter two scans
LFL1LEN 8 POS 0 EN 1 DN 0 EM 1 FU 0 EU 1
LFL1_Data[0, 0, 0, 0, 0, 0, 0, 0]
LFU1_Dest0
LFU1_Execute1
LFU1_Reset0

How it works

Each time Execute turns on, writes the newest entry, the one just below POS, to Dest and takes 1 from POS. An empty stack is left as it is and Dest keeps its value.

Status bits

The Control tag holds the state. Read a bit with the tag name and a dot, such as Control.DN.

BitMeaning
.ENOn while the Execute of the load that owns this Control tag is on.
.EUOn while the Execute of this unload is on.
.EMEmpty: on while POS is 0.
.FUFull: on while POS equals LEN.
.DNDone: on while the queue is full, the same as FU.
.LENLength: how many entries it can hold. It cannot be more than the size of the array.
.POSPosition: how many entries are on the stack. An unload takes 1 from it.

Rules

  • A stack acts once when Execute turns on, not on every scan. If Execute is already on in the first scan, it acts once then.
  • A load into a full stack does nothing and raises no fault, so the value is lost.
  • An unload from an empty stack does nothing and leaves Dest as it was.
  • Reset sets POS to 0 and does not clear the array. The old values stay in the array until they are written over.
  • It takes the newest entry, the one just below POS.
  • It uses the stack and Control tag of the LIFO Load it is paired with.

Over time

A FIFO Load with Execute on for scans 2 and 3, off at scan 4, then on for scans 5 to 7. POS moves one step at scan 2 and one at scan 5, each time Execute turns on. Holding Execute on adds no steps.Scan12345678Execute.EN.POS011122222 Execute turns on: one step3 Held on: no step5 Turns on again: next step
ScanExecute.EN.POS
1OffOff0
2OnOn1
3OnOn1
4OffOff1
5OnOn2
6OnOn2
7OnOn2
8OffOff2

The chart shows a FIFO Load; the others act on Execute the same way. One step happens on the scan where Execute turns on. Holding Execute on does nothing more, so turn it off and on for the next step.

How it's used

Use LFU to take the newest part first. It works on the stack and control tag of its LFL.

1. Unload. The newest entry, 22, goes to Taken. POS is 1.

StepTakenStackPile.POSPile.EM
1. Unload22[11, 0]10
2. Turn Unload off22[11, 0]10
3. Unload again11[0, 0]01
4. Turn Unload off11[0, 0]01
5. Unload from empty11[0, 0]01

Taken went 0, 22, 11: the newest entry first. POS fell from 2 to 0. The third unload found the stack empty, so Taken stayed 11.

Operands

OperandWhat it is forData typeRead or write
ExecuteA BOOL that makes the instruction act once each time it turns on.BOOLReads
ResetA BOOL that, while on, clears the control tag and starts over.BOOLReads
ArrayThe array that holds the stack. Use the one the LIFO Load fills.Array of BOOL, DINT, REALReads and writes
ControlThe CONTROL tag that tracks the position, length and status.CONTROLReads and writes
DestThe tag that receives the newest entry.BOOL, DINT, REALWrites

Common mistakes

  • Placing it before any LIFO LoadPlace the LIFO Load first. The unload takes the control tag and stack of that load.
  • Rung already true on the first scanA rung that is already true on the first scan after a reset acts once, the same as any other scan where Execute turns on.

Related