priority
encoders are used to encode the position of the active input with the highest
priority
truth table
for an 4-2 priority encoder: a3 is
the highest priority input
inputs (a)
a3 a2 a1 a0 |
outputs (x,v)
=> x1 x0 v |
0..0..0..0
0..0..0..1 0..0..1..- 0..1..-..- 1..-..-..- |
=> X..X..0
=> 0..0..1 => 0..1..1 => 1..0..1 => 1..1..1 |
library IEEE;
use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity prenc_4to2 is port(a: in unsigned(3 downto 0); v: out std_logic; x out unsigned (1 downto 0)); end prenc_4to2; |
architecture
process_prenc_1 of
encod_4to2 is
begin process(a) variable int_a: integer range 0 to 15; begin int_a := to_integer(a); -- from IEEE.numeric_std v <='1'; case int_a is when 8 to 15 => x <= "11"; when 4 to 7 => x <= "10"; when 2 to 3 => x <= "01"; when 1 => x <= "00"; when others => v <='0'; x <="XX"; end case; end process; end process_prenc_1; |
architecture
process_prenc_2 of
encod_4to2 is
begin process(a) begin x <= "XX"; v <= '0'; for i in 3 downto 0 loop if(a(i)='1') then x <= to_unsigned(i,2); -- from IEEE.numeric_std v <= '1'; exit; end if; end loop; end process; end process_prenc_2; |