for loop and addition

OP (Company: Gidel) #4952818
1) Hi, I'm trying to write a code that looks like this
1
localparam NUM_OF_LINES = 2;
2
localparam ROWS = 2;
3

4
genvar i, j;
5

6
generate
7
  for (i = 0; i < NUM_OF_LINES; i = i+1)
8
    begin: lines_loop 
9
      for (i = 0; i < NUM_OF_ROWS; i = i+1)
10
         begin: rows_loop
11
            always @(posedge clk)
12
               data[i][j] <= prev_data [i][j];
13
        end
14
    end

ofcourse all the regs are declared.
I can't compile it when it's like that, what is the right syntax for 
loop within a loop?


2)

localparam WIDTH = 10;

How can I right an addition command with the width of the parameter?

explanation: I'm trying to do:

data <= data + 1;

when data is the width of WIDTH but I don't want it to do the addition 
with 32 bits so i tried to write "data <= data + WIDTH'h1" but it's not 
working
Moderator (Company: Titel)
Yoni C. wrote:
> I can't compile it when it's like that
What error message do you get?

> what is the right syntax for loop within a loop?
Lets go one step back: do you know, that a 'loop' in a HDL is completely 
different from a loop in C?

To keep things short: a clock inside a HDL loop is a very tricky thing. 
What hardware do you expect for that? What hardware do you want to 
"describe"? (as HDL is read "hardware DESCRIPTION language" you should 
know what hardware you want to describe...)
OP (Company: Gidel)
The messege i get:

Error (10049): Verilog HDL error at arrays.sv(20): value must not be 
assigned to nonvariable "j".

I don't realy understand the deferance between loop in c and verilog.
OP (Company: Gidel)
Lothar M. wrote:
> To keep things short: a clock inside a HDL loop is a very tricky thing.
> What hardware do you expect for that? What hardware do you want to
> "describe"? (as HDL is read "hardware DESCRIPTION language" you should
> know what hardware you want to describe...)

I want to describe assigning from the registers of "prev_data"
to the registers of "data", both of them are 2 dimention registers 
array.

Reply

A question of your own? This thread is over 9 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.