Forum Discussion

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

lpm functions and hdl

Hi all,

So I'm trying to create a (synchronous) 8-bit loadable counter, as below but for some reason this synthesizes to around 28 LE's compared to the altera LPM 11 LE version. Any idea why?

Thanks!

-Mux

module register8 (

clk,

clken,

reset_n,

data,

load,

cnt_en,

updown,

q,

q_next

);

input clk;

input clken;

input reset_n;

input [7:0] data;

input load;

input cnt_en;

input updown;

output [7:0] q, q_next;

reg [7:0] addsub;

always @(*)

if ( updown )

addsub = q - 8'd1;

else

addsub = q + 8'd1;

// asynchronous 'next' value. This is used extensively for flags

reg [7:0] q, q_next;

always @(*)

if ( load )

q_next = data;

else

begin

if ( cnt_en )

q_next = addsub;

else

q_next = q;

end

always @(posedge clk or negedge reset_n )

if ( !reset_n )

q <= 8'd0;

else if ( clken )

q <= q_next;

endmodule

12 Replies

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

    Yes and no :-) If you choose an LPM_ADDSUB the cost for the lpm function goes to 16+ LE's whereas the counter comes in as 8LE's + 8LUT's. So what's the best way to synthesize and up/down counter without +/-? Anyone know?

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

    Hi ,

    Most likely cause would be due to the use of the +/- operators.

    -Abr