Forum Discussion

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

Looping Instructions in Altera Nios

Hai ,

How to write looping constructs like while loop in Altera NIOS?

It is giving some error in while statement .

The code is

always @(posedge clk)

begin

while (count<=10)

begin

@(posedge clk)

k=k+1;

count=count-1;

end

end

In Leonardo Spec it is working, but it is not working in Altera.

I gave the EDIF generated from Leon spec to Altera, it worked ?

Will it really work well after fusing into FPGA?

2 Replies

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

    --- Quote Start ---

    originally posted by mohana sundaram.s.v+aug 11 2005, 07:47 am--><div class='quotetop'>quote (mohana sundaram.s.v @ aug 11 2005, 07:47 am)</div>

    --- quote start ---

    in leonardo spec it is working, but it is not working in altera.[/b]

    --- quote end ---

    it&#39;s valid simulation code, but not well-designed synthesis code.

    <!--quotebegin-mohana sundaram.s.v@Aug 11 2005, 07:47 AM

    i gave the edif generated from leon spec to altera, it worked ?

    --- Quote End ---

    You have to wonder what was actually synthesized. I didn&#39;t see the types of "count" and "k" declared in there, so I assume it&#39;s manufacturing "int" variables (as opposed to "reg" variables) for you and initializing them to 0. The "count = count - 1" doesn&#39;t seem to make sense in that case, though.

    --- Quote Start ---

    originally posted by mohana sundaram.s.v@Aug 11 2005, 07:47 AM

    will it really work well after fusing into fpga?

    --- Quote End ---

    Only way to be sure would be to build the chip and run it through the Altera simulator.

    I wonder what you&#39;re trying to create here. It looks like a counter, which would be just:

    reg  count;
    always @(posedge clk, posedge reset)
      if(reset)
        count <= 0;
      else if(count <= 10)
        count <= count + 1;

    In general, you should only have @ events show up once after "always" and never within the begin...end block. Bear in mind that Verilog started life as a simulation language, not a synthesis language, and because of that it looks too much like a sequential programming language like C, which tends to lose the simultaneity of hardware design.

    I recommend you obtain the book advanced digital design with the verilog hdl, ISBN 0-13-089161-4.