1

My module has a configurable width input of signals sensor_line[WIDTH-1:0] where WIDTH is parameter. For each sensor_line I have a recorder module instantiated with a generate block in a for loop. I need to pass a decimal number parameter to this recorder which is different for each sensor_line.

I need to create some decimal array parameter to give to my module in the top, which it’s width will be aligned with the WIDTH parameter. I don’t mind if I need to match the given array size myself as long as I can do it from the top when instantiating my module.

Looking for a solution, I found only for passing an array of bits (binary value). For example, to pass 5 bits for each sensor_line, a code like this can be used:

module my_module #(
    parameter WIDTH = 4,    // number of input lines
    parameter [4:0] CYCELS [WIDTH-1:0] = '{ WIDTH{5'b0}}
)
(
    Input clk;
input [WIDTH-1:0] sensor_line;
…
);
logic [WIDTH-1:0] sensor_line_out;
…
genvar i;
generate
for (i=0; i< WIDTH; i=i+1) begin : sensor_sync
        recorder #(
            . CYCELS(CYCELS [(i+1)*5:i*5])
        )
        recorder_instance(
            .in(sensor_line[i]),
            .out(sensor_line_out[i]),
            .clk(clk),
            …
        );
    end
endgenerate
…

endmodule

How can I pass decimal values to the recorder module, not bits like in the example, like passing integer array in C and then point to the array at index [i] and at the end instance my module like this:

my_module #(
    .WIDTH(4),  // number of input lines
    .CYCELS([2,3,5,4])
) my_module_1 (
...
)

my_module #(
    .WIDTH(3),  // number of input lines
    .CYCELS([3,2,2])
) my_module_2 (
...
)

1 Answer 1

0

The syntax you used to pass an array of decimal values is incorrect. For example, change:

.CYCELS([2,3,5,4])

to:

.CYCELS('{2,3,5,4}) // an assignment pattern

or

.CYCELS({2,3,5,4})  // an unpacked array concatenation 

Here is actual code that compiles:

module my_module #(
    parameter WIDTH = 4,    // number of input lines
    parameter [4:0] CYCELS [WIDTH-1:0] = '{default:'0}
);

for (genvar i=0; i< WIDTH; i++) begin : sensor_sync
    initial $display("%m CYCELS[%0d]=%0d", i, CYCELS[i]);
end

endmodule


module top;

my_module #(
    .WIDTH(4),  // number of input lines
    .CYCELS('{2,3,5,4})
) my_module_1 (
);

my_module #(
    .WIDTH(3),  // number of input lines
    .CYCELS('{3,2,2})
) my_module_2 (
);

endmodule

Output:

top.my_module_1.sensor_sync[0] CYCELS[0]=4
top.my_module_1.sensor_sync[1] CYCELS[1]=5
top.my_module_1.sensor_sync[2] CYCELS[2]=3
top.my_module_1.sensor_sync[3] CYCELS[3]=2
top.my_module_2.sensor_sync[0] CYCELS[0]=2
top.my_module_2.sensor_sync[1] CYCELS[1]=2
top.my_module_2.sensor_sync[2] CYCELS[2]=3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.