Guest
Hi all,
I am trying to write a code where parameter 'approx' can be changed from outside of the module RCA1.
Default value of approx is zero. If it is greater than zero then RCA1 module will go through 2 different types of for loops and create module instance name accordingly.
If I run this code It says rr block name is already defined. If I change the block name for 2 different for loop then no syntax error generates but if I try to see the schematic view then nothing appears.
Please help me with this situation.
Thanks
............................
module tb1;
parameter n=3;
reg [n:0] a,b;
reg c,approx;
wire [n+1:0] s;
RCA1 #(.approx(1)) rca1(a,b,c,s);
endmodule
.................................................
module FA(a,b,cin,s,cout);
input a,b,cin;
output s,cout;
assign s=a^b^cin;
assign cout=(a&b)|(b&cin) | (a&cin);
endmodule
module RCA1(p,q,ci,r);
input [3:0] p,q;
input ci;
output [4:0] r;
parameter approx=0;
wire [4:0] carry;
assign carry[0]=ci;
genvar i;
genvar j;
generate
for (i=0;i<approx;i=i+1) begin: rr
FA fa(p,q,carry,r,carry[i+1]);
end
for (j=approx;j<4;j=j+1) begin: rr
FA fa(p[j],q[j],carry[j],r[j],carry[j+1]);
end
endgenerate
assign r[4]=carry[5];
endmodule
I am trying to write a code where parameter 'approx' can be changed from outside of the module RCA1.
Default value of approx is zero. If it is greater than zero then RCA1 module will go through 2 different types of for loops and create module instance name accordingly.
If I run this code It says rr block name is already defined. If I change the block name for 2 different for loop then no syntax error generates but if I try to see the schematic view then nothing appears.
Please help me with this situation.
Thanks
............................
module tb1;
parameter n=3;
reg [n:0] a,b;
reg c,approx;
wire [n+1:0] s;
RCA1 #(.approx(1)) rca1(a,b,c,s);
endmodule
.................................................
module FA(a,b,cin,s,cout);
input a,b,cin;
output s,cout;
assign s=a^b^cin;
assign cout=(a&b)|(b&cin) | (a&cin);
endmodule
module RCA1(p,q,ci,r);
input [3:0] p,q;
input ci;
output [4:0] r;
parameter approx=0;
wire [4:0] carry;
assign carry[0]=ci;
genvar i;
genvar j;
generate
for (i=0;i<approx;i=i+1) begin: rr
FA fa(p,q,carry,r,carry[i+1]);
end
for (j=approx;j<4;j=j+1) begin: rr
FA fa(p[j],q[j],carry[j],r[j],carry[j+1]);
end
endgenerate
assign r[4]=carry[5];
endmodule