Thursday, October 15, 2015

Multiplexers

Unit-V
COMBINATIONAL LOGIC DESIGN
Multiplexers

A multiplexer is a digital switch—it connects data from one of n sources to its output. Figure.1(a) shows the inputs and outputs of an n-input, b-bit multiplexer.

 

Figure 1: Multiplexer Structure (a) inputs and outputs (b) Functional Equivalent

There are n sources of data, each of which is b bits wide, and there are b output bits. In typical commercially available multiplexers, n = 1, 2, 4, 8, or 16, and b = 1, 2, or 4. There are s inputs that select among the n sources, so s = [log2n]. An enable input EN allows the multiplexer to “do its thing”; when EN = 0, all of the outputs are 0. A multiplexer is often called a mux for short. Figure.1(b) shows a switch circuit that is roughly equivalent to the multiplexer.


 However, unlike a mechanical switch, a multiplexer is a unidirectional device: information flows only from inputs (on the left) to outputs (on the right).

In the general logic equation for a multiplexer output, the summation symbol represents a logical sum of product terms. Variable iY is a particular output bit (1 ≤ i ≤ b), and variable iDj is input bit i of source j (0 ≤ j ≤ n - 1). Mj represents minterm j of the s select inputs. Thus, when the multiplexer is enabled and the value on the select inputs is j, each output iY equals the corresponding bit of the selected input, iDj.

Multiplexers are obviously useful devices in any application in which data must be switched from multiple sources to a destination. A common application in computers is the multiplexer between the processor’s registers and its arithmetic logic unit (ALU). Eg., consider a 16-bit processor in which each instruction has a 3-bit field that specifies one of eight registers to use. This 3-bit field is connected to the select inputs of an 8-input, 16-bit multiplexer. The multiplexer’s data inputs are connected to the eight registers, and its data outputs are connected to the ALU to execute the instruction using the selected register.

Standard MSI Multiplexers

The sizes of commercially available MSI multiplexers are limited by the number of pins available in an inexpensive IC package. Commonly used muxes come in 16-pin packages.

Figure 2: The 74x151 8-input, 1-bit multiplexer (a) Logic Diagram including pin numbers for a standard 16-pin dual-in line package (b) traditional Logic Symbol

The 74x151, shown in Figure.2 selects among eight 1-bit inputs. The select inputs are named C, B, and A, where C is most significant numerically. The enable input EN_L is active low; both active-high (Y) and active-low (Y_L) versions of the output are provided. The 74x151’s truth table is shown in Table.1. In the 74x151’s table, only a few of the inputs are listed under the “Inputs” heading. Each output is specified as 0, 1, or a simple logic function of the remaining inputs (e.g., D0 or D0’), which saves eight columns and eight rows in the table, and presents the logic function more clearly than a larger table would.

Table.1: Truth Table for a 74x151 8-input, 1-bit multiplexer


Program Code:

Library ieee;
Use ieee.std_logic_1164.all;

Entity mux74x151 is
Port( EN_L: in std_logic;
S: in std_logic_vector(2 downto 0);
D: in std_logic_vector(7 downto 0);
Y,Y_L: out std_logic);
End mux74x151;

Architecture dataflow of mux74x151 is
Signal Y1: std_logic;
Begin
          with S select  Y1<=    D(7) when “111”,
                             D(6) when “110”,
                             D(5) when “101”,
                             D(4) when “100”,
D(3) when “011”,
D(2) when “010”,
D(1) when “001”,
D(0) when “000”,
                             ‘0’ when others;
          Y<=Y1 when EN_L=‘0’ else ‘0’;
          Y_L<=not y;
End dataflow;

Architecture behav of mux74x151 is
Begin
Process(EN_L, S, D)
Begin
Case S is
When “111” =>   Y1<=    D(7) ;
When “110” =>   Y1<=    D(6) ;
When “101” =>   Y1<=    D(5) ;
When “100” =>   Y1<=    D(4) ;
When “011” =>   Y1<=    D(3) ;
When “010” =>   Y1<=    D(2) ;
When “001” =>   Y1<=    D(1) ;
When “000” =>   Y1<=    D(0) ;
When others =>   Y1<=‘0’;
End case;
If (EN_L=‘0’) then
Y<=Y1;
Else
Y<=‘0’;
End if;
Y_L<=not Y;
End process;
End behav;

