Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Ask about finding maximum and second's maximum number in array is given.

Reply
Thread Tools

Ask about finding maximum and second's maximum number in array is given.

 
 
phanhuyich
Guest
Posts: n/a
 
      06-18-2013
I am starting to study VHDL. Now, I have to do an exercise with the following content:

I have to define an array of 10 elements ( 8 bit range) ([3,4,2,8,9,0,1,5,7,6] for example). And 10 elements were imported to within 10 clock cycles. The question is find the maximum number and second maximum number in this array after 10 clock cycle.
Anyone help to show me the method to solve it using VHDL ?

Thank you.
 
Reply With Quote
 
 
 
 
valtih1978
Guest
Posts: n/a
 
      06-25-2013
Here is the computation of the max

process
variable max: integer := Integer.Minimum;
begin
for I in 1 to 10 loop
wait until clk = '1';
if (input > max)
max := input;
end if;
end loop;
report "max = " & integer'image(max);
end process;

I am sure, you can extend it to the pre-max variable by something like
if (input > max)
premax := max;
max := input;
end if;

 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      06-25-2013
Your premax solution only works if the highest value occurs in the input stream after the 2nd highest value, and the 2nd highest value does not have the same value as the highest value.

You need a separate comparison of input and premax. That means premax needs initialization too.

Process variables are only initialized at time zero; when the implied process loop (not the loop statement) repeats, the variable is not re-initialized.

In all fairness though, the OP did not state he needed a synthesizable solution.

Andy
 
Reply With Quote
 
Anssi Saari
Guest
Posts: n/a
 
      06-28-2013
Andy <(E-Mail Removed)> writes:

> Your premax solution only works if the highest value occurs in the input stream after the 2nd highest value, and the 2nd highest value does not have the same value as the highest value.
>
> You need a separate comparison of input and premax. That means premax needs initialization too.
>
> Process variables are only initialized at time zero; when the implied process loop (not the loop statement) repeats, the variable is not re-initialized.
>
> In all fairness though, the OP did not state he needed a synthesizable solution.


Didn't he mention a clock cycle limit of 10 though? So it slightly hints
towards synthesizable. Or at least synchronous.

Another solution is of course sorting the array and taking the two
largest values. I'd do that if this were a real problem and there were
some doubt that maybe it's not the two largest but perhaps the fourth or
seventh largest value I need... Or the median for that matter.
 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      06-28-2013

The OP said; "And 10 elements were imported to within 10 clock cycles". That is not the same as "only 10 clocks will be provided".

What does the model do on the 11th and following clock cycles?

Andy
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Days in a given date range for a given month......... Lord0 Java 1 04-19-2006 04:54 PM
Creating the maximum number of menus and maximum number of stills rossco DVD Video 2 11-24-2005 09:33 PM
generate all possible strings of given length given a set of characters chiara C Programming 6 10-06-2005 01:43 AM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net Web Controls 2 07-16-2004 05:14 PM
The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum is 3. mayur ASP .Net 2 07-02-2004 10:35 AM



Advertisments