Module 3 STD
Module 3 STD
Sequential circuit:
comprises both logic gates and the state of
storage elements such as flip-flops.
The output of a sequential circuit depends not
only on present value of inputs but also on
past state of inputs.
3
INTRODUCTION TO COMBINATIONAL LOGIC
7
INTRODUCTION TO COMBINATIONAL LOGIC
8
23
DESIGN PROCEDURE
symbols.
4. Construction of a truth table for the given logic.
STEP3: The input & outputs are assign with letter symbols
Letter symbol for inputs: A, B, C
Letter symbol for output: Y
26
DESIGN PROCEDURE
MO DULE-4 19
DECODE
RS
2 : 4 Decoders
Inputs Outputs
Enable A B Y3 Y2 Y1 Y0
0 x x 0 0 0 0
1 0 0 0 0 0 1
1 0 1 0 0 1 0
1 1 0 0 1 0 0
1 1 1 1 0 0 0
Truth table
MO DULE-4 19
DECODERS
2 : 4 Decoders
Logic Diagram
MO DULE-4 19
DECODE
RS
3 : 8 Decoders
A 3-to-8 line decoder has three inputs (A, B, C)
and eight outputs (Y0- Y7). Based on the 3 inputs
one of the eight outputs is selected.
Inputs Outputs
A B C Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7
0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0 0 0 0
0 1 1 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0
1 0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 0 1 0
1 1 1 0 0 0 0 0 0 0 1
Truth table
MO DULE-4 19
DECODERS
3 : 8 Decoders
Logic Diagram
MO DULE-4 19
DECODE
RS
Applications
Instruction decoder is the part of the CPU
MO DULE-4 19
DECODE
RS
Realization of Boolean Expression using Decoders
The combination of decoder and external logic
gates can be used to implement single or multiple
output function. The decoder can have one of the
two output states either active or active high.
For active high output :
SOP function implementation
When the decoder output is active high it generates
minterms for input variables (i.e) it makes the selected
output logic1. In such cases to implement the sop
function we have to take sum of selected product
terms generated by decoder. This can be implemented
by ORing the selected decoder output.
MO DULE-4 20
DECODERS
Realization of Boolean Expression using Decoders
MO DULE-4 20
DECODE
RS
Realization of Boolean Expression using Decoders
POS function implementation: When the decoder
output is active high POS function in similar manner as
per SOP function except function output is complemented.
This can be achieved by connecting NOR gates instead of
OR gates .
MO DULE-4 20
ENCODERS
Generally, digital encoders produce outputs of 2-
bit, 3-bit or 4-bit codes depending upon the
number of data input lines.
MO DULE-4 20
4 to 2 Encoder
ENCODERS
MO DULE-4 20
ENCODERS Priority Encoder
MO DULE-4 20
ENCODERS Priority Encoder
MO DULE-4 205
ENCODERS Priority Encoder
A priority encoder is an encoder circuit that includes
the priority function.
209
4 to 2 Priority Encoder
ENCODERS
MO DULE-4 21
4 to 2 Priority Encoder
ENCODERS
MO DULE-4 21
ENCODERS 4 to 2 Priority Encoder
MO DULE-4 21
8 to 3 Priority Encoder
ENCODERS
MO DULE-4 21
ENCODERS Encoder Applications
(i). Keyboard Encoder
Priority encoders can be used to reduce the number
of wires needed in a particular circuits or application
that have multiple inputs.
• not n1(w[0],a[0]);
• not n2(w[1],a[1]);
• and (w[2],w[0], w[1]);
• and (w[3],w[1], a[0]);
• and (w[4],a[1], w[0]);
• and (w[5],a[0],a[1]);
• and (y[0],en, w[2]);
• and (y[1],en, w[3]);
• and (y[2],en, w[4]);
• and (y[3],en, w[5]);
• endmodule
2x4 decoder using Gate level model
TB
• ////////////////////////////////
• module decoder2x4gatelevel_tb();
• reg [1:0]a;
• reg en;
• wire [3:0]y;
• decoder2x4 uut (.y(y),.a(a),.en(en));
• initial
• begin
• en=0; a= 2'b00; #100;
• en=1; a = 2'b00; #100;
• en=1; a = 2'b01; #100;
• en=1; a = 2'b10; #100;
• en=1; a = 2'b11; #100;
• end
• endmodule
2x4 decoder using Data flow model
• module decoder(d0,d1,d2,d3,e,a0,a1);
• input e,a0,a1;
• output d0,d1,d2,d3;
• assign d3= (e&a1&a0);
• assign d2= (e&a1&~a0);
• assign d1= (e&a1&~a0);
• assign d0= (e&~a1&a0);
• endmodule
Decoder 2x4 ( Data flow
TB) //////////////////
module test();
reg e,a0,a1;
wire d0,d1,d2,d3;
decoder mydecoder(d0,d1,d2,d3,e,a0,a1);
initial
begin
e=0; a0= 1'b1;a1=1'b1;
#100
e=1; a0= 1'b0;a1=1'b0;
#100
e=1; a0= 1'b0;a1=1'b1;
#100
e=1; a0= 1'b1;a1=1'b0;
#100
e=1; a0= 1'b1;a1=1'b1;
end
endmodule
Decoder 2x4 using
module decoder2x4(y,a,en);
behavioural
levelinput [1:0]a;
output [3:0]y;
input en;
reg [3:0]y;
always @ (a, en)
if (en==0)
y=1'b0;
else
case (a)
2'b00:y=4'b0001;
2'b01:y=4'b0010;
2'b10:y=4'b0100;
2'b11:y=4'b1000;
default : y=1'bx;
endcase
endmodule
2x4 decoder using behavioural level test
bench////////////
module decoder2x4beh_tb;
reg [1:0]a;
reg en;
wire [3:0]y;
decoder2x4 uut (.y(y),.a(a),.en(en));
initial
begin
en=0; a= 2'b00; #100;
en=0; a = 2'b00; #100;
en=0; a = 2'b01; #100;
en=0; a = 2'b10; #100;
en=0; a = 2'b11; #100;
end
endmodule
3x8 decoder using behavioural level
//Declare the Verilog module - The inputs and output port names.
module decoder3to8( Data_in, Data_out );
//what are the input ports and their sizes.
input [2:0] Data_in;
//what are the output ports and their sizes.
output [7:0] Data_out;
//Internal variables
reg [7:0] Data_out;
//Whenever there is a change in the Data_in, execute the always block.
always @(Data_in)
case (Data_in) //case statement. Check all the 8 combinations.
3'b000 : Data_out = 8'b00000001; 3'b001 : Data_out = 8'b00000010;
3'b010 : Data_out = 8'b00000100; 3'b011 : Data_out = 8'b00001000;
3'b100 : Data_out = 8'b00010000; 3'b101 : Data_out = 8'b00100000;
3'b110 : Data_out = 8'b01000000; 3'b111 : Data_out = 8'b10000000;
//To make sure that latches are not created create a default value for output.
default : Data_out = 8'b00000000;
endcase
endmodule
3x8 decoder using behavioural level test benc
module tb_decoder;
// Declaring Inputs
reg [2:0] Data_in;
// Declaring Outputs
wire [7:0] Data_out;
// Instantiate the Unit Under Test (UUT)
decoder3to8 uut (
.Data_in(Data_in),
.Data_out(Data_out)
);
initial begin
//Apply Input and wait for 100 ns
Data_in = 3'b000; #100; Data_in = 3'b001; #100;
Data_in = 3'b010; #100; Data_in = 3'b011; #100;
Data_in = 3'b100; #100; Data_in = 3'b101; #100;
Data_in = 3'b110; #100; Data_in = 3'b111; #100;
end
endmodule
8x3 decoder using behavioural
level
module encoder8to31122( Data_in,Data_out);
always @(Data_in)
case (Data_in)
8'h01 : Data_out = 3'b000;
8'h02 : Data_out = 3'b001;
8'h04 : Data_out = 3'b010;
8'h08 : Data_out = 3'b011;
8'h10 : Data_out = 3'b100;
8'h20 : Data_out = 3'b101 ;
8'h40 : Data_out = 3'b110;
8'h80 : Data_out = 3'b111;
default : Data_out = 3'bxxx;
endcase
endmodule
Multiple Sources Selector Single Destination
MP3 Player
Docking Station
D0
Laptop
D1
MUX
Sound Card Y
D2
D3
Surround Sound System