Verilog Parameter overriding -
during parameter overriding, parameter my_secret getting overridden 2.3.4.5. want impose condition overrides my_secret 2 count = 0 10, my_secret 3 count = 10 20, my_secret 4 count = 20 30, my_secret 5 count = 40 50 ?
test bench:
module tb_def_param; // inputs reg clk; reg rst; reg [4:0] a; reg [4:0] b; reg [5:0] count; parameter my_secret = 4'd0; wire [6:0] sum; initial begin // initialize inputs = 0; b = 0; clk = 1; rst = 1; // wait 100 ns global reset finish #100 rst = 1; #100 rst = 0; // add stimulus here = 5'd2; b = 5'd3; end @ (posedge clk) begin if(rst) count <= 6'd0; else count <= count + 1; end secret_number #(2) u0(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum)); secret_number #(3) u1(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum)); secret_number #(4) u2(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum)); secret_number #(5) u3(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum)); begin #10 clk <= ~clk; end endmodule
main module is:
module secret_number(clk,rst,a,b,sum); input clk, rst; input [4:0]a,b; output [6:0]sum; reg [6:0] sum; parameter my_secret = 0; always@(posedge clk) sum = + b + my_secret; initial begin $display("%d", my_secret); end endmodule
is possible ???
if understand correctly, want use count
determine value of my_secret
used in computing sum
. have of need in testbench module now, missing logic select between resulting values various secret_number
modules. have of modules driving same vector sum
should driving separate vectors , using combinational logic select desired result:
wire [6:0] sum2, sum3, sum4, sum5; reg [6:0] sum; secret_number #(2) u0(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum2)); secret_number #(3) u1(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum3)); secret_number #(4) u2(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum4)); secret_number #(5) u3(.clk(clk), .rst(rst), .a(a),.b(b),.sum(sum5)); @(*) begin if (count <= 10) begin // not sure if want inclusive of 10, if not, < sum = sum2; end else if (count <= 20) begin sum = sum3; end else if (count <= 30) begin sum = sum4; end else sum = sum5; end end
however, can have my_secret
input module rather parameter unless need use my_secret = 2
block when count greater 10 else. save amount of area if input instead.
(now also, inside module should sum <= + b + my_secret
, use nba (<=
) clocked blocks)
Comments
Post a Comment