Skip to content

Instantly share code, notes, and snippets.

@taichi-ishitani
Created July 21, 2021 14:37
Show Gist options
  • Save taichi-ishitani/06de5e82e4b781951713f5a3f7fa690f to your computer and use it in GitHub Desktop.
Save taichi-ishitani/06de5e82e4b781951713f5a3f7fa690f to your computer and use it in GitHub Desktop.
interface clock_gen;
timeunit 1ns/1ps;
bit clk;
event start_clock_event;
realtime high_period_ns;
realtime low_period_ns;
function automatic void start_clock(
realtime period_ns,
real duty_cycle = 0.5
);
high_period_ns = period_ns * duty_cycle;
low_period_ns = period_ns * (1.0 - duty_cycle);
->start_clock_event;
endfunction
initial begin
clk = 0;
@(start_clock_event);
forever begin
clk = 1;
#(high_period_ns);
clk = 0;
#(low_period_ns);
end
end
endinterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment