req of CLK_OUT[4] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 5} { :>
    if ((period5 -ref_period5_clkin1) <= 100 && (period5 -ref_period5_clkin1) >= -100) begin
<:   if {$mmcm_clkout4_cascade} { :>
<:   if {$num_out_clks >= 7 } { :>
    $display("Freq of CLK_OUT[5] ( in KHz ) : %0f\n", 1000000000/period5);
<: } else { :>
    $display("Freq of CLK_OUT[5] ( in MHz ) : %0f\n", 1000000/period5);
<: } :>
<: } else { :>
    $display("Freq of CLK_OUT[5] ( in MHz ) : %0f\n", 1000000/period5);
<: } :>
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[5] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 6} { :>
    if ((period6 -ref_period6_clkin1) <= 100 && (period6 -ref_period6_clkin1) >= -100) begin
    $display("Freq of CLK_OUT[6] ( in MHz ) : %0f\n", 1000000/period6);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[6] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 7} { :>
    if ((period7 -ref_period7_clkin1) <= 100 && (period7 -ref_period7_clkin1) >= -100) begin
    $display("Freq of CLK_OUT[7] ( in MHz ) : %0f\n", 1000000/period7);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[7] is not correct"); 
    $finish;
    end 
<: } :>
<: if { $sv_test}  {  :>
<: if { $num_out_clks== 1}  {  :>
    if (dut.counter < (count1_exp1 - min_offset1)) begin
      $display("ERROR: %t: Count is too small for <=: PRIMARY_PORT :>: %1d, should be: %1d",
        $time, dut.counter, count1_exp1);
      $finish;
    end
    if (dut.counter > (count1_exp1 + max_offset1)) begin
      $display("ERROR: %t: Count is too large for <=: PRIMARY_PORT :>: %1d, should be: %1d",
        $time, dut.counter, count1_exp1);
      $finish;
    end
<: } else  { :>
    exp_count_min[1] = count1_exp1 - min_offset1;
    exp_count_max[1] = count1_exp1 + max_offset1;
    exp_count_min[2] = count2_exp1 - min_offset2;
    exp_count_max[2] = count2_exp1 + max_offset2;
    exp_count_min[3] = count3_exp1 - min_offset3;
    exp_count_max[3] = count3_exp1 + max_offset3;
    exp_count_min[4] = count4_exp1 - min_offset4;
    exp_count_max[4] = count4_exp1 + max_offset4;
    exp_count_min[5] = count5_exp1 - min_offset5;
    exp_count_max[5] = count5_exp1 + max_offset5;
    exp_count_min[6] = count6_exp1 - min_offset6;
    exp_count_max[6] = count6_exp1 + max_offset6;
    exp_count_min[7] = count7_exp1 - min_offset7;
    exp_count_max[7] = count7_exp1 + max_offset7;
    for (ii = 1; ii <= <=: num_out_clks :>; ii = ii + 1) begin
      if (dut.counter[ii] < exp_count_min[ii]) begin
        $display("ERROR: %t: Count%1d is too small for <=: PRIMARY_PORT :>: %1d, should be: %1d",
          $time, ii, dut.counter[ii], exp_count_min[ii]);
        $finish;
      end
      if (dut.counter[ii] > exp_count_max[ii]) begin
        $display("ERROR: %t: Count%1d is too large for <=: PRIMARY_PORT :>: %1d, should be: %1d",
          $time, ii, dut.counter[ii], exp_count_max[ii]);
        $finish;
      end
    end
    $display("%t, <=: PRIMARY_PORT :> count values check out", $time);
<: } :>
<: } :>
<: if { $use_inclk_switchover}  {  :>
    $display ("Timing checks are not valid");
    test_phase = "change clocks";
<: if { $use_reset && !$c_has_AXI}  {  :>
<: if { $reset_active_high}  {  :>
    reset = 1;
<: } else { :>
    resetn = 0;
<: } :>
<: } :>
    #(PER2*1);
    clk_in_sel = 0;
    #(PER2*2);
<: if { $use_reset && !$c_has_AXI}  {  :>
<: if { $reset_active_high}  {  :>
    reset = 0;
<: } else { :>
    resetn = 1;
<: } :>
<: } :>
    #(PER2*2);
<: if { $use_clk_valid}  {  :>
    `wait_lock;
<: } elseif  { $use_locked}  { :>
    `wait_lock;
<: } else  { :>
    #(PER2*50000);
<: } :>
    #(PER2*20);
    COUNTER_RESET = 1;
    #(PER2*19.2)
    COUNTER_RESET = 0;
    #(PER2*0.3)
<: if { $clock_sequencing && $max_seq_number>= 2}  {  :>
    #(PER2*1000)
<: } else { :>
    #(PER2*1)
<: } :>
    $display ("Timing checks are valid");
    test_phase = "counting";
<:   if {$mmcm_clkout4_cascade} { :>
<:   if {$num_out_clks >= 7 } { :>
    #(PER2*<=: mmcm_divclk_divide :>*<=: mmcm_clkout4_divide :>*<=: mmcm_clkout6_divide :>);
<: } :>
<: } :>
    #(PER2*COUNT_PHASE);
    $display("Output Frequencies w.r.t Secondary clock"); 
<:   if {$num_out_clks >= 1} { :>
    if ((period1 -ref_period1_clkin2) <= 100 && (period1 -ref_period1_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[1] ( in MHz ) : %0f\n", 1000000/period1);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[1] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 2} { :>
    if ((period2 -ref_period2_clkin2) <= 100 && (period2 -ref_period2_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[2] ( in MHz ) : %0f\n", 1000000/period2);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[2] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {(!$mmcm_ss_en) && ($num_out_clks >= 3)} { :>
    if ((period3 -ref_period3_clkin2) <= 100 && (period3 -ref_period3_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[3] ( in MHz ) : %0f\n", 1000000/period3);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[3] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {(!$mmcm_ss_en) && ($num_out_clks >= 4)} { :>
    if ((period4 -ref_period4_clkin2) <= 100 && (period4 -ref_period4_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[4] ( in MHz ) : %0f\n", 1000000/period4);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[4] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 5} { :>
    if ((period5 -ref_period5_clkin2) <= 100 && (period5 -ref_period5_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[5] ( in MHz ) : %0f\n", 1000000/period5);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[5] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 6} { :>
    if ((period6 -ref_period6_clkin2) <= 100 && (period6 -ref_period6_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[6] ( in MHz ) : %0f\n", 1000000/period6);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[6] is not correct"); 
    $finish;
    end 
<: } :>
<:   if {$num_out_clks >= 7} { :>
    if ((period7 -ref_period7_clkin2) <= 100 && (period7 -ref_period7_clkin2) >= -100) begin
    $display("Freq of CLK_OUT[7] ( in MHz ) : %0f\n", 1000000/period7);
    end else 
    begin
    $display("ERROR: Freq of CLK_OUT[7] is not correct"); 
    $finish;
    end 
<: } :>
<: if { $sv_test}  {  :>
<: if { $num_out_clks== 1}  {  :>
    if (dut.counter < (count1_exp1 - 2*min_offset1)) begin
      $display("ERROR: %t: Count is too small for <=: SECONDARY_PORT :>: %1d, should be: %1d",
         $time, dut.counter, count1_exp1);
      $finish;
    end
    if (dut.counter > (count1_exp1 + 2*max_offset1)) begin
      $display("ERROR: %t: Count is too large for <=: SECONDARY_PORT :>: %1d, should be: %1d",
         $time, dut.counter, count1_exp1);
      $finish;
    end
<: } else  { :>
    exp_count_min[1] = count1_exp1 - 2*min_offset1;
    exp_count_max[1] = count1_exp1 + 2*max_offset1;
    exp_count_min[2] = count2_exp1 - 2*min_offset2;
    exp_count_max[2] = count2_exp1 + 2*max_offset2;
    exp_count_min[3] = count3_exp1 - 2*min_offset3;
    exp_count_max[3] = count3_exp1 + 2*max_offset3;
    exp_count_min[4] = count4_exp1 - 2*min_offset4;
    exp_count_max[4] = count4_exp1 + 2*max_offset4;
    exp_count_min[5] = count5_exp1 - 2*min_offset5;
    exp_count_max[5] = count5_exp1 + 2*max_offset5;
    exp_count_min[6] = count6_exp1 - 2*min_offset6;
    exp_count_max[6] = count6_exp1 + 2*max_offset6;
    exp_count_min[7] = count7_exp1 - 2*min_offset7;
    exp_count_max[7] = count7_exp1 + 2*max_offset7;
    for (ii = 1; ii <= <=: num_out_clks :>; ii = ii + 1) begin
      if (dut.counter[ii] < exp_count_min[ii]) begin
        $display("ERROR: %t: Count%1d is too small for <=: SECONDARY_PORT :>: %1d, should be: %1d",
          $time, ii, dut.counter[ii], exp_count_min[ii]);
        $finish;
      end
      if (dut.counter[ii] > exp_count_max[ii]) begin
        $display("ERROR: %t: Count%1d is too large for <=: SECONDARY_PORT :>: %1d, should be: %1d",
          $time, ii, dut.counter[ii], exp_count_max[ii]);
        $finish;
      end
    end
    $display("%t, <=: SECONDARY_PORT :> count values check out", $time);
<: } :>
<: } :>
<: } :>
<: if { $sv_test}  {  :>
    wait(oversample_done);
    #(PER1*5);
<: } :>
    $display("SIMULATION PASSED");
    $display("Test Completed Successfully");
    $display("SYSTEM_CLOCK_COUNTER : %0d\n",$time/PER1);
    $finish;
  end


<: if { $use_locked}  {  :>
   always@(posedge <=: PRIMARY_PORT :>) begin
      timeout_counter <= timeout_counter + 1'b1;
      if (timeout_counter == 16'b1100000000000000) begin
         if (locked != 1'b1) begin
            $display("ERROR : NO LOCK signal");
            $display("SYSTEM_CLOCK_COUNTER : %0d\n",$time/PER1);
            $finish;
         end
      end
   end
<: } :>

  // Instantiation of the example design containing the clock
  //    network and sampling counters
  //---------------------------------------------------------
  <=: ComponentName :>_exdes 
    dut
   (// Clock in ports
<: if { $use_inclk_switchover}  {  :>
<: if { $clkin2_diff}  {  :>
    .<=: SECONDARY_PORT :>_p          (<=: SECONDARY_PORT :>_p),
    .<=: SECONDARY_PORT :>_n          (<=: SECONDARY_PORT :>_n),
<: } else  { :>
    .<=: SECONDARY_PORT :>            (<=: SECONDARY_PORT :>),
<: } :>
    .clk_in_sel         (clk_in_sel),
<: } :>
<: if { ($mmcm_compensation != "INTERNAL")} { :>
<: if {( $ext_feedback && !$exdes_connectfb)  || $auto_ext_feedback}  {  :>
<: if { $auto_diff_feedback}  {  :>
    .clkfb_in_p         (clkfb_in_p),
    .clkfb_in_n         (clkfb_in_n),
<: } else  { :>
    .clkfb_in           (clkfb_in),
<: } :>
<: } :>
<: } :>
    // Reset for logic in example design
    .COUNTER_RESET      (COUNTER_RESET),
<: if { $is_plle3}  {  :>
<: if { $enable_clkoutphy}  {  :>
   .clkoutphy(clkoutphy_TB),
<: } :>
<: } :>
<: if {$mmcm_ss_en} { :>
<: if {($num_out_clks > 2)} { :>
    .CLK_OUT            (CLK_OUT_int),
<: } else  { :>
    .CLK_OUT            (CLK_OUT),
<: } :>
<: } else  { :>
    .CLK_OUT            (CLK_OUT),
<: } :>
    // High bits of the counters
<: if { $clkout_last_nodyn ||( $clkfbout_last_nodyn && $exdes_connectfb) }  {  :>
    .COUNT              (COUNT));
<: } else  { :>
    .COUNT              (COUNT),
<: } :>
<: if { $use_clkout1_bar}  {  :>
    .COUNTB_1           (COUNTB_1),
<: } :>
<: if { $use_clkout2_bar}  {  :>
    .COUNTB_2           (COUNTB_2),
<: } :>
<: if { $use_clkout3_bar}  {  :>
    .COUNTB_3           (COUNTB_3),
<: } :>
<: if { $use_clkout4_bar}  {  :>
    .COUNTB_4           (COUNTB_4),
<: } :>
<: if { ($mmcm_compensation != "INTERNAL")} { :>
<: if {( $ext_feedback && !$exdes_connectfb)  || $auto_ext_feedback}  {  :>
<: if { $auto_diff_feedback}  {  :>
    .clkfb_out_p        (clkfb_out_p),
<: if { $clkfbout_last_nodyn}  {  :>
    .clkfb_out_n        (clkfb_out_n));
<: } else  { :>
    .clkfb_out_n        (clkfb_out_n),
<: } :>
<: } else  { :>
<: if { $clkfbout_last_nodyn}  {  :>
    .clkfb_out          (clkfb_out));
<: } else  { :>
    .clkfb_out          (clkfb_out),
<: } :>
<: } :>
<: } :>
<: } :>
<: if { $has_control}  {  :>
    // Status and control signals
<: } :>
<: if { $use_reset && !$c_has_AXI}  {  :>
<: if { $reset_last}  {  :>
<: if { $reset_active_high}  {  :>
    .reset              (reset));
<: } else { :>
    .resetn             (resetn));
<: } :>
<: } else  { :>
<: if { $reset_active_high}  {  :>
    .reset              (reset),
<: } else { :>
    .resetn             (resetn),
<: } :>
<: } :>
<: } :>
<: if { $use_power_down}  {  :>
<: if { $power_down_last}  {  :>
    .power_down         (power_down));
<: } else  { :>
    .power_down         (power_down),
<: } :>
<: } :>
<: if { $use_freeze}  {  :>
<: if { $freeze_last}  {  :>
    .FREEZE             (FREEZE));
<: } else  { :>
    .FREEZE             (FREEZE),
<: } :>
<: } :>
<: if { $use_status}  {  :>
<: if { $status_last}  {  :>
    .STATUS             (STATUS));
<: } else  { :>
    .STATUS             (STATUS),
<: } :>
<: } :>
<: if { $use_inclk_stopped}  {  :>
<: if { $inclk_stopped_last}  {  :>
    .input_clk_stopped  (input_clk_stopped));
<: } else  { :>
    .input_clk_stopped  (input_clk_stopped),
<: } :>
<: } :>
<: if { $use_clkfb_stopped}  {  :>
<: if { $clkfb_stopped_last}  {  :>
    .clkfb_stopped  (clkfb_stopped));
<: } else  { :>
    .clkfb_stopped  (clkfb_stopped),
<: } :>
<: } :>
<: if { $use_locked}  {  :>
<: if { $locked_last}  {  :>
    .locked             (locked));
<: } else  { :>
    .locked             (locked),
<: } :>
<: } :>
<: if { $has_cddc}  {  :>
<: if { !$is_plle3}  {  :>
    .<=: cddcdone_port :>           (), 
    .<=: cddcreq_port :>            (1'b0),
<: } :>
<: } :>
<: if { $use_clk_valid}  {  :>
    .CLK_VALID          (CLK_VALID),
<: } :>
<: if { $clkin1_diff}  {  :>
    .<=: PRIMARY_PORT :>_p          (<=: PRIMARY_PORT :>_p),
    .<=: PRIMARY_PORT :>_n          (<=: PRIMARY_PORT :>_n)
<: } else  { :>
    .<=: PRIMARY_PORT :>            (<=: PRIMARY_PORT :>)
<: } :>
);
<: if {$mmcm_ss_en} { :>
<: if {($num_out_clks > 2)} { :>
   assign CLK_OUT[2:1] = CLK_OUT_int[2:1];
<: if {($num_out_clks > 4)} { :>
   assign CLK_OUT[4:3] = 2'b00;
   assign CLK_OUT[<=: num_out_clks :>:5] = CLK_OUT_int[<=: num_out_clks :> -2:3];
<: } :>
<: } :>
<: } :>

// Freq Check 
<:   if {$num_out_clks >= 1} { :>
initial
  prev_rise1 = 0;

always @(posedge CLK_OUT[1])
begin
  if (prev_rise1 != 0)
    period1 = $time - prev_rise1;
  prev_rise1 = $time;
end
<:   } :>
<:   if {$num_out_clks >= 2} { :>
initial
  prev_rise2 = 0;

always @(posedge CLK_OUT[2])
begin
  if (prev_rise2 != 0)
    period2 = $time - prev_rise2;
  prev_rise2 = $time;
end
<:   } :>
<:   if {(!$mmcm_ss_en) && ($num_out_clks >= 3)} { :>
initial
  prev_rise3 = 0;

always @(posedge CLK_OUT[3])
begin
  if (prev_rise3 != 0)
    period3 = $time - prev_rise3;
  prev_rise3 = $time;
end
<:   } :>
<:   if {(!$mmcm_ss_en) && ($num_out_clks >= 4)} { :>
initial
  prev_rise4 = 0;

always @(posedge CLK_OUT[4])
begin
  if (prev_rise4 != 0)
    period4 = $time - prev_rise4;
  prev_rise4 = $time;
end
<:   } :>
<:   if {$num_out_clks >= 5} { :>
initial
  prev_rise5 = 0;

always @(posedge CLK_OUT[5])
begin
  if (prev_rise5 != 0)
    period5 = $time - prev_rise5;
  prev_rise5 = $time;
end
<:   } :>
<:   if {$num_out_clks >= 6} { :>
initial
  prev_rise6 = 0;

always @(posedge CLK_OUT[6])
begin
  if (prev_rise6 != 0)
    period6 = $time - prev_rise6;
  prev_rise6 = $time;
end
<:   } :>
<:   if {$num_out_clks >= 7} { :>
initial
  prev_rise7 = 0;

always @(posedge CLK_OUT[7])
begin
  if (prev_rise7 != 0)
    period7 = $time - prev_rise7;
  prev_rise7 = $time;
end
<:   } :>
<: } :>

endmodule
