Created
July 21, 2021 14:37
-
-
Save taichi-ishitani/06de5e82e4b781951713f5a3f7fa690f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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