Combinatorial Logic
Implement truth table
Libraries:
Simulink /
Logic and Bit Operations
Description
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.
Examples
Two-Input AND Logic
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
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.
Circuit Logic
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.
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.
Extended Examples
Building a Clutch Lock-Up Model
Use Simulink® to model and simulate a rotating clutch system. Although modeling a clutch system is difficult because of topological changes in the system dynamics during lockup, this example shows how enabled subsystem can easily handle such problems. We illustrate how to employ important Simulink modeling concepts in the creation of the clutch simulation. Designers can apply these concepts to many models with strong discontinuities and constraints that may change dynamically.
Ports
Input
Port_1 — Input signal
vector
Input signal, specified as a vector. 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
.
Data Types: double
| Boolean
Output
Port_2 — Output signal
scalar | vector
Output signal, double
if the truth table contains
non-Boolean values of type double
;
Boolean
otherwise. 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.
Data Types: double
| Boolean
Parameters
Truth table — Matrix of outputs
matrix
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 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 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
Programmatic Use
Block Parameter:
TruthTable |
Type: character vector |
Values: matrix |
Default: '[0 0;0 1;0
1;1 0;0 1;1 0;1 0;1 1]' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
More About
Model Coverage
If you have a Simulink Coverage™ license, the Combinatorial Logic block receives decision and condition coverage. Decision coverage measures the number of time steps that the block outputs each row of the truth table.
If the block passes each row of the truth table as the output for at least one time step, decision coverage is 100%. Otherwise, decision coverage is the number of truth table values output during at least one time step, divided by the total number of truth table values. Because the Combinatorial Logic block always has at least one value in the truth table, the minimum achievable decision coverage is one divided by the total number of truth table values.
Condition coverage measures the number of time steps where each input is equal to zero, which indicates a false condition, and the number of times each input is not equal to zero, which indicates a true condition. If the input signal to the Combinatorial Logic block has a single input element, Simulink Coverage reports only decision coverage, because decision and condition coverage are equivalent.
Simulink
Coverage records whether each element of the input array is true at least once
and false at least once. If all block inputs
are false for at least one time step and true for at least one time step, condition
coverage is 100%. From a coverage perspective, the behavior is the same as a
Logical Operator block that has the Operator
parameter set to OR
with a vector signal input.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced before R2006a
See Also
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)