马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 luoyanghero 于 2020-10-3 16:47 编辑
//How use $random with seed? //This is the verilog standard documentdiscription: //The seed argument controls the numbers that$random returns so that different seeds generate different random streams. Theseed argument shall be an integral variable. The seed value should be assignedto this variable prior to calling $random.
//I did a test.
- `ifndef DLY
- `define DLY 1
- `endif
- module tb_top;
- reg clk_bus;
- reg brst_n;
- reg [31:0] frame_cnt;
- reg [31:0] cnt;
- initial begin
- brst_n = 1'b1;
- #1;
- brst_n = 1'b0;
- #100;
- brst_n = 1'b1;
- #1000000000;
- //$finish;
- end
- initial begin
- clk_bus = 1'b0;
- forever #5 clk_bus = ~clk_bus;
- end
- always @ (posedge clk_bus or negedge brst_n) begin
- if (~brst_n)
- cnt[31:0] <= #`DLY 'd0;
- else
- cnt[31:0] <= #`DLY cnt + 1;
- end
- always @ (posedge clk_bus or negedge brst_n) begin
- if (~brst_n)
- frame_cnt[31:0] <= #`DLY 32'd0;
- else if (cnt==1000)
- frame_cnt[31:0] <= #`DLY frame_cnt + 1;
- end
- integer end_dly;
- initial begin
- end_dly = 1;
- while (1) begin
- @(posedge clk_bus);
- if (cnt==1001) begin
- #`DLY end_dly = $random(frame_cnt[7:0]);//luoy why random seed(frame_cnt[7:0]) be force changed?
- end
- end
- end
- initial begin
- //wait ((in_data_drv.frm_cnt == 1) && (in_data_drv.mb_y_cnt == 90));
- $fsdbDumpfile("tb_top.fsdb");
- $fsdbDumpvars(tb_top, 0);
- end
- endmodule
复制代码
//frame_cnt be force changed from 32'h1 to 32'hce.
|