LIFOPLCopen motion icon

FunctionClosedA function calculates a result according to the current value of its inputs. A function has no internal data and is not linked to declared instances. block - Manages a "last in / first out" stack

Inputs

PUSH BOOL Push a new value (on rising edgeClosedA rising edge is the transition of a digital signal from low to high. It is also called positive edge)
POP BOOL Pop a new value (on rising edge)
RST BOOL Reset the list
NEXTIN ANY Value to be pushed
NEXTOUT ANY Value at the top of the stack - updated after call!
BUFFER ANY Array for storing values

Outputs

EMPTY BOOL TRUE if the stack is empty
OFLO BOOL TRUE if overflow on a PUSH command
COUNT DINT Number of values in the stack
PREAD DINT Index in the buffer of the top of the stack
PWRITE DINT Index in the buffer of the next push position

Remarks

NEXTIN, NEXTOUT and BUFFER must have the same data type and cannot be STRING. The NEXTOUT argument specifies a variable which is filled with the value at the top of the stack after the block is called.

Values are stored in the "BUFFER" array. Data is never shifted or reset. Only read and write pointers and pushed values are updated. The maximum size of the stack is the dimension of the array.

The first time the block is called, it remembers on which array it should work. If you call later the same instance with another BUFFER input, the call is considered as invalid and makes nothing. Outputs reports an empty stack in this case.

In FFLD language, input rung is the PUSH input. The output rung is the EMPTY output.

ST Language

(* MyLIFO is a declared instance of LIFO function block *)
MyLIFO (PUSH, POP, RST, NEXTIN, NEXTOUT, BUFFER);
EMPTY := MyLIFO.EMPTY;
OFLO := MyLIFO.OFLO;
COUNT := MyLIFO.COUNT;
PREAD := MyLIFO.PREAD;
PWRITE := MyLIFO.PWRITE;

FBD Language

FFLD Language

IL Language

(* MyLIFO is a declared instance of LIFO function block *)
Op1: CAL MyLIFO (PUSH, POP, RST, NEXTIN, NEXTOUT, BUFFER)
FFLD  MyLIFO.EMPTY
STClosed"Structured text" A high-level language that is block structured and syntactically resembles Pascal  EMPTY
FFLD  MyLIFO.OFLO
ST  OFLO
FFLD  MyLIFO.COUNT
ST  COUNT
FFLD  MyLIFO.PREAD
ST  PREAD
FFLD  MyLIFO.PWRITE
ST  PWRITE

See also

FIFO