-- ############################################################################ -- # Project : Leonardo CBT-Kernel # -- # # -- # Filename : encoders_decoders.vhd # -- # # -- # Component : encN : N-bit MSB-priority encoder. When no input # -- # is asserted the module is 1(0...), where # -- # the number of '0's is log2(N). # -- # # -- # Model : rtl # -- # # -- # Designer : S. Theoharis,N. Zervas # -- # Institute : VLSI Design Lab., University of Patras # -- # Date : 01.05.1999 # -- ############################################################################ library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use work.useful_functions.all; -- encN Entity Description entity encN is generic(N: INTEGER := 4); port( DIN: in unsigned(N-1 downto 0); DOUT: out unsigned(log2(N)-1 downto 0) ); end encN; -- encN Architecture Description architecture rtl of encN is begin PRIORITY_ENCODER_Process: process(DIN) VARIABLE DOUT_int: integer range 0 to N-1; BEGIN DOUT_int := 0; -- for the case that no '1' exists in DIN FOR i IN 0 TO N-1 LOOP IF DIN(i) = '1' THEN -- priority the lowest DIN(i) equal to '1' DOUT_int := i; exit; END IF; END LOOP; DOUT <= Conv_Unsigned(DOUT_int, log2(N)); end process PRIORITY_ENCODER_Process; end rtl;