Sunday 23 January 2022

Verilog Code for 2 to 4 Decoder

 


Gate Level Modelling

module 2to4decoder(a0,a1, d0,d1,d2,d3);

input a0,a1;

output d0,d1,d2,d3;

wire s,t;

not g1(s,a0);

not g2(t,a1);

and g3(d0, s,t);

and g4(d1, a0,t);

and g5(d2, s,a1);

and g6(d3, a0,a1);

endmodule

Data flow Level Modelling

module 2to4decoder(a0,a1, d0,d1,d2,d3);

input a0,a1;

output d0,d1,d2,d3;

assign d0 = ~a0 & ~a1;

assign d1 = a0 & ~a1;

assign d2 = ~a0 & a1;

assign d3 = a0 & a1;

endmodule

Behavioral level Modelling

module 2to4decoder(a0,a1, d0,d1,d2,d3);

input a0,a1;

output reg d0,d1,d2,d3;

always @(a0,a1)

begin

case({a1,a0})

2'b00: begin d0 = 1; d1 = 0, d2 = 0; d3 = 0; end

2'b01: begin d0 = 0; d1 = 1, d2 = 0; d3 = 0; end

2'b10: begin d0 = 0; d1 = 0, d2 = 1; d3 = 0; end

2'b11: begin d0 = 0; d1 = 0, d2 = 0; d3 = 1; end

endcase

end

endmodule

No comments:

Post a Comment

Verilog Code for Universal Shift Register

  Universal Shift Register module universalshift (clr,clk,sel,in,out); input clr,clk; input [1:0]sel; input [3:0]parin; output reg[3:0]out; ...