The 74x157 is shown in Figure.3, which selects between two 4-bit inputs. The select input is S, the active-low enable input is G_L and the data sources are named A and B instead of D0 and D1. The extended truth-table notation makes the 74x157’s description very compact, as shown in Table.2.

Table 2: Truth Table for a 74x157 2-input, 4-bit multiplexer



Figure 3: The 74x157 2-input, 4-bit multiplexer (a) Logic Diagram including pin numbers for a standard 16-pin dual in-line package (b) Traditional Logic Symbol

Program Code:

Library ieee;
Use ieee.std_logic_1164.all;

Entity mux74x157 is
Port( EN_L,S: in std_logic;
A,B: in std_logic_vector(4 downto 1);
Y: out std_logic_Vector(4 downto 1));
End mux74x157;

Architecture dataflow of mux74x157 is
Signal y1: std_logic_vector(4 down to 1);
Begin
with S select  Y1<=    A when ‘0’,
                                  B when ‘1’,
                                  “0000” when others;
y<=y1 when G_L=‘1’ else “0000”;
End dataflow;

The intermediate between the 74x151 and 74x157 is the 74x153, a 4-input, 2-bit multiplexer, whose logic symbol is shown in Figure.4, has separate enable inputs (1G, 2G) for each bit and its function is shown in Table.3.

Table 3: Truth Table for a 74x153 4-input, 2-bit multiplexer
                               


Figure 4: Traditional Symbol for the 74x153
Some multiplexers have three-state outputs. The enable input of such a multiplexer, instead of forcing the outputs to zero, forces them to the Hi-Z state. Eg., the 74x251 is identical to the ’151 in its pinout and its internal logic design, except that Y and Y_L are three-state outputs. When the EN_L input is negated, instead of forcing the outputs to be negated, it forces the outputs into the high-Z state. Similarly, the 74x253 and 74x257 are three-state versions of the ’153 and ’157. The three-state outputs are especially useful when n-input muxes are combined to form larger muxes.

Program Code

Library ieee;
Use ieee.std_logic_1164.all;

Entity mux74x153 is
Port( G_L,S: in std_logic_vector(1 downto 0);
C1,C2: in std_logic_vector(3 downto 0);
Y: out std_logic_Vector(1 downto 0));
End mux74x153;

Architecture behavioral of mux74x153 is
Signal y1: std_logic_vector(1 downto 0);
Begin
Process(G_L,S,C1,C2)
Begin
If (G_L=“00”) then
If (S=“00”) then
Y1(1)<= C1(0);
Y1(0)<= C2(0);
Elsif (S=“01” ) then
Y1(1)<= C1(1);
Y1(0)<= C2(1);
Elsif (S=“10” ) then
Y1(1)<= C1(2);
Y1(0)<= C2(2);
Elsif (S=“11” ) then
Y1(1)<= C1(3);
Y1(0)<= C2(3);
End if;
Els if(G_L=“01” ) then
If (S=“00”) then
Y1(1)<= C1(0);
Y1(0)<= ‘0’;
Elsif (S=“01” ) then
Y1(1)<= C1(1);
Y1(0)<= ‘0’;
Elsif (S=“10” ) then
Y1(1)<= C1(2);
Y1(0)<= ‘0’;
Elsif (S=“11” ) then
Y1(1)<= C1(3);
Y1(0)<= ‘0’;
End if;
Els if(G_L=“10” ) then
If (S=“00”) then
Y1(1)<= ‘0’;
Y1(0)<= C2(0);
Elsif (S=“01” ) then
Y1(1)<= ‘0’;
Y1(0)<= C2(1);
Elsif (S=“10” ) then
Y1(1)<= ‘0’;
Y1(0)<= C2(2);
Elsif (S=“11” ) then
Y1(1)<= ‘0’;
Y1(0)<= C2(3);
End if;
Elsif (G_L=“11”) then
Y1=“00”;
 end if;
