EmbDev.net

Forum: FPGA, VHDL & Verilog for loop and addition


von Yoni C. (Company: Gidel) (yonico12344)


Rate this post
useful
not useful
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

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
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...)

: Edited by Moderator
von Yoni C. (Company: Gidel) (yonico12344)


Rate this post
useful
not useful
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.

von Duke Scarring (Guest)


Rate this post
useful
not useful
Yoni C. wrote:
> for (i = 0; i < NUM_OF_LINES; i = i+1)
> ...
>       for (i = 0; i < NUM_OF_ROWS; i = i+1)
Where is j used?

von Yoni C. (Company: Gidel) (yonico12344)


Rate this post
useful
not useful
sorry, ofcourse the second for loop is with j

von Dussel (Guest)


Rate this post
useful
not useful
Yoni C. wrote:
> Error (10049): Verilog HDL error at arrays.sv(20): value must not be
> assigned to nonvariable "j".
Which line is line 20?

von Yoni C. (Company: Gidel) (yonico12344)


Rate this post
useful
not useful
Dussel wrote:
> Which line is line 20?

for (j = 0; j < NUM_OF_ROWS; j = j+1)

von Yoni C. (Company: Gidel) (yonico12344)


Rate this post
useful
not useful
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.

: Edited by User
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.