Implement truth table
Logic and Bit Operations
The Combinatorial Logic block implements a standard truth table for modeling programmable logic arrays (PLAs), logic circuits, decision tables, and other Boolean expressions. You can use this block in conjunction with Memory blocks to implement finite-state machines or flip-flops.
You specify a matrix that defines all possible block outputs as the Truth table parameter. Each row of the matrix contains the output for a different combination of input elements. You must specify outputs for every combination of inputs. The number of columns is the number of block outputs.
The relationship between the number of inputs and the number of rows is:
number of rows = 2 ^ (number of inputs)
Simulink^{®} returns a row of the matrix by computing the row's
index from the input vector elements. Simulink computes the index
by building a binary number where input vector elements having zero
values are 0 and elements having nonzero values are 1, then adding
1 to the result. For an input vector, u
, of m
elements:
row index = 1 + u(m)*2
^{0} +
u(m-1)*2
^{1} + ... + u(1)*2
^{m-1}
This example builds a two-input AND function, which returns
1 when both input elements are 1, and 0 otherwise. To implement this
function, specify the Truth table parameter value
as [0; 0; 0; 1]
. The portion of the model that
provides the inputs to and the output from the Combinatorial Logic
block might look like this:
The following table indicates the combination of inputs that generate each output. The input signal labeled "Input 1" corresponds to the column in the table labeled Input 1. Similarly, the input signal "Input 2" corresponds to the column with the same name. The combination of these values determines the row of the Output column of the table that is passed as block output.
For example, if the input vector is [1 0]
,
the input references the third row:
(2^1*1 + 1)
The output value is 0.
Row | Input 1 | Input 2 | Output |
---|---|---|---|
1 | 0 | 0 | 0 |
2 | 0 | 1 | 0 |
3 | 1 | 0 | 0 |
4 | 1 | 1 | 1 |
This sample circuit has three inputs: the two bits (a and b) to be summed and a carry-in bit (c). It has two outputs: the carry-out bit (c') and the sum bit (s).
The truth table and corresponding outputs for each combination of input values for this circuit appear in the following table.
Inputs | Outputs | |||
---|---|---|---|---|
a | b | c | c' | s |
0 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 1 |
0 | 1 | 0 | 0 | 1 |
0 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 0 | 1 |
1 | 0 | 1 | 1 | 0 |
1 | 1 | 0 | 1 | 0 |
1 | 1 | 1 | 1 | 1 |
To implement this adder with the Combinatorial Logic block, you enter the 8-by-2 matrix formed by columns c' and s as the Truth table parameter.
You can also implement sequential circuits (that is, circuits with states) with the Combinatorial Logic block by including an additional input for the state of the block and feeding the output of the block back into this state input.
The type of signals accepted by a Combinatorial Logic block
depends on whether you selected the Boolean logic signals option (see Implement logic signals as Boolean data (vs. double)
).
If this option is enabled, the block accepts real signals of type Boolean
or double
.
The Truth table parameter can have Boolean values
(0 or 1) of any data type, including fixed-point data types. If the
table contains non-Boolean values, the data type of the table must
be double
.
The type of the output is the same as that of the input except
that the block outputs double
if the input is Boolean
and
the truth table contains non-Boolean values.
If Boolean compatibility mode is disabled, the Combinatorial
Logic block accepts only signals of type Boolean
.
The block outputs double
if the truth table contains
non-Boolean values of type double
. Otherwise, the
output is Boolean
.
For more information, see Data Types Supported by Simulink in the Simulink documentation.
Specify the matrix of outputs. Each column corresponds to an element of the output vector and each row corresponds to a row of the truth table.
Note:
This parameter is not visible in the block dialog box unless
it is explicitly set to a value other than |
The sldemo_clutchsldemo_clutch
model
shows how you can use the Combinatorial Logic block
with the Memory block to implement
a finite-state machine.
The finite-state machine appears in the Friction
Mode Logic/Lockup FSM
subsystem.
For more information, see the model descriptionmodel description.
The powerwindowpowerwindow
model
shows how you can use two Combinatorial Logic blocks
as inputs to a Stateflow^{®} chart to implement a finite-state machine.
For more information, see the model descriptionmodel description.
Direct Feedthrough | Yes |
Sample Time | Inherited from the driving block |
Scalar Expansion | No |
Dimensionalized | Yes, the output width is the number of columns of the Truth table parameter |
Zero-Crossing Detection | No |