# Variable clock generation in verilog using task

**URL:** <https://verificationacademy.com/forums/t/variable-clock-generation-in-verilog-using-task/30298>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Clock-generator, task, Verilog\
**Created:** [January 20, 2015, 6:47am UTC](https://verificationacademy.com/forums/t/variable-clock-generation-in-verilog-using-task/30298 "2015-01-20T06:47:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![raghavkumar](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@raghavkumar](https://verificationacademy.com/forums/u/raghavkumar)\
**Post date:** [January 20, 2015, 6:47am UTC](https://verificationacademy.com/forums/t/variable-clock-generation-in-verilog-using-task/30298/1 "2015-01-20T06:47:56Z")

</div>

I have used following code to generate clock (whichever value i pass through task it will create that frequency), but the code only works if i use CLKSEL\_global = clksel\_local (line no. 23)(i.e. blocking assignment) but that creates delta delay.

```verilog
 `timescale 1ns/1ps
module new(CLK,CLK_OUT);
input CLK;
output CLK_OUT;
 
and(CLK_OUT,1,CLK);
 
 
endmodule

`timescale 1ns/1ps
module tb();
real CLKSEL_global;
reg clk;
reg CLK7;
wire clk_out;
 
new dut(clk,clk_out);
 
task task_CLOCK;
 
input real clksel_local;
begin
CLKSEL_global = clksel_local;
 
end
endtask
 
initial begin
 CLK7 = 0;
 forever begin
  #(500.0/CLKSEL_global) CLK7 = 1;
  #(500.0/CLKSEL_global) CLK7 = 0;
 end
end
 
always @(CLK7) begin
   clk = CLK7;
 end
 
 initial begin
task_CLOCK(340.0);
  end
  
 initial begin
 #100 $finish ;
 end
 endmodule

```

How do i generate variable clock without introducing delta delay ?? or is their other way than using a task

Thank you in advance
