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.

Need help with syntax for replicator in Verilog

Status
Not open for further replies.

Dasco

Junior Member level 2
Joined
Jul 21, 2008
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,435
I wanna replicate every bit of the input and write it all out
something like this :




Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
module (input, output);
    wire input [n+1: 0];
    parameter  M ; // replicating factor
    parameter n; // the width of the input
    wire output [M*(n+1) :0]; 
    integer i ;
        initial begin
              for(i = 0; i < n ; i = i + 1) 
    assign output [(n*M)+7: (n*M)]  = M {input[n]} ;
    end 
    endmodule





but I am missing the right syntax

any help??

thanks in advance!!
 
Last edited by a moderator:

replication can be done using {M{N}} =>NNNN(for M times). for ex {3{4}} -> 444
 

As an additional remark, the part select output [(n*M)+7: (n*M)] is no valid Verilog syntax. Either use a bit select with an additional bit iteration loop or indexed part select syntax as shown below. Refer to the Verilog specification or your preferred text book for details.

Code:
reg [15:0] big_vect;
reg [0:15] little_vect;

big_vect[lsb_base_expr +: width_expr]
little_vect[msb_base_expr +: width_expr]
big_vect[msb_base_expr -: width_expr]
little_vect[lsb_base_expr -: width_expr]

Furthermore, some variable width expressions in the example obviously need recalculation.
 

As an additional remark, the part select output [(n*M)+7: (n*M)] is no valid Verilog syntax. Either use a bit select with an additional bit iteration loop or indexed part select syntax as shown below. Refer to the Verilog specification or your preferred text book for details.

Code:
reg [15:0] big_vect;
reg [0:15] little_vect;

big_vect[lsb_base_expr +: width_expr]
little_vect[msb_base_expr +: width_expr]
big_vect[msb_base_expr -: width_expr]
little_vect[lsb_base_expr -: width_expr]

Furthermore, some variable width expressions in the example obviously need recalculation.



that is exactly the obstacle
What I want to do is :
assign output [M*n : 0] = append (M*input[n], M*input[n-1]....................., M*input[0] )
how should i define this??

I know how to do it if i give M and N values but I do not know how to do it with parameters
where should i start??
thanks in advance
 

A simple construct that works with a minimum of special Verilog syntax
Code:
for(i = 0; i < n ; i = i + 1) 
  for(j = 0; j < M ; j = j + 1) 
    output[i*M+j] = input[i];
 

A simple construct that works with a minimum of special Verilog syntax
Code:
for(i = 0; i < n ; i = i + 1) 
  for(j = 0; j < M ; j = j + 1) 
    output[i*M+j] = input[i];
so in my case it would be something like :


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module (input, output);
wire input [n+1: 0];
parameter M ; // replicating factor
parameter n; // the width of the input
wire output [M*(n+1) :0];
integer i, j ;
initial begin
 
for(i = 0; i < n ; i = i + 1) 
  for(j = 0; j < M ; j = j + 1) 
     = input[i];
assign  output[i*M+j] = M {input[i]} ;
end
endmodule


right?

i will try it and get back to you
thanks in advance
 
Last edited by a moderator:

so in my case it would be something like
No, I meaned the code as is. Your's is involving various syntax errors.

As previously mentioned, the definitions of wire input and output should be corrected to give the inteded number of bits.
 

No, I meaned the code as is. Your's is involving various syntax errors.

As previously mentioned, the definitions of wire input and output should be corrected to give the inteded number of bits.

what do you mean ?
should i use reg instead of wire??
 

Yes, or assign in a generate loop. Your tool will tell you about incorrect syntax.
 

Yes, or assign in a generate loop. Your tool will tell you about incorrect syntax.

I did assign it in the 2d loop
i have to look into the generate thing
any example?
thanks
 

Same point as before: If you're not aware of the generate syntax, why don't you use a regular for loop with a reg variable. They all compile to the same gate level code.
 

Same point as before: If you're not aware of the generate syntax, why don't you use a regular for loop with a reg variable. They all compile to the same gate level code.

something like this :

Code:
module (input, output);
reg input [n+1: 0];
parameter M ; // replicating factor
parameter n; // the width of the input
reg output [M*(n+1) :0];
integer i, j ;
initial begin
 
for(i = 0; i < n ; i = i + 1) 
  for(j = 0; j < M ; j = j + 1) 
     = input[i];
assign  output[i*M+j] = M {input[i]} ;
end
endmodule
am i right?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top