Thursday, July 1, 2010

3x8 Decoder

A decoder is a device which does the reverse operation of an encoder, undoing the encoding so that the original information can be retrieved. A slightly more complex decoder would be the n-to-2n type binary decoders. These type of decoders are combinational circuits that convert binary information from 'n' coded inputs to a maximum of 2n unique outputs. We say a maximum of 2n outputs because in case the 'n' bit coded information has unused bit combinations, the decoder may have less than 2n outputs. We can have 2-to-4 decoder, 3-to-8 decoder or 4-to-16 decoder. We can form a 3-to-8 decoder from two 2-to-4 decoders (with enable signals).

module dec (x, z);
input [2:0] x;
output [7:0] z;
reg [7:0] z;
always @ (x)
                3'b000 : z=8'b00000001;
                3'b001 : z=8'b00000010;
                3'b010 : z=8'b00000100;
                3'b011 : z=8'b00001000;
                3'b100 : z=8'b00010000;
                3'b101 : z=8'b00100000;
                3'b110 : z=8'b01000000;
                3'b111 : z=8'b10000000;

You could download file dec.v and testbench.tb here

No comments:

Post a Comment