I'm working on a binary decoder and am trying to parameterize the address size. It is a project requirement that this be made in gate level verilog.
Is there a way to generate the i[k] statements in the second generate statement based on ADDR_SIZE?
module Decoder #(
parameter ADDR_SIZE = 5
)(
out,
in
);
input wire [ADDR_SIZE-1:0] in;
output wire [(2**ADDR_SIZE)-1:0] out;
wire [ADDR_SIZE-1:0] code, codeNot;
genvar j;
generate
for (j = 0; j < ADDR_SIZE; j = j + 1)
begin : bufs
buf (code[j], in[j]);
not(codeNot[j], in[j]);
end
endgenerate
genvar i;
generate
for (i = 0; i < (2**ADDR_SIZE); i = i + 1)
begin : selects
and (out[i],
i[0] ? codeNot[0] : code[0],
i[1] ? codeNot[1] : code[1],
i[2] ? codeNot[2] : code[2],
i[3] ? codeNot[3] : code[3],
i[4] ? codeNot[4] : code[4],
);
end
endgenerate
endmodule
So if ADDR_SIZE = 4, the only thing that would change would be:
and (out[i],
i[0] ? codeNot[0] : code[0],
i[1] ? codeNot[1] : code[1],
i[2] ? codeNot[2] : code[2],
i[3] ? codeNot[3] : code[3]
);
Or if ADDR_SIZE = 6
and (out[i],
i[0] ? codeNot[0] : code[0],
i[1] ? codeNot[1] : code[1],
i[2] ? codeNot[2] : code[2],
i[3] ? codeNot[3] : code[3],
i[4] ? codeNot[4] : code[4],
i[5] ? codeNot[5] : code[5]
);
Since its a decoder, I'm accepting a binary input of 2^ADDR_SIZE (default to 5). Depending on what the input binary value is, the corresponding output line would be driven high, so if in = 5'b00001, out = 32'b...0000001 (dots are all zeros. only least significant bit is high). If in = 5'b00011, out = 32'b...0000100.
That part has been done and works with a 5 bit address in the following code. I'm now trying to make it so that if I set ADDR_SIZE = 4, my input is now 4'b and my output is now 16'b. Most of this works, and each output line is just an AND of either in or inNot depending on the place.
After all this generated code is taken out, I'm essentially asking how I can do the following. Again, its important this be done in Structural Verilog.
parameter ADDR_SIZE = 5
generate . . .
and(out, a, b, c, d, e);
endgenerate
parameter ADDR_SIZE = 3
generate . . .
and(out, a, b, c);
endgenerate
parameter ADDR_SIZE = 6
generate . . .
and(out, a, b, c, d, e, f);
endgenerate
i)? I'm guessing a nested generate loop may be needed.