Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

how to increase frequency

Hi,

I have written a code in Verilog and its frequency is comming out to be 28MHz only for Cyclone EPC6Q240C8 device.

The place where frequency drops is Average Calculation.

I have 3 registers 24bit each.

Say,

reg1 [23:0]

reg2 [23:0]

reg3 [23:0]

each of these registers contain 8 bit data. And I need to calculate the average of these nos.

So, how I am doing is:

//---------------------------------------------------------

always block 1

sum1 <= reg1[23:16] + reg1[15:8] + reg1[7:0];

sum2 <= reg2[23:16] + reg2[15:8] + reg2[7:0];

sum3 <= reg3[23:16] + reg3[15:8] + reg3[7:0];

always block 2

sum4 <= sum1 + sum2 + sum3;

always block 3

average <= (my conditions)? sum4 / 9 : average;

average_valid <= (my conditions)? 1'b1 : 1'b0;

//---------------------------------------------------------

Simply by eleminating this part of code, the frequency of my design shoots to 70MHz.

So, please can anyone provide me with an alternative approach to calculate the average without compromising with the frequency.

Thank you,

-Amit

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    truncating 3 bits(instead of explicit division):

    for 8 values average you need to divide the sum by 8 i.e. 2^3 so all you have to do is discard the 3 LSBs from sum4.

    using mult instead of divide(since dividers can be slower than multipliers):

    to divide by 9, final sum = sum4/9 = sum4 * 57/512

    i.e. multiply sum4 by 57 then discard 9 bits off final result.

    The value 57 is derived from 512/9

    you can and should use more bits for more accuracy:

    final sum = sum4 * 3641/32768 then discard 15 bits
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I don't see the design is completely pipelined. all statements involving three additions can be further pipelined e.g.

    --- Quote End ---

    Yes, that's true. I assumed however, that two 12-Bit additions in a cycle won't be an issue for 48 MHz.

    Average of 9 needs a divider or a approximation by integer multiply/shift. But with Cyclone, the integer multiply is converted to multiple additions and may cause timing problems as well. Alternatively, the divider can be pipelined, using a MegFunction. Cause dividers are resource consuming, I generally use a serial divider, where ever applicable. It e. g. takes 4 cycles for a /9 division.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    truncating 3 bits(instead of explicit division):

    for 8 values average you need to divide the sum by 8 i.e. 2^3 so all you have to do is discard the 3 LSBs from sum4.

    using mult instead of divide(since dividers can be slower than multipliers):

    to divide by 9, final sum = sum4/9 = sum4 * 57/512

    i.e. multiply sum4 by 57 then discard 9 bits off final result.

    The value 57 is derived from 512/9

    you can and should use more bits for more accuracy:

    final sum = sum4 * 3641/32768 then discard 15 bits

    --- Quote End ---

    //------------------------------------------------------------

    hey thanx everyone ......

    the multiplication funda worked for me ....... multiplying the sum by 57 and then discarding the lsb 9 bits, frequency almost increased to 3 times ...... the design is now at 80MHz.

    cheers

    -amit garg