Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

is nested for loop supported in verilog

Status
Not open for further replies.

tayyab786

Junior Member level 3
Joined
Mar 11, 2017
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
224
following code not give desired ouput
the desired output is random number having length 510,
instead of given random number it will give following pattern

Capture.PNG


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
parameter length = 8 ;   
     parameter [1:length-4] initial_state   = 4'b1101;   //for lFSR
     parameter [1:length-4] Tap_coefficient = 4'b1001;  //for LFSR
        
     output reg [1:510]chan_array = 0 ;
     reg [1:length-4]Y = initial_state ;
         
     integer Cell_ptr;
     integer Cell_ptr1;
         
         
     for (Cell_ptr1 = 1 ; Cell_ptr1 <= 510 ; Cell_ptr1 = Cell_ptr1+2) // As max available prim chan = 255
         begin            
             for (Cell_ptr =2 ; Cell_ptr <= (length-4) ; Cell_ptr = Cell_ptr+1)   //LFSR algo
                 begin
                     Y[1] <= Y[length-4];
                     Y[Cell_ptr]<= Tap_coefficient[(length-4) - Cell_ptr +1] ? Y[Cell_ptr -1]^ Y[(length-4)]: Y[Cell_ptr-1];
                 end //end inner for loop
             chan_array[Cell_ptr1] = Y[1];
             chan_array[Cell_ptr1+1] = Y[3];
         end //end top for loop

 

You probably want to read about non-blocking assignments. In this case you want Y to only use blocking assignments. IIRC, some version of Verilog or maybe SystemVerilog allow reg's to be declared local to the always block. Normally blocking assignments in clocked always blocks is discouraged as the use of the blocking assigned reg outside of that always block is not well specified.

This should synthesize to some small logic. However, I've not tested this coding style. You can also generate a state update matrix and an output matrix and then do matrix-vector multiplies. This can be done by having the matrices be wires that are assigned in for-generate, or by having them be localparams assigned by a function. The way this is done is basically the same as what you have done, just in a way that makes it more clear that small constants can be constructed. I've also seen this all done in an initial statement, but it seems some tools will remove that logic and only issue a warning.

for the matrix-vector multiply, "y[n] <= |(x & a[n])" can be useful.

https://zipcpu.com/dsp/2017/11/13/lfsr-multi.html <-- this is one example of this using the generate statement and wires.
I wrote a version that used a function and a localparam, but it is on another computer. And I tried a handful of new things out so the file is kinda ugly.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top