End process;
End behavioral;

Expanding Multiplexers

Seldom does the size of an MSI multiplexer match the characteristics of the problem at hand. Eg., an 8-input, 16-bit multiplexer might be used in the design of a computer processor, this function could be performed by 16 74x151 8-input, 1-bit multiplexers or equivalent ASIC cells, each handling one bit of all the inputs and the output. The processor’s 3-bit register-select field would be connected to the A, B, and C inputs of all 16 muxes, so they would all select the same register source at any given time.

The device that produces the 3-bit register-select field in this example must have enough fanout to drive 16 loads. With 74LS-series ICs this is possible because typical devices have a fanout of 20 LS-TTL loads. Still, it is fortunate that the ’151 was designed so that each of the A, B, and C inputs presents only one LS-TTL load to the circuit driving it. Theoretically, the ’151 could have been designed without the first rank of three inverters shown on the select inputs in Figure.5, but then each select input would have presented five LS-TTL loads, and the drivers in the register-select application would need a fanout of 80.

Also the multiplexers can be expanded with the number of data sources. Eg. For a 32-input, 1-bit multiplexer, Figure.5 shows five select bits are required. A 2-to-4 decoder (one-half of a 74x139) decodes the two high-order select bits to enable one of four 74x151 8-input multiplexers. Since only one ’151 is enabled at a time, the ’151 outputs can simply be ORed to obtain the final output.

Figure 5: Combining 74x151s to make a 32-to-1 multiplexer.
Program Code
Library ieee;
Use ieee.std_logic_1164.all;

Entity mux32to1 is
Port(XEN_L: in std_logic;
XA: in std_logic_vector(4 downto 0);
X: in std_logic_vector(31 downto 0);
XOUT:out std_logic);
End mux32to1;

Architectural structural of mux32to1 is

Component dec74x139 is
Port(G_L: in std_logic;
A: in std_logic_vector(1 downto 0);
Y:out std_logic_vector(3 downto 0));
End component;

Component IC74x151 is
Port(EN_L: in std_logic;
S: in std_logic_vector(2 downto 0);
D: in std_logic_vector(7 downto 0);
Y,Y_L: out std_logic);
End component;

Component IC74x20 is
Port(D_L: in std_logic_vector(3 downto 0);
Y: out std_logic);
End component;

Signal EN_L, XO_L: std_logic_vector(3 downto 0);

Begin
U1: IC74139  port map(XEN_L,XA(3),XA(4),EN_L(3 downto 0));
U2: IC74x151  port map(EN_L(0), XA(2 downto 0),X(7 downto 0), OPEN, XO_L(0));
U3: IC74x151  port map(EN_L(1), XA(2 downto 0),X(15 downto 8), OPEN, XO_L(1));
U4: IC74x151  port map(EN_L(2), XA(2 downto 0),X(23 downto 16), OPEN, XO_L(2));
U5: IC74x151  port map(EN_L(3), XA(2 downto 0),X(31 downto 24), OPEN, XO_L(3));
U6: IC74x20 port map(XO_L, XOUT);
End structural;

The 32-to-1 multiplexer can also be built using 74x251s, this circuit is identical to Figure.6, except that the output NAND gate is eliminated. Instead, the Y (and, if desired, Y_L) outputs of the four ’251s are simply tied together. The ’139 decoder ensures that at most one of the ’251s has its threestate outputs enabled at any time. If the ’139 is disabled (XEN_L is negated), then all of the ’251s are disabled, and the XOUT and XOUT_L outputs are undefined. However, if desired, resistors may be connected from each of these signals to +5 volts to pull the output HIGH in this case.


Figure 6: A multiplexer driving a bus and a demultiplexer receiving the bus (a) Switch equivalent (b) Block Diagram Symbols

Multiplexers, Demultiplexers, and Buses

