Stack - Store inputs into LIFO register - Simulink (original) (raw)

Store inputs into LIFO register

Libraries:
DSP System Toolbox / Signal Management / Buffers

Description

The Stack block stores a sequence of input samples in a last in, first out (LIFO) register. You set the register capacity in the Stack depth parameter. Inputs to the block can be scalars, vectors, or matrices.

The block pushes the input at the In port to the top of the stack when it receives a trigger event at the Push port. When it receives a trigger event at the Pop port, the block pops the top element off the stack and holds the Out port at that value. The last input that the block pushes on the stack is always the first to be popped off.

When you trigger two or more of the control input ports at the same time step, the block executes the operations in this order:

  1. Reset (Rst)
  2. Push
  3. Pop

Examples

expand all

This table shows how the Stack block operates for the following parameter values: Stack depth of4, Trigger type ofEither edge, and Clear output port on reset enabled. Because the block triggers on both rising and falling edges in this example, each transition from 1 to0 or 0 to 1 in the Push, Pop, and Rst columns represents a distinct trigger event. A value of1 in the Empty column indicates an empty buffer, while1 in the Full column indicates a full buffer.

In Push Pop Rst Stack Out Empty Full Num
1 0 0 0 0 1 0 0
2 1 0 0 0 0 0 1
3 0 0 0 0 0 0 2
4 1 0 0 0 0 0 3
5 0 0 0 0 0 1 4
6 0 1 0 5 0 0 3
7 0 0 0 4 0 0 2
8 0 1 0 3 0 0 1
9 0 0 0 2 1 0 0
10 1 0 0 2 0 0 1
11 0 0 0 2 0 0 2
12 1 0 1 0 0 0 1

Note that at the last step shown, the Push andRst ports are triggered simultaneously. TheRst trigger takes precedence, and the stack is first cleared and then pushed.

Ports

Input

expand all

Specify the input as a scalar, vector, or a matrix.

When the block receives a trigger event at thePush port, the block pushes the input at theIn port onto the top of the stack.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point
Complex Number Support: Yes

Specify a trigger event at this port to push the input at the In port to the top of the stack. The last input that the block pushes to the stack is always the first to be popped off.

Inputs to this port must have the same built-in data type as inputs to the Pop and Rst input ports

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Specify a trigger event at this port to pop the top element off the stack and to hold the Out port at that value. The last input that the block pushes to the stack is always the first to be popped off.

Inputs to this port must have the same built-in data type as inputs to the Push and Rst input ports

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Specify a trigger event at this port to empty the stack contents. When you select Clear output port on reset, then a trigger event at the Rst port empties the stack and sets the value at the Out port to zero. This setting also applies when a disabled subsystem containing theStack block is reenabled. In this case, when you select Clear output port on reset, theOut port value is only reset to zero.

Inputs to this port must have the same built-in data type as inputs to the Push and Pop input ports.

Dependencies

To enable this port, select Show reset port (Rst) to clear internal stack buffer.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

Output

expand all

Stack output, returned as a scalar, vector, or a matrix. When you specify a trigger event at the Pop port, the block pops the top element off the stack and holds the Out port at that value. The last input that the block pushes to the stack is always the first to be popped off.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean | fixed point
Complex Number Support: Yes

The Empty port outputs a high (1) when the stack is empty and low (0) otherwise.

Dependencies

To enable this port, select Show empty stack indicator port (Empty).

Data Types: Boolean

The Full port outputs a high (1) when the stack is full and low (0) otherwise. The Full port remains low when you select Dynamic reallocation in thePush full stack parameter.

Dependencies

To enable this port, select Show full stack indicator port (Full).

Data Types: Boolean

The Num port outputs the number of stack entries through this port. This value indicates the number of entries currently on the stack. The block outputs a double-precision floating-point value at this port when the input at the In port is of the double-precision floating-point data type. The block outputs a 32-bit unsigned integer value at this port when the input at the In port is not a double-precision floating-point value.

Dependencies

To enable this port, select Show number of stack entries port (Num).

Data Types: double | uint32

Parameters

expand all

Specify the number of entries that the LIFO register can hold as a positive integer.

Specify the type of event that triggers the block execution. The rate of the trigger signal must be the same as the rate of the data signal input.

Specify the triggering event for the Push, Pop, and Rst ports as one of these options:

Use this parameter to specify how the block responds to the trigger at thePush port when the register is full.

Note

The Push full stack parameter is a diagnostic parameter. Like all diagnostic parameters on the Configuration Parameters dialog box, this parameter is set toIgnore in the code generated for this block by the Simulink Coder™ code generation software.

Use this parameter to specify how the block responds to the trigger at thePop port when the register is empty.

Note

The Pop empty stack parameter is a diagnostic parameter. Like all diagnostic parameters on the Configuration Parameters dialog box, this parameter is set toIgnore in the code generated for this block by the Simulink Coder code generation software.

Enable the Empty output port, which is high (1) when the stack is empty, and low (0) otherwise.

Enable the Full output port, which is high (1) when the stack is full, and low (0) otherwise. The Full port remains low when you select Dynamic reallocation in the Push full stack parameter.

Enable the Num output port, which tracks the number of entries currently on the stack. When inputs to theIn port are double-precision values, the outputs from the Num port are also double-precision values. Otherwise, the outputs from the Num port are 32-bit unsigned integer values.

Enable the Rst input port to empty the stack when the block receives the trigger specified in the Trigger type parameter.

Reset the Out port to 0 (in addition to clearing the stack) when the block receives a trigger at the Rst input port.

Block Characteristics

Data Types Boolean | double fixed point integer single
Direct Feedthrough no
Multidimensional Signals no
Variable-Size Signals no
Zero-Crossing Detection no

Extended Capabilities

expand all

The following limitations apply:

Version History

Introduced before R2006a