I am trying to design a 17-bit ripple up counter using a positive edge triggered d flip flop in my design. Here is my code:
`timescale 1us/ 1ns
module upcounter (clk, pr, clr, out);
input wire clk;
input wire pr;
input wire clr;
output wire [16:0] out;
wire [16:0] fb;
wire [16:0] i_wire;
//const int n = 16;
genvar i;
//wire and1, and2;
generate
for (i = 0; i<17; i++) begin
//int j = i;
if (i == 0)begin
dff d[i] (.clk(clk),.pr_b(pr),.clr_b(clr),.d(fb[i]),.q_b(fb[i]),.q(i_wire[i]));
end else begin
dff d[i] (.clk(fb[i-1]),.pr_b(pr),.clr_b(clr),.d(fb[i]),.q_b(fb[i]),.q(i_wire[i]));
end
assign out[i] = i_wire[i];
end
endgenerate
endmodule
The code compiles without any error, but while initializing simulation it throws up a runtime fatal error saying Range width expression must be positive
, it indicates the error occurs in the following line:
dff d[i] (.clk(clk),.pr_b(pr),.clr_b(clr),.d(fb[i]),.q_b(fb[i]),.q(i_wire[i]));
How can I solve this error?
I'm using active hdl as the EDA.
I have tried using generate
and endgenerate
block.