1module top;
2  wire z;
3
4  foo f1 ();
5  foo #(4) f2();
6  foo #(5) f3();
7
8  OSCILLATOR g1(z);
9
10  initial
11    $monitor("z=%d",z);
12
13endmodule
14
15module foo #(.Z(2));
16  parameter Z2 = Z/2;
17  parameter Z3 = Z2*3;
18
19  initial
20    $display("Z=%d  Z2=%d",Z,Z2);
21
22endmodule
23
24module OSCILLATOR #(.HZ(1000)) (Z);
25  parameter HZ0 = HZ/2;
26  parameter HZ1 = HZ - HZ0;
27  output Z;
28  reg Z;
29  time t;
30
31  initial
32    t = 0;
33
34  always
35    begin
36      Z = 1'b0;
37      if (t == 0) t = $tkg$systime;
38      t = t + HZ0;
39      $tkg$waituntil(t);
40      Z = 1'b1;
41      t = t + HZ1;
42      $tkg$waituntil(t);
43    end
44
45
46endmodule
47