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-
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.
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
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.
0 comments:
Post a Comment