From 783c33e2685c06e4f1d95ffef3c29585b2a01ca7 Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov Date: Thu, 16 Jun 2022 06:57:56 +0300 Subject: [PATCH] Updated testbench template project --- .../testbench_template_tb/c_rand.v | 48 ------------------- .../testbench_template_tb/compile.tcl | 9 ++-- .../testbench_template_tb/main_tb.sv | 42 ++++++++-------- 3 files changed, 23 insertions(+), 76 deletions(-) delete mode 100755 example_projects/testbench_template_tb/c_rand.v diff --git a/example_projects/testbench_template_tb/c_rand.v b/example_projects/testbench_template_tb/c_rand.v deleted file mode 100755 index e3e5574..0000000 --- a/example_projects/testbench_template_tb/c_rand.v +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2007 Altera Corporation. All rights reserved. -// Altera products are protected under numerous U.S. and foreign patents, -// maskwork rights, copyrights and other intellectual property laws. -// -// This reference design file, and your use thereof, is subject to and governed -// by the terms and conditions of the applicable Altera Reference Design -// License Agreement (either as signed by you or found at www.altera.com). By -// using this reference design file, you indicate your acceptance of such terms -// and conditions between you and Altera Corporation. In the event that you do -// not agree with such terms and conditions, you may not use the reference -// design file and please promptly destroy any copies you have made. -// -// This reference design file is being provided on an "as-is" basis and as an -// accommodation and therefore all warranties, representations or guarantees of -// any kind (whether express, implied or statutory) including, without -// limitation, warranties of merchantability, non-infringement, or fitness for -// a particular purpose, are specifically disclaimed. By making this reference -// design file available, Altera expressly does not recommend, suggest or -// require that this reference design file be used in combination with any -// other product not provided by Altera. -///////////////////////////////////////////////////////////////////////////// - -// C runtime library random number generator -// -// uses 32 logic cells for DFF/ADD and 8 DSP blocks for the -// 32x18=>32 multiply - -module c_rand (clk,rst,reseed,seed_val,out); -input clk,rst,reseed; -input [31:0] seed_val; -output [15:0] out; -wire [15:0] out; - -reg [31:0] state; - -always @(posedge clk or posedge rst) begin - if (rst) state <= 0; - else begin - if (reseed) state <= seed_val; - else begin - state <= state * 32'h343fd + 32'h269EC3; - end - end -end - -assign out = (state >> 16) & 16'h7fff; - -endmodule \ No newline at end of file diff --git a/example_projects/testbench_template_tb/compile.tcl b/example_projects/testbench_template_tb/compile.tcl index 31d0cd5..2541e53 100755 --- a/example_projects/testbench_template_tb/compile.tcl +++ b/example_projects/testbench_template_tb/compile.tcl @@ -17,18 +17,17 @@ set library_file_list { work {main_tb.sv - # main.sv - c_rand.v + main.sv + clk_divider.sv edge_detect.sv - delay.sv - clk_divider.sv} + delay.sv} } set vsim_params "-L altera_mf_ver -L altera_mf -L lpm_ver -L lpm" set top_level work.main_tb -set suppress_err_list "" +set suppress_err_list 0 # Console commands: # r = Recompile changed and dependent files diff --git a/example_projects/testbench_template_tb/main_tb.sv b/example_projects/testbench_template_tb/main_tb.sv index 8f57cbe..7799abe 100755 --- a/example_projects/testbench_template_tb/main_tb.sv +++ b/example_projects/testbench_template_tb/main_tb.sv @@ -60,42 +60,34 @@ end logic nrst_once; assign nrst_once = ~rst_once; -logic [31:0] DerivedClocks; +logic [31:0] clk200_div; clk_divider #( .WIDTH( 32 ) ) cd1 ( .clk( clk200 ), .nrst( nrst_once ), .ena( 1'b1 ), - .out( DerivedClocks[31:0] ) + .out( clk200_div[31:0] ) ); -logic [31:0] E_DerivedClocks; +logic [31:0] clk200_div_rise; edge_detect ed1[31:0] ( .clk( {32{clk200}} ), .anrst( {32{nrst_once}} ), - .in( DerivedClocks[31:0] ), - .rising( E_DerivedClocks[31:0] ), + .in( clk200_div[31:0] ), + .rising( clk200_div_rise[31:0] ), .falling( ), .both( ) ); -logic [31:0] RandomNumber1; -c_rand rng1 ( - .clk( clk200 ), - .rst( 1'b0 ), - .reseed( rst_once ), - .seed_val( DerivedClocks[31:0] ^ (DerivedClocks[31:0] << 1) ), - .out( RandomNumber1[15:0] ) -); - -c_rand rng2 ( - .clk( clk200 ), - .rst( 1'b0 ), - .reseed( rst_once ), - .seed_val( DerivedClocks[31:0] ^ (DerivedClocks[31:0] << 2) ), - .out( RandomNumber1[31:16] ) -); +logic [31:0] rnd_data; +always_ff @(posedge clk200) begin + if( ~nrst_once ) begin + rnd_data[31:0] <= $random( 1 ); // seeding + end else begin + rnd_data[31:0] <= $random; + end +end logic start; initial begin @@ -104,7 +96,11 @@ initial begin #20 start = 1'b0; end -// Module under test ========================================================== +//initial begin +// #1000 $finish; +//end + +// Module under test =========================================================== logic [15:0] seq_cntr = '0; @@ -121,7 +117,7 @@ always_ff @(posedge clk200) begin if( seq_cntr[15:0]<300 ) begin id[31:0] <= '1; - //id[31:0] <= {4{RandomNumber1[15:0]}}; + //id[31:0] <= {4{rnd_data[15:0]}}; end else begin id[31:0] <= '0; end