Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12745 Discussions

Looping Instructions in Altera Nios

Altera_Forum
Honored Contributor II
1,185 Views

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?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
441 Views

You code isn&#39;t able to be synthesised.

0 Kudos
Altera_Forum
Honored Contributor II
441 Views

 

--- 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.
0 Kudos
Reply