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

Reply

VHDL - Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)

 
Thread Tools Search this Thread
Old 06-28-2006, 12:09 AM   #1
Default Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)


hello all. Big time newbie here.

Hardware: Cyclone
Software: Quartus II
Problem: I have to implement a lookup table of sorts and I have no
idea what I'm doing.

A counter is counting the duration of an external event. When the
event ends I need to take the final count and retreive a value from a
lookup table and assign it to another variable.

A) I assume I will use the 'table' construct. but what if the table
is huge?
B) It's a 24bit counter so the possilbe values are quite large. The
table will contain the same value for large ranges of counts. I.E. if
count is anywhere between 10 and 100 the lookup value is the same. Is
there a way to minimize the table so that I only have to list index
ranges? In other words it would be nice if the index isn't found, to
take the 'nearest' index.
C) Is there some entirely different way to code the lookup table?

Thanks in advance for any help you can give,
Shannon


Shannon
  Reply With Quote
Old 06-28-2006, 08:23 AM   #2
Thomas Stanka
 
Posts: n/a
Default Re: Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)

Hello,
Shannon schrieb:
> Problem: I have to implement a lookup table of sorts and I have no
> idea what I'm doing.
>
> A counter is counting the duration of an external event. When the
> event ends I need to take the final count and retreive a value from a
> lookup table and assign it to another variable.
>
> A) I assume I will use the 'table' construct. but what if the table
> is huge?


Then you need more devices to fit the table in *g*

> B) It's a 24bit counter so the possilbe values are quite large. The
> table will contain the same value for large ranges of counts. I.E. if
> count is anywhere between 10 and 100 the lookup value is the same. Is
> there a way to minimize the table so that I only have to list index
> ranges? In other words it would be nice if the index isn't found, to
> take the 'nearest' index.
> C) Is there some entirely different way to code the lookup table?


You need to google for "hash".
I guess a hash function and a small table will suit.
Another way would be something like

signal cnt : integer range 0 to 2**24-1;
....
process
....
case cnt is
when 0-9 =>....
when 10-100 => ....
when others => ...
end case

bye Thomas

  Reply With Quote
Old 06-28-2006, 02:00 PM   #3
Ricardo
 
Posts: n/a
Default Re: Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)

Hello

You may want a "ROM". You can use for-generate (as many as your
intervals) to build the table. Also you must have a classical memory
signal (an array-type of std_logic_vector, for example) to do this.
Your counter generates the address, the output is your value.

If your device has memory blocks, you may use them. I do not now about
Altera, but xilinx block-ram probably would do the job. For xilinx, a
"data out" must receive a value according to the address (in this case,
your counter). If this is synchronous to a clock, then you probably is
using a block ram, else you will use distributed.

Can't tell about altera ram usage.

Regards,

Ricardo


Shannon escreveu:

> hello all. Big time newbie here.
>
> Hardware: Cyclone
> Software: Quartus II
> Problem: I have to implement a lookup table of sorts and I have no
> idea what I'm doing.
>
> A counter is counting the duration of an external event. When the
> event ends I need to take the final count and retreive a value from a
> lookup table and assign it to another variable.
>
> A) I assume I will use the 'table' construct. but what if the table
> is huge?
> B) It's a 24bit counter so the possilbe values are quite large. The
> table will contain the same value for large ranges of counts. I.E. if
> count is anywhere between 10 and 100 the lookup value is the same. Is
> there a way to minimize the table so that I only have to list index
> ranges? In other words it would be nice if the index isn't found, to
> take the 'nearest' index.
> C) Is there some entirely different way to code the lookup table?
>
> Thanks in advance for any help you can give,
> Shannon


  Reply With Quote
Old 06-29-2006, 03:57 PM   #4
Andy
 
Posts: n/a
Default Re: Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)

You may be able to use only the upper bits of the counter.

case counter / 2**16 is -- take the upper 8 bits (24 -16)
when 0-9 =>
var := this;
when 10-100 =>
var := that;
when others =>
var := the_other;
end case;

