On 27 Jan 2005 13:43:27 -0800, "Ryan" <
[email protected]> wrote:
>I have a 1024 one-hot input that I am trying to encode. I've looked at
>examples converting the 1024 to an unsigned integer, but 2^1024 seems
>to not be working with the synthesis tool. I'm wondering if anyone has
>a good loop for encoding a one-hot number without sending the whole
>thing to an integer.
>
[...]
>I'm also concerned about going through all 1024 bits, since this will
>priority encode it, when I know the output is one-hot.
It's easy in principle; onehot-to-binary is just a tree of OR
gates for each of the 10 output bits. However, you'll make
rather a lot of OR gates... but you should get at most 10
levels of logic, probably fewer in a LUT-based
FPGA.
I think we've done this one already here.
Here's a VHDL solution (I'm sure I've posted this one before).
It makes no attempt to check that the onehot code is valid,
but from your post I guess you know that's OK already.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity coder is
port (onehot: in std_logic_vector(1023 downto 0);
binary: out std_logic_vector(9 downto 0) );
end;
architecture proc of coder is
begin
process (onehot)
variable code: std_logic_vector(binary'RANGE);
begin
code := (others => '0');
for N in onehot'RANGE loop
if onehot(N) = '1' then
code := code OR std_logic_vector(to_unsigned(N, code'LENGTH));
end if;
end loop;
binary <= code;
end process;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services
Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
[email protected]
Fax: +44 (0)1425 471573 Web:
http://www.doulos.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.