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

Discussion in 'VHDL' started by phanhuyich, Jun 18, 2013.

  1. phanhuyich

    phanhuyich Guest

    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.
     
    phanhuyich, Jun 18, 2013
    #1
    1. Advertising

  2. phanhuyich

    valtih1978 Guest

    Re: Ask about finding maximum and second's maximum number in arrayis given.

    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;
     
    valtih1978, Jun 25, 2013
    #2
    1. Advertising

  3. phanhuyich

    Andy Guest

    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
     
    Andy, Jun 25, 2013
    #3
  4. phanhuyich

    Anssi Saari Guest

    Andy <> 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.
     
    Anssi Saari, Jun 28, 2013
    #4
  5. phanhuyich

    Andy Guest

    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
     
    Andy, Jun 28, 2013
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lord0
    Replies:
    1
    Views:
    573
    Thomas Weidenfeller
    Apr 19, 2006
  2. chiara
    Replies:
    6
    Views:
    478
    Barry Schwarz
    Oct 6, 2005
  3. 2Barter.net
    Replies:
    0
    Views:
    372
    2Barter.net
    Dec 13, 2006
  4. Casey Hawthorne
    Replies:
    385
    Views:
    5,706
    ng2010
    Apr 4, 2010
  5. yelipolok
    Replies:
    4
    Views:
    264
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page