Decoder implementation using the Shift operators in VHDL

| |
One of the different method of implementing a decoder in VHDL is to use the shift operators of vhdl language. Using these operator can shorten the code and can be extended easily to higher number of input/output bits. Here it is shown how a 3x8 decoder can be implemented using vhdl shift operator and verified and simulated using the active-hdl VHDL software.

Before going to the implementation readers may want to read other ways of implementing decoder. For this follow the following links-
  • 74LS138 Decoder design using logical gates
  • 74LS138 Decoder design using With Select statement 
  • 74LS138 3x8 decoder design with case construct in vhdl
  • 74LS138 3x8 decoder design using if else construct
In this vhdl tutorial we gonna see how the shift operator in VHDL can be used to implement a decoder. The idea of using shift operator comes from the fact that there is bit shift in the output of the decoder according the input. If we let x be 4 bit input and y be the 8 bit output then one can observe the output y being in the form- 10000000, 01000000, 00100000, 00010000 ...00000001, which shows that 1 is shifted to the right one bit according to the input x. Now x is 4 bit binary but when it is converted to integer then x as integer indicates the number of shift required.

The following VHDL code illustrates how a decoder could be realized using shift operator in vhdl:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity decoder_shift is
    generic (n : positive := 4);
    port(
    x : in std_logic_vector(n-1 downto 0);
    y : out std_logic_vector(2**n-1 downto 0)
    );
end decoder_shift;

architecture decoder_shift_arch of decoder_shift is
constant yout : bit_vector(2**n-1 downto 0) := (0=>1,others => 0);
begin
    y <= to_stdlogicvector(yout sll to_integer(unsigned(x)));
   
end decoder_shift_arch;


In the above as x input is a std_logic_vector it is first unsigned and then to integer. The shifting operater ssl is used to shift the intermediate signal yout. Since shifting operator ssl acts only on bit_vector, intermediate signal yout is defined as bit_vector. After the shifting the bit_vector is converted back to std_logic_vector using the function to_stdlogic_vector and assigned to the original output y.

The advantage of using shift operator for modelling the decoder is that it requires less code lines to implement the decoder. Another advantage is that it can be easily adopted to higher number of input/output bits by changing the generic bit number n declaration.

The code was simulated with active-hdl vhdl software and the waveform of the simulation is shown below.

decoder simulation in vhdl software

Related Posts by Categories

0 comments:

Post a Comment