VHDL Logic gates coding
For these notes:
1 = true = high = value of a digital signal on a wire
0 = false = low = value of a digital signal on a wire
A digital logic gate can be represented at least three ways,
we will interchangeably use: schematic symbol, truth table or equation.
The equations may be from languages such as mathematics, VHDL or Verilog.
Digital logic gates are connected by wires. A wire or a group of
wires must be given a name, called a signal name. From an electronic
view the digital logic wire has a high or a low (voltage) but we
will always consider the wire to have a one '1' or a zero '0'.
The basic logic gates are shown below.
The basic "and" gate:
truth table equation symbol
a b | c
----+-- c <= a and b; VHDL
0 0 | 0
0 1 | 0 c = a & b;
1 0 | 0
1 1 | 1 c = and(a,b)
Easy way to remember: The output is 1 when all inputs are 1, 0 otherwise.
In theory, an "and" gate can have any number of inputs.
"and" gate may have many inputs:
truth table equation symbol
a b c | d
------+-- d <= a and b and c; VHDL
0 0 0 | 0
0 0 1 | 0
0 1 0 | 0 notice how a truth table has the inputs
0 1 1 | 0 counting 0, 1, 2, ... in binary.
1 0 0 | 0
1 0 1 | 0 the output (may be more than one bit) is
1 1 0 | 0 after the vertical line, on the right.
1 1 1 | 1
The basic "or" gate:
truth table equation symbol
a b | c
----+-- c <= a or b; VHDL
0 0 | 0
0 1 | 1 c = a | b;
1 0 | 1
1 1 | 1 c = or(a,b)
Easy way to remember: The output is 0 when all inputs are 0, 1 otherwise.
In theory, an "or" gate can have any number of inputs.
"or" gate may have many inputs:
truth table equation symbol
a b c | d
------+-- c <= a or b or c; VHDL
0 0 0 | 0
0 0 1 | 1
0 1 0 | 1 notice how a truth table has the inputs
0 1 1 | 1 counting 0, 1, 2, ... in binary.
1 0 0 | 1
1 0 1 | 1 the output (may be more than one bit) is
1 1 0 | 1 after the vertical line, on the right.
1 1 1 | 1
The basic "nand" gate:
truth table equation symbol
a b | c
----+-- c <= a nand b; VHDL c <= not ( a and b);
0 0 | 1
0 1 | 1 c = ~ (a & b);
1 0 | 1
1 1 | 0 c = nand(a,b)
Easy way to remember: "nand" reads "not and", the complement of "and".
The basic "nor" gate:
truth table equation symbol
a b | c
----+-- c <= a nor b; VHDL c <= not ( a or b);
0 0 | 1
0 1 | 0 c = ~ (a | b);
1 0 | 0
1 1 | 0 c = nor(a,b)
Easy way to remember: "nor" reads "not or", the complement of "or".
The basic "xor" gate:
truth table equation symbol
a b | c
----+-- c <= a xor b; VHDL c = (a and not b) or (not a and b);
0 0 | 0
0 1 | 1 c = a ^ b;
1 0 | 1
1 1 | 0 c = xor(a,b)
Easy way to remember: "eXclusive or" not 11, or odd number of ones.
The basic "xor" gate:
truth table equation symbol
a b c | d
------+-- d <= a xor b xor c; VHDL
0 0 0 | 0
0 0 1 | 1
0 1 0 | 1 d = a ^ b ^ c;
0 1 1 | 0
1 0 0 | 1 d = xor(a,b,c)
1 0 1 | 0
1 1 0 | 0
1 1 1 | 1
Easy way to remember: odd parity, odd number of ones.
The basic "xnor" gate:
truth table equation symbol
a b | c
----+-- c <= a xnor b; VHDL c <= not(a xor b);
0 0 | 1
0 1 | 0 c = ~ (a ^ b);
1 0 | 0
1 1 | 1 c = xnor(a,b)
Easy way to remember: "xnor" reads "not xor", equality or even parity.
The basic "not" gate:
truth table equation symbol
a | b
--+-- b <= not a; VHDL
0 | 1
1 | 0 b = ~ a;
b = not(a)
Easy way to remember: invert or "not", the complement.
A specialized gate:
truth table equation symbol
a b c | d
------+-- d <= not( not a and b and not c); VHDL
0 0 0 | 1
0 0 1 | 1
0 1 0 | 0 d = ~( ~a & b & ~c);
0 1 1 | 1
1 0 0 | 1 d = and(not(a),b,not(c))
1 0 1 | 1 _______
1 1 0 | 1 _ _
1 1 1 | 1 d = (a b c)
Easy way to remember: none, just work it out.
Bubbles on the input mean the same as bubbles on the output,
invert the signal value. Often this is written with a line
_______
_ _
above the variable d = a b c which is read:
d equals a bar and b and c bar. The word "bar" for the line
above the variable, meaning invert the expression.
It is known that there are 16 Boolean functions with two inputs.
In fact, for any number of inputs, n, there are 2^(2^n) Boolean
functions ( two to the power of two to the nth).
For n=2 16 functions 2^4
n=3 256 functions 2^8
n=4 65,536 functions 2^16
n=5 over four billion functions 2^32
The truth table for all Boolean functions of two inputs is
n x
n x a a n
o _ _ o n n o 1 1 o
a b | 0 r 2 a 4 b r d d r b 1 a 3 r 1
----+--------------------------------
0 0 | 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1 | 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
1 0 | 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
1 1 | 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
Notice that for two input variables, a b, there are 2^2 = 4 rows
Notice that for four rows there are 2^4 = 16 columns.
A question is: Which are "universal" functions from which all
other functions can be obtained?
The answer is that either "nand" or "nor" can be used to create
all other functions (when having 0 and 1 available). It turns out
that electric circuits rather naturally create "nand" or "nor"
gates. No more than five "nand" gates or five "nor" gates are
needed in creating any of the 16 Boolean functions of two inputs.
Here are the circuits using only "nand" to get all 16 functions.
Then, there is more than just 0 and 1 values a boolean variable may have:
H = 1 high, weak
L = 0 low, weak
X = unknown
Z = high impedance, usually open circuit, or bus
W = unknown, weak
U = uninitialized
- = don't care = X = unknown
Truth tables for and, or, ... using all VHDL std_logic signal values:
t_table.out
Generated by program, digital logic simulator, VHDL
t_table.vhdl