Andy

Thomas Stanka wrote:
> Hello,
> Shannon schrieb:
> > Problem: I have to implement a lookup table of sorts and I have no
> > idea what I'm doing.
> >
> > A counter is counting the duration of an external event. When the
> > event ends I need to take the final count and retreive a value from a
> > lookup table and assign it to another variable.
> >
> > A) I assume I will use the 'table' construct. but what if the table
> > is huge?

>
> Then you need more devices to fit the table in *g*
>
> > B) It's a 24bit counter so the possilbe values are quite large. The
> > table will contain the same value for large ranges of counts. I.E. if
> > count is anywhere between 10 and 100 the lookup value is the same. Is
> > there a way to minimize the table so that I only have to list index
> > ranges? In other words it would be nice if the index isn't found, to
> > take the 'nearest' index.
> > C) Is there some entirely different way to code the lookup table?

>
> You need to google for "hash".
> I guess a hash function and a small table will suit.
> Another way would be something like
>
> signal cnt : integer range 0 to 2**24-1;
> ...
> process
> ...
> case cnt is
> when 0-9 =>....
> when 10-100 => ....
> when others => ...
> end case
>
> bye Thomas


  Reply With Quote
Old 06-30-2006, 02:40 PM   #5
Shannon
 
Posts: n/a
Default Re: Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)

Thanks everyone. I knew I'd get some great answers!

I think there would be too many (hundreds) of case statements to use
that method however.

I guess I'll have to keep digging. There must be a way to write some
logic to find the nearest value. Something like:

Find index where index<count and next index>count then take the value
at table(next index).

or the HDL equivalent of:

temp=count
while notFound
index==temp++
end while
result=table(temp)


On Tue, 27 Jun 2006 16:09:52 -0700, Shannon
<lglcc-> wrote:

>hello all. Big time newbie here.
>
>Hardware: Cyclone
>Software: Quartus II
>Problem: I have to implement a lookup table of sorts and I have no
>idea what I'm doing.
>
>A counter is counting the duration of an external event. When the
>event ends I need to take the final count and retreive a value from a
>lookup table and assign it to another variable.
>
>A) I assume I will use the 'table' construct. but what if the table
>is huge?
>B) It's a 24bit counter so the possilbe values are quite large. The
>table will contain the same value for large ranges of counts. I.E. if
>count is anywhere between 10 and 100 the lookup value is the same. Is
>there a way to minimize the table so that I only have to list index
>ranges? In other words it would be nice if the index isn't found, to
>take the 'nearest' index.
>C) Is there some entirely different way to code the lookup table?
>
>Thanks in advance for any help you can give,
>Shannon

  Reply With Quote
Old 06-30-2006, 06:10 PM   #6
Mike Treseler
 
Posts: n/a
Default Re: Newbie strugling with a lookup (look-up) table in VHDL (or AHDL)

Shannon wrote:

> I think there would be too many (hundreds) of case statements to use
> that method however.


If there are hundreds of bins, they have to be described somehow.
A big case statement is as good a way as any unless the function
is known.

I would declare the function to start with:

subtype rom_adr_t is unsigned(8 downto 0); -- hundreds of bins
subtype count_t is unsigned(23 downto 0); -- millions of counts

function count2bins (arg_cnt : count_t)
return bin_t; -- bin 0 to 511


-- Mike Treseler
  Reply With Quote
Old 05-13-2007, 12:25 PM   #7
amirster
Junior Member
 
Join Date: May 2007
Posts: 4
Default

Hello
I will be very happy to know if u found a way to do ur lookup table without the case statment or with a better way like to found the nearest value ?
I have the same problem here, I need to build a look up table just like urs I.E. if count is anywhere between 10 and 100 the lookup value is the same.

P.S:* sorry about my english
* I am a beggner in programming vhdl
amirster is offline   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
Forum Jump