Question

In: Electrical Engineering

Code a 2:4 decoder with registered out. Also write a testbench of the decoder.

Code a 2:4 decoder with registered out. Also write a testbench of the decoder.

Solutions

Expert Solution

Verilog Code

module decoder2to4(A,B,En,Y0,Y1,Y2,Y3);

      input A,B;

      input En;

      output reg Y0,Y1,Y2,Y3;

      always@(A or B or En)

         begin

           if (En)

              case( {A,B} )

                    2'b00: {Y3,Y2,Y1,Y0} = 4'b0001;

                    2'b01: {Y3,Y2,Y1,Y0} = 4'b0010;

                    2'b10: {Y3,Y2,Y1,Y0} = 4'b0100;

                    2'b11: {Y3,Y2,Y1,Y0} = 4'b1000;

                    default: {Y3,Y2,Y1,Y0} = 4'b0000;

             endcase

          if (En==0)

                   {Y3,Y2,Y1,Y0} = 4'b0000;

       end

endmodule

Test Bench

module testdecoder;

      wire Y0,Y1,Y2,Y3;

      reg A,B;

      reg En;

      decoder2to4   UUT(A,B,En,Y0,Y1,Y2,Y3);    // Unit under test

      initial

         begin

             A= 1'b0;

             B= 1'b0;

             En=1'b0;

             #9;

            En = 1'b1;

            #10;

             A= 1'b0;

             B= 1'b1;

             #10;

             A= 1'b1;

             B= 1'b0;

             #10;   

             A= 1'b1;

             B= 1'b1;

            #5;

            En = 1'b0;

            #5;

         $stop

   end

endmodule


Related Solutions

Write a Huffman decoder in verilog that inputs a text file with testbench.
Write a Huffman decoder in verilog that inputs a text file with testbench.
Digital System Design Write the verilog HDL code for 2-4 decoder (Gate level modeling) along with...
Digital System Design Write the verilog HDL code for 2-4 decoder (Gate level modeling) along with the testbench and simulate using ModelSim. Upload the assignment (i) code (ii) testbench (iii) simulation in single pdf file.
Write down the VERILOG code for an XOR gate and the testbench code to test it
Write down the VERILOG code for an XOR gate and the testbench code to test it
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder...
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder that asks the user to enter the string and output the Huffman code for every letter and a code for encoding that will have every letter and its Huffman code and output all the possibilities for the real string. you must show a screen of an input and the output for both the encoder and the decoder
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado...
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado and show waveform.
Please write down in Verilog code with testbench: Audio Tone Generator like Ambulance siren or Police...
Please write down in Verilog code with testbench: Audio Tone Generator like Ambulance siren or Police siren.
Design in VHDL a gray code decoder to excess 3 code Screenshot the simulation and code.
Design in VHDL a gray code decoder to excess 3 code Screenshot the simulation and code.
Design an 8-bit adder. Show Verilog code and testbench.
Design an 8-bit adder. Show Verilog code and testbench.
Write a VHDL code and testbench for a positive-edge-triggered JK-type FF with asynchronous active-low reset (RN)...
Write a VHDL code and testbench for a positive-edge-triggered JK-type FF with asynchronous active-low reset (RN) - JKFFR
Verilog code to make 8bit bcd to 8bit binary please with testbench
Verilog code to make 8bit bcd to 8bit binary please with testbench
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT