Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - N_bit decoder/encoder

 
Thread Tools Search this Thread
Old 12-03-2003, 10:54 PM   #1
Default N_bit decoder/encoder


How can I implement N-bit decoder (encoder?) (I mean 001 => 00000001, 010 =>
00000010, 011 => 00000100, 111 => 10000000...), where N is a parameter?
It's quite easy with integer signal on input but I have bit_vector.




Gietek
  Reply With Quote
Old 12-04-2003, 12:55 AM   #2
valentin tihomirov
 
Posts: n/a
Default Re: N_bit decoder/encoder
Have you looked into design templates? In addition, here is mine:

process
O <= (others => '0');
O(code) <= '1';
end;




valentin tihomirov
  Reply With Quote
Old 12-04-2003, 09:08 AM   #3
Joerg Ritter
 
Posts: n/a
Default Re: N_bit decoder/encoder
Gietek wrote:
> How can I implement N-bit decoder (encoder?) (I mean 001 => 00000001, 010 =>
> 00000010, 011 => 00000100, 111 => 10000000...), where N is a parameter?
> It's quite easy with integer signal on input but I have bit_vector.
>
>

try an recursive approach with generate-statements.

dec(1) ~ feed trough / inverter
dec(n) ~ dec(n/2) + ...

j



Joerg Ritter
  Reply With Quote
Old 12-04-2003, 02:02 PM   #4
Nicolas Matringe
 
Posts: n/a
Default Re: N_bit decoder/encoder
Joerg Ritter a écrit:
> Gietek wrote:
>
>> How can I implement N-bit decoder (encoder?) (I mean 001 => 00000001,
>> 010 =>
>> 00000010, 011 => 00000100, 111 => 10000000...), where N is a parameter?
>> It's quite easy with integer signal on input but I have bit_vector.
>>
>>

> try an recursive approach with generate-statements.
>
> dec(1) ~ feed trough / inverter
> dec(n) ~ dec(n/2) + ...
>
> j
>


....
nn : in std_logic_vector(a downto 0); -- a = log2(n)
output : out std_logic_vector(n downto 0);
....
output <= ((to_integer(unsigned(nn)) => '1', others => '0');
....

(quite similar to V. Tihomirov's approach )

Nicolas



Nicolas Matringe
  Reply With Quote
Old 12-04-2003, 03:20 PM   #5
Charles M. Elias
 
Posts: n/a
Default Re: N_bit decoder/encoder
"Gietek" <> wrote in message news:<bqlpmc$fvu$>...
> How can I implement N-bit decoder (encoder?) (I mean 001 => 00000001, 010 =>
> 00000010, 011 => 00000100, 111 => 10000000...), where N is a parameter?
> It's quite easy with integer signal on input but I have bit_vector.


Here is something close to what you want, I think. It using
std_logic_vector inputs, not bit_vector, but it should be easy to
adapt it for your needs. The output codes are arbitrary and not the
ones you want--again easily changed.

--================================================== ============================
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.numeric_std.all;
--================================================== ============================
ENTITY LookUp IS
GENERIC ( addr_width : natural := 3;
tout_width : natural := 12 );
PORT ( addr : in std_logic_vector( addr_width - 1 downto 0 );
tout : out std_logic_vector( tout_width - 1 downto 0
));
END LookUp;

ARCHITECTURE archlookup OF lookup IS


subtype tablerng is natural range 0 to 2**addr_width - 1;
type ttable is array( tablerng ) of std_logic_vector( tout_width -
1 downto 0 );

constant table : ttable := ( "000000100000", --0
"000000100001", --1
"000000100010", --2
"000000100011", --3
"000000100100", --4
"000000100101", --5
"000000100110", --6
"000000100111" ); --7


BEGIN

tout <= table( to_integer( unsigned( addr ) ) );

END archlookup;


Charles M. Elias
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46