Skip to content

Commit 8d95647

Browse files
committed
Added Fmax computation script for Xilinx Vivado
1 parent 9ea8e5e commit 8d95647

File tree

4 files changed

+71
-35
lines changed

4 files changed

+71
-35
lines changed

example_projects/testbench_template_tb/edge_detect.sv

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
//------------------------------------------------------------------------------
22
// edge_detect.sv
3+
// published as part of https://github.com/pConst/basic_verilog
34
// Konstantin Pavlov, pavlovconst@gmail.com
45
//------------------------------------------------------------------------------
56

67
// INFO ------------------------------------------------------------------------
7-
// Edge detector, ver.3
8+
// Edge detector, ver.4
9+
//
10+
// (new!) Added WIDTH parameter to simplify instantiating arrays of edge detectors
11+
// (new!) Made reset to be asynchronous
12+
//
813
// Added parameter to select combinational implementation (zero clocks delay)
914
// or registered implementation (one clocks delay)
1015
//
@@ -17,12 +22,13 @@
1722
/* --- INSTANTIATION TEMPLATE BEGIN ---
1823
1924
edge_detect #(
25+
.WIDTH( 32 ),
2026
.REGISTER_OUTPUTS( 1'b1 )
21-
) ED1[31:0] (
22-
.clk( {32{clk}} ),
23-
.nrst( {32{1'b1}} ),
27+
) in_ed (
28+
.clk( clk ),
29+
.anrst( 1'b1 ),
2430
.in( in[31:0] ),
25-
.rising( out[31:0] ),
31+
.rising( in_rise[31:0] ),
2632
.falling( ),
2733
.both( )
2834
);
@@ -31,59 +37,60 @@ edge_detect #(
3137

3238

3339
module edge_detect #( parameter
40+
bit [7:0] WIDTH = 1, // signal width
3441
bit [0:0] REGISTER_OUTPUTS = 1'b0 // 0 - comb. implementation (default)
3542
// 1 - registered implementation
3643
)(
3744
input clk,
38-
input nrst,
45+
input anrst,
3946

40-
input in,
41-
output logic rising,
42-
output logic falling,
43-
output logic both
47+
input [WIDTH-1:0] in,
48+
output logic [WIDTH-1:0] rising,
49+
output logic [WIDTH-1:0] falling,
50+
output logic [WIDTH-1:0] both
4451
);
4552

4653
// data delay line
47-
logic in_d = 0;
48-
always_ff @(posedge clk) begin
49-
if ( ~nrst ) begin
50-
in_d <= 0;
54+
logic [WIDTH-1:0] in_d = '0;
55+
always_ff @(posedge clk or negedge anrst) begin
56+
if ( ~anrst ) begin
57+
in_d[WIDTH-1:0] <= '0;
5158
end else begin
52-
in_d <= in;
59+
in_d[WIDTH-1:0] <= in[WIDTH-1:0];
5360
end
5461
end
5562

56-
logic rising_comb;
57-
logic falling_comb;
58-
logic both_comb;
63+
logic [WIDTH-1:0] rising_comb;
64+
logic [WIDTH-1:0] falling_comb;
65+
logic [WIDTH-1:0] both_comb;
5966
always_comb begin
60-
rising_comb = nrst && (in && ~in_d);
61-
falling_comb = nrst && (~in && in_d);
62-
both_comb = nrst && (rising_comb || falling_comb);
67+
rising_comb[WIDTH-1:0] = {WIDTH{anrst}} & (in[WIDTH-1:0] & ~in_d[WIDTH-1:0]);
68+
falling_comb[WIDTH-1:0] = {WIDTH{anrst}} & (~in[WIDTH-1:0] & in_d[WIDTH-1:0]);
69+
both_comb[WIDTH-1:0] = {WIDTH{anrst}} & (rising_comb[WIDTH-1:0] | falling_comb[WIDTH-1:0]);
6370
end
6471

6572
generate
66-
if( REGISTER_OUTPUTS=='0 ) begin
73+
if( REGISTER_OUTPUTS==1'b0 ) begin
6774

6875
// combinational outputs, no delay
6976
always_comb begin
70-
rising = rising_comb;
71-
falling = falling_comb;
72-
both = both_comb;
77+
rising[WIDTH-1:0] = rising_comb[WIDTH-1:0];
78+
falling[WIDTH-1:0] = falling_comb[WIDTH-1:0];
79+
both[WIDTH-1:0] = both_comb[WIDTH-1:0];
7380
end // always
7481

7582
end else begin
7683

7784
// registered outputs, 1 cycle delay
78-
always_ff @(posedge clk) begin
79-
if( ~nrst ) begin
80-
rising <= 0;
81-
falling <= 0;
82-
both <= 0;
85+
always_ff @(posedge clk or negedge anrst) begin
86+
if( ~anrst ) begin
87+
rising[WIDTH-1:0] <= '0;
88+
falling[WIDTH-1:0] <= '0;
89+
both[WIDTH-1:0] <= '0;
8390
end else begin
84-
rising <= rising_comb;
85-
falling <= falling_comb;
86-
both <= both_comb;
91+
rising[WIDTH-1:0] <= rising_comb[WIDTH-1:0];
92+
falling[WIDTH-1:0] <= falling_comb[WIDTH-1:0];
93+
both[WIDTH-1:0] <= both_comb[WIDTH-1:0];
8794
end // always
8895
end // if
8996

example_projects/testbench_template_tb/main_tb.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ clk_divider #(
7373
logic [31:0] E_DerivedClocks;
7474
edge_detect ed1[31:0] (
7575
.clk( {32{clk200}} ),
76-
.nrst( {32{nrst_once}} ),
76+
.anrst( {32{nrst_once}} ),
7777
.in( DerivedClocks[31:0] ),
7878
.rising( E_DerivedClocks[31:0] ),
7979
.falling( ),

scripts/Vivado_init.tcl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#------------------------------------------------------------------------------
22
# Vivado_init.tcl
3+
# published as part of https://github.com/pConst/basic_verilog
34
# Konstantin Pavlov, pavlovconst@gmail.com
45
#------------------------------------------------------------------------------
56

@@ -81,4 +82,14 @@ proc el_time {} {
8182
puts "----------------------------------"
8283
puts [ join [ list "TOTAL: " [format "%02d:%02d:%02d" $hs_t $ms_t $ss_t]] "" ]
8384
puts ""
84-
}
85+
}
86+
87+
# compuiting fmax, in MHz, given target clock in MHz
88+
proc fmax {target_clock} {
89+
open_run impl_1
90+
puts [ join [ list \
91+
[expr round(1e3/((1e3/$target_clock)-[get_property SLACK [get_timing_paths]]))] \
92+
" MHz" ] "" ]
93+
puts ""
94+
}
95+

scripts/get_fmax_vivado.tcl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#------------------------------------------------------------------------------
2+
# get_fmax_vivado.tcl
3+
# published as part of https://github.com/pConst/basic_verilog
4+
# Konstantin Pavlov, pavlovconst@gmail.com
5+
#------------------------------------------------------------------------------
6+
7+
8+
fmax 1000
9+
10+
# compuiting fmax, in MHz, given target clock in MHz
11+
proc fmax {target_clock} {
12+
open_run impl_1
13+
puts [ join [ list \
14+
[expr round(1e3/((1e3/$target_clock)-[get_property SLACK [get_timing_paths]]))] \
15+
" MHz" ] "" ]
16+
puts ""
17+
}
18+

0 commit comments

Comments
 (0)