n_by_m_encoder

K

krby_xtrm

Guest
i'm creating a n_by_m encoder such that m = log2(n)
so that it will be set based only on 'n' inside generic...
see skeleton code below:

----------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.math_complex.all;

entity encoder is
generic( n : integer := 8);
port(
x : in STD_LOGIC_VECTOR(n-1 downto 0);
y : out STD_LOGIC_VECTOR(log2(n)-1 downto 0) -- << here <<
);
end encoder;

--}} End of automatically maintained section

architecture encoder of encoder is
begin

-- enter your statements here --

end encoder;
----------------------------------------------------
 
A simple code coude be using a for loop

for i in 0 to n-1 loop
if(x(i) = '1') then
y <= conv_std_logic_vector(i,log2(n));
end if;
end loop;

This shud explain the logic, although I dont know if this is optimal.

Sudhi
 
no, i mean in the port(<>) assignments, will that loop be in this:
y: out STD_LOGIC_VECTOR(??? downto 0); such that ??? is log2(n)-1
 
no, i mean in the port(<>) assignments, will that loop be in this:
y: out STD_LOGIC_VECTOR(??? downto 0); such that ??? is log2(n)-1
 
no, i mean in the port(<>) assignments, will that loop be in this:
y: out STD_LOGIC_VECTOR(??? downto 0); such that ??? is log2(n)-1
 
Instead of taking in 'n' through the generic, take in log2(n) through
the generic, getting 'n' then is simple,
say u declare "datawidth :integer 3" in your generic, then your entity
wud be
x : std_logic_vector(2**datawidth-1 downto 0);
y : std_logic_vector(datawidth-1 downto 0);

Sudhi
 

Welcome to EDABoard.com

Sponsor

Back
Top