HDL Code To Simulate 2:4 Decoder

By | November 28, 2017
Spread the love

HDL code to simulate 2:4 Decoder

Aim – Simulate of 2:4 Decoder using HDL code.

Basics of 2:4 Decoder to learn simulate 2:4 decoder

  1. 2:4 Decoder has 2 inputs and 4 outputs. In this program, a,b are two inputs and y0,y1,y2,y3 are four outputs.
  2. en– enable should be active high, in order to get output. If en=0 ( active low), then irrespective of inputs, the output will be zero.

Truth Table

2to4 simulation

HDL Program To simulate 2:4 Decoder

Verilog Code

module dec2_4 (a,b,en,y0,y1,y2,y3)
input a, b, en;
output y0,y1,y2,y3;
assign y0= (~a) & (~b) & en;
assign y1= (~a) & b & en;
assign y2= a & (~ b) & en;
assign y3= a & b & en;
Verilog Test Bench

module dec_tb;
reg a,b,en;
wire y0,y1,y2,y3;
dec2_4 uut (
.a(a), .b(b), .en(en),
.y0(y0), .y1(y1), .y2(y2), .y3(y3));
initial begin
// Initialize Inputs
a = 0;b = 0;en = 1;#100;
a = 0;b = 1;en = 1;#100;
a = 1;b = 0;en = 1;#100;
a = 1;b = 1;en = 1;#100;
a = 0;b = 0;en = 0;#100;


simulation using 2:4 decoder

Related Blogs

Simulation of 2:4 Decoder using Verilog Code

HDL Code to simulate all logic gates 

You Might Like This

Free Download Executed Engineering VHDL Lab Programs

LiFi | Future Internet Light Based WiFi

Microsoft HoloLens–You Can Create Your Desired World

Spread the love

Leave a Reply

Your email address will not be published.