A multiplexer can be used to select one of n sources of data to transmit on a bus. At the far end of the bus, a demultiplexer can be used to route the bus data to one of m destinations. Such an application, using a 1-bit bus, is depicted in terms of our switch analogy in Figure.6(a). In fact, block diagrams for logic circuits often depict multiplexers and demultiplexers using the wedge-shaped symbols in (b), to suggest visually how a selected one of multiple data sources gets directed onto a bus and routed to a selected one of multiple destinations. The function of a demultiplexer is just the inverse of a multiplexer’s. Eg., a 1-bit, n-output demultiplexer has one data input and s inputs to select one of n = 2s data outputs. In normal operation, all outputs except the selected one are 0; the selected output equals the data input. This definition may be generalized for a b-bit, n-output demultiplexer; such a device has b data inputs, and its s select inputs choose one of n = 2s sets of b data outputs.

A binary decoder with an enable input can be used as a demultiplexer, as shown in Figure.7. The decoder’s enable input is connected to the data line, and its select inputs determine which of its output lines is driven with the data
bit. The remaining output lines are negated. Thus, the 74x139 can be used as a 2-bit, 4-output demultiplexer with active-low data inputs and outputs, and the 74x138 can be used as a 1-bit, 8-output demultiplexer. In fact, the manufacturer’s catalog typically lists these ICs as “decoders/demultiplexers.”


Figure 7: Using a 2-to-4 binary decoder as a 1-bit, 4-output demultiplexer (a) generic Decoder (b) 74x139



Tuesday, September 15, 2015

Three State Devices, IC74x541, IC74x245 and VHDL Programming

Unit-V
COMBINATIONAL LOGIC DESIGN
Three State Devices
The electrical design of CMOS and TTL devices whose outputs may be in one of three states—0, 1, or Hi-Z.

Three-State Buffers

The most basic three-state device is a three-state buffer, often called a three-state driver. The logic symbols for four physically different three-state buffers are shown in Figure 1.

Figure 1: Three state buffers (a) noninverting, active-high enable (b) noninverting, active-low enable (c) inverting, active-high enable (d) inverting, active-low enable

The basic symbol is that of a noninverting buffer (a, b) or an inverter (c, d). The extra signal at the top of the symbol is a three-state enable input, which may be active high (a, c) or active low (b, d). When the enable input is asserted, the device behaves like an ordinary buffer or inverter. When the enable input is negated, the device output “floats”; that is, it goes to high impedance (Hi-Z), disconnected state and functionally behaves as if it weren’t even there.

Figure 2: Eight Sources sharing a three-state parity line

Figure 2 shows an example of how the three-state devices allow multiple sources to share a single “party line,” as long as only one device “talks” on the line at a time. Three input bits, SSRC2–SSRC0, select one of eight sources of data that may drive a single line, SDATA. A 3-to-8 decoder, the 74x138, ensures that only one of the eight SEL lines is asserted at a time, enabling only one three-state buffer to drive SDATA. However, if not all of the EN lines are asserted, and then none of the three-state buffers is enabled. The logic value on SDATA will be undefined.

Typical three-state devices are designed so that they go into the Hi-Z state faster than they come out of the Hi-Z state. (In terms of the specifications in a data book, tpLZ and tpHZ are both less than tpZL and tpZH) i.e., if the outputs of two three-state devices are connected to the same party line, and we simultaneously disable one and enable the other, the first device will get off the party line before the second one gets on. This is important because, if both devices were to drive the party line at the same time, and if both were trying to maintain opposite output values (0 and 1), then excessive current would flow and create noise in the system, often called fighting.

Unfortunately, delays and timing skews in control circuits make it difficult to ensure that the enable inputs of different three-state devices change “simultaneously.”

Even when this is possible, a problem arises if three-state devices from different - speed logic families (or even different ICs manufactured on different days) are connected to the same party line. The turn-on time (tpZL or tpZH) of a “fast” device may be shorter than the turn-off time (tpLZ or tpHZ) of a “slow” one, and the outputs may still fight. The only really safe way to use three-state devices is to design control logic that guarantees a dead time on the party line during which no one is driving it.

Figure 3: Timing Diagram for the three-state parity line

The dead time must be long enough to account for the worst-case differences between turn-off and turn-on times of the devices and for skews in the three-state control signals. Figure 3 shows the operation for the party line of Figure 2, i.e., a drawing convention for three-state signals—when in the Hi-Z state, they are shown at an “undefined” level halfway between 0 and 1.

Standard SSI and MSI Three-State Buffers

Like logic gates, several independent three-state buffers may be packaged in a single SSI IC. Figure 4 shows the pinouts of 74x125 and 74x126, each of which contains four independent noninverting three-state buffers in a 14-pin package. The three-state enable inputs in the ’125 are active low, and in the ’126 they are active high.

Figure 4: Pinouts of the 74x125 and 74x126 three-state buffers

Most party-line applications use a bus with more than one bit of data. For example, in an 8-bit microprocessor system, the data bus is eight bits wide, and peripheral devices normally place data on the bus eight bits at a time. Thus, a peripheral device enables eight three-state drivers to drive the bus, all at the same time. Independent enable inputs, as in the ’125 and ’126, are not necessary.

Thus, to reduce the package size in wide-bus applications, most commonly used MSI parts contain multiple three-state buffers with common enable inputs. Eg., Figure 5 shows the logic diagram and symbol for a 74x541 octal noninverting three-state buffer. Octal means that the part contains eight individual buffers. Both enable inputs, G1_L and G2_L, must be asserted to enable the device’s three-state outputs. The little rectangular symbols inside the buffer symbols indicate hysteresis, an electrical characteristic of the inputs that improves noise immunity; the 74x541 inputs typically have 0.4 volts of hysteresis.


Figure 5: The 74x541 octal three-state buffer (a) logic diagram including pin numbers for a standard 20-pin dual in-line package (b) traditional logic symbol

VHDL Program Code

Library ieee;
Use ieee.std_logic_1164.all;

Entity IC74541 is
Port(A: in std_logic_vector(7 downto 0);
          G1_L,G2_L: in std_logic;
    Y: out std_logic_vector(7 downto 0));
End IC74541;

Architecture behav of IC74541 is
Begin
Process(a,G1_L, G2_L)
Begin
If(G1_L=‘0’ and G2_L=‘0’ ) then
Y<=A;
else
Y<=“ZZZZZZZZ”;
End if;
End process;
End behav;

Figure 6 shows part of a microprocessor system with an 8-bit data bus, DB[0–7], and a 74x541 used as an input port. The microprocessor selects Input Port 1 by asserting INSEL1 and requests a read operation by asserting READ. The selected 74x541 responds by driving the microprocessor data bus with user supplied input data. Other input ports may be selected when a different INSEL line is asserted along with READ.


Figure 6: Using a 74x541 as a microprocessor input port

Many other varieties of octal three-state buffers are commercially available. Eg., the 74x540 is identical to the 74x541 except that it contains inverting buffers. The 74x240 and 74x241 are similar to the ’540 and ’541, except that they are split into two 4-bit sections, each with a single enable line. A bus transceiver contains pairs of three-state buffers connected in opposite directions between each pair of pins, so that data can be transferred in either direction. Figure 7 shows the logic diagram and symbol for a 74x245 octal three-state transceiver. The DIR input determines the direction of transfer, from A to B (DIR = 1) or from B to A (DIR = 0). The three-state buffer for the selected direction is enabled only if G_L is asserted.


Figure 7: The 74x245 octal three-state transceiver (a) Logic Diagram (b) Traditional Logic Symbol

VHDL Program Code

Library ieee;
Use ieee.std_logic_1164.all;

Entity IC74245 is
Port(G_L,DIR: in std_logic;
          A,B: inout std_logic_vector(7 downto 0);
         Y: out std_logic_vector(7 downto 0));
End IC74245;

Architecture behav of IC74245 is
Begin
Process (G_L, DIR, A,B)
Begin
If(G_L=‘0’ and DIR=’1’) then
B<=A;
Elsif (G_L=’0’ and DIR=‘0’) then
A<=B;
End if;
End process;
End behav;
    

A bus transceiver is typically used between two bidirectional buses, as shown in Figure 8. Three different modes of operation are possible, depending on the state of G_L and DIR, as shown in Table 1. As usual, it is the designer’s responsibility to ensure that neither bus is ever driven simultaneously by two devices. However, independent transfers where both buses are driven at the same time may occur when the transceiver is disabled, as indicated in the last row of the table.


Figure 8: Bidirectional buses and transceiver operation

Table 1: Modes of Operation for a pair of bidirectional buses


Program Code:

IEEE 1164 package declarations for STD_ULOGIC and STD_LOGIC

PACKAGE std_logic_1164 IS
-- logic state system (unresolved)
TYPE std_ulogic IS ( 'U', -- Uninitialized
'X', -- Forcing Unknown
'0', -- Forcing 0
'1', -- Forcing 1
'Z', -- High Impedance
'W', -- Weak Unknown
'L', -- Weak 0
'H', -- Weak 1
'-' -- Don't care
);
-- unconstrained array of std_ulogic
TYPE std_ulogic_vector IS ARRAY ( NATURAL RANGE <> ) OF std_ulogic;
-- resolution function
FUNCTION resolved ( s : std_ulogic_vector ) RETURN std_ulogic;
-- *** industry standard logic type ***
SUBTYPE std_logic IS resolved std_ulogic;
...

IEEE 1164 package body for STD_ULOGIC and STD_LOGIC

PACKAGE BODY std_logic_1164 IS
-- local type
TYPE stdlogic_table IS ARRAY(std_ulogic, std_ulogic) OF std_ulogic;
-- resolution function
CONSTANT resolution_table : stdlogic_table := (
-- ---------------------------------------------------------
-- | U X 0 1 Z W L H - | |
-- ---------------------------------------------------------
( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ), -- | U |
( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ), -- | X |
( 'U', 'X', '0', 'X', '0', '0', '0', '0', 'X' ), -- | 0 |
( 'U', 'X', 'X', '1', '1', '1', '1', '1', 'X' ), -- | 1 |
( 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', 'X' ), -- | Z |
( 'U', 'X', '0', '1', 'W', 'W', 'W', 'W', 'X' ), -- | W |
( 'U', 'X', '0', '1', 'L', 'W', 'L', 'W', 'X' ), -- | L |
( 'U', 'X', '0', '1', 'H', 'W', 'W', 'H', 'X' ), -- | H |
(‘U’, 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ) -- | - |
);
FUNCTION resolved ( s : std_ulogic_vector ) RETURN std_ulogic IS
VARIABLE result : std_ulogic := 'Z'; -- weakest state default
BEGIN
-- the test for a single driver is essential otherwise the
-- loop would return 'X' for a single driver of '-' and that
-- would conflict with the value of a single driver unresolved
-- signal.
IF (s'LENGTH = 1) THEN RETURN s(s'LOW);
ELSE
FOR i IN s'RANGE LOOP
result := resolution_table(result, s(i));
END LOOP;
END IF;
RETURN result;
END resolved;
...

VHDL program with four 8-bit three-state drivers

library IEEE;
use IEEE.std_logic_1164.all;

entity V3statex is
port (
G_L: in STD_LOGIC; -- Global output enable
SEL: in STD_LOGIC_VECTOR (1 downto 0); -- Input select 0,1,2,3 ==> A,B,C,D
A, B, C, D: in STD_LOGIC_VECTOR (1 to 8); -- Input buses
X: out STD_ULOGIC_VECTOR (1 to 8) -- Output bus (three-state)
);
end V3statex;

architecture V3states of V3statex is
constant ZZZZZZZZ: STD_ULOGIC_VECTOR := ('Z','Z','Z','Z','Z','Z','Z','Z');
begin

process (G_L, SEL, A)
begin
if G_L='0' and SEL = "00" then X <= To_StdULogicVector(A);
else X <= ZZZZZZZZ;
end if;
end process;

process (G_L, SEL, B)
begin
if G_L='0' and SEL = "01" then X <= To_StdULogicVector(B);
else X <= ZZZZZZZZ;
end if;
end process;

process (G_L, SEL, C)
begin
if G_L='0' and SEL = "10" then X <= To_StdULogicVector(C);
else X <= ZZZZZZZZ;
end if;
end process;

process (G_L, SEL, D)
begin
if G_L='0' and SEL = "11" then X <= To_StdULogicVector(D);
else X <= ZZZZZZZZ;
end if;
end process;

end V3states;