OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [src/] [clock/] [recover_clock.v] - Blame information for rev 51

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 qaztronic
// --------------------------------------------------------------------
2
//
3
// --------------------------------------------------------------------
4
 
5
`timescale 1ps/1ps
6
 
7
 
8
module
9
  recover_clock
10
  #(
11
    parameter PROFILE_COUNT   = 20
12
  )
13
  (
14
    input       in,
15
 
16
    output reg  clock
17
  );
18
 
19
  time  in_time_buffer;
20
  time  clock_period_buffer;
21
  time  clock_out_period = 1000000;
22
 
23
  integer count = 0;
24
 
25
  // --------------------------------------------------------------------
26
  //
27
  reg internal_clock;
28
 
29
  initial
30
    begin
31
 
32
      internal_clock <= 1'bx;
33
 
34
      wait( in === 0 );
35
 
36
      repeat( PROFILE_COUNT )
37
        begin
38
 
39
          @( posedge in );
40
          in_time_buffer  = $time;
41
          @( negedge in );
42
 
43
          clock_period_buffer = $time - in_time_buffer;
44
 
45
          if( clock_period_buffer < clock_out_period )
46
            clock_out_period = clock_period_buffer;
47
 
48
          count = count + 1;
49
 
50
        end
51
 
52
      $display( "-#- %16.t | recover_clock: period (in sim time) = %t", $time, clock_out_period );
53
 
54
      @( posedge in )
55
        internal_clock <= 1'b1;
56
 
57
      forever
58
        #(clock_out_period/2) internal_clock <= ~internal_clock;
59
 
60
    end
61
 
62
 
63
  // --------------------------------------------------------------------
64
  //
65
  time  delta = 0;
66
  time  delta_buffer = 0;
67
 
68
  always @( posedge internal_clock)
69
    delta_buffer <= $time;
70
 
71
  always @( posedge in)
72
    if( internal_clock !== 1'bx )
73
      delta <= ($time - delta_buffer) %  clock_period_buffer;
74
 
75
 
76
  // --------------------------------------------------------------------
77
  //
78
  always @( * )
79
    clock = #(delta) internal_clock;
80
 
81
 
82
endmodule
83
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.