Decoders

 

decoders are used to decode the position of the output line: to each input code corresponds one output line


truth table for an 2-4 binary decoder:



 
library IEEE; 

use IEEE.std_logic_1164.all; 

use IEEE.numeric_std.all; 

entity dec_2to4 is 

    port(a: in unsigned (1 downto 0); x: out unsigned(3 downto 0));
end dec_2to4; 
 
architecture process_dec_1 of dec_2to4 is 

begin 

process(a) 

variable int_a: integer range 0 to 3; 

begin 

    int_a := to_integer(a); -- from IEEE.numeric_std
    case int_a is  
      when 0 => x <= "0001"; 

      when 1 => x <= "0010"; 

      when 2 => x <= "0100"; 

      when 3 => x <= "1000"; 

    end case;
end process; 

end process_dec_1;

 
architecture process_dec_2 of dec_2to4 is 

begin 

process(a) 

variable int_a: integer range 0 to 3; 

begin 

    int_a := to_integer(a); -- from IEEE.numeric_std 

    for i in 0 to 3 loop 

      if(int_a = i ) then 
        x(i) <= '1'; 

        else 

        x(i) <= '0';

      end if;
    end loop;
end process; 

end process_dec_2;

 
architecture flow_dec_1 of dec_2to4 is 

signal int_a: integer range 0 to 3; 

begin 

    int_a <= to_integer(a); -- from IEEE.numeric_std
    with int_a select 
       x <= "0001" when 0, 
        "0010" when 1, 
        "0100" when 2, 
        "1000" when 3, 
        "0000" when others;
end flow_dec_1;

Exercise:

    1. use if statement to check the enable signal state
    2. concatenate enable signal with the regular inputs and use one case statement