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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [rtl/] [rtc/] [rtc.v] - Blame information for rev 21

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

Line No. Rev Author Line
1 3 ash_riple
`timescale 1ns/1ns
2
 
3 15 edn_walter
module rtc (
4 3 ash_riple
  input rst, clk,
5
  // 1. direct time adjustment: ToD set up
6
  input time_ld,
7
  input [37:0] time_reg_ns_in,   // 37:8 ns, 7:0 ns_fraction
8
  input [47:0] time_reg_sec_in,  // 47:0 sec
9
  // 2. frequency adjustment: frequency set up for drift compensation
10
  input period_ld,
11
  input [39:0] period_in,        // 39:32 ns, 31:0 ns_fraction
12
  input [37:0] time_acc_modulo,  // 37: 8 ns,  7:0 ns_fraction
13
  // 3. precise time adjustment: small time difference adjustment with a time mark
14
  input adj_ld,
15
  input [31:0] adj_ld_data,
16
  input [39:0] period_adj,  // 39:32 ns, 31:0 ns_fraction
17
 
18
  // time output          
19
  output [37:0] time_reg_ns,  // 37:8 ns, 7:0 ns_fraction
20
  output [47:0] time_reg_sec  // 47:0 sec 
21
);
22
 
23
reg  [39:0] period_fix;  // 39:32 ns, 31:0 ns_fraction
24
reg  [31:0] adj_cnt;
25
reg  [39:0] time_adj;    // 39:32 ns, 31:0 ns_fraction
26
// frequency and small time difference adjustment registers
27
always @(posedge rst or posedge clk) begin
28
  if (rst) begin
29
    period_fix <= 40'd0;
30
    adj_cnt    <= 32'hffffffff;
31
    time_adj   <= 40'd0;
32
  end
33
  else begin
34
    if (period_ld)  // load period adjustment
35
      period_fix <= period_in;
36
    else
37
      period_fix <= period_fix;
38
 
39
    if (adj_ld)  // load precise time adjustment time mark
40
      adj_cnt  <= adj_ld_data;
41
    else if (adj_cnt==32'hffffffff)
42
      adj_cnt  <= adj_cnt;  // no cycling
43
    else
44
      adj_cnt  <= adj_cnt - 1;  // counting down
45
 
46
    if (adj_cnt==0)  // change period temparorily
47
      time_adj <= period_fix + period_adj;
48
    else
49
      time_adj <= period_fix + 0;
50
  end
51
end
52
 
53 19 edn_walter
reg  [39:0] time_adj_08n_32f;  // 39:32 ns, 31:0 ns_fraction
54 3 ash_riple
wire [15:0] time_adj_08n_08f;  // 15: 8 ns,  7:0 ns_fraction
55
reg  [23:0] time_adj_00n_24f;  //           23:0 ns_fraction
56
// delta-sigma circuit to keep the lower 24bit of time_adj
57 19 edn_walter
always @(posedge rst or posedge clk) begin
58 3 ash_riple
  if (rst) begin
59 19 edn_walter
    time_adj_08n_32f <= 40'd0;
60 3 ash_riple
    time_adj_00n_24f <= 24'd0;
61
  end
62
  else begin
63 19 edn_walter
    time_adj_08n_32f <= time_adj[39: 0] + {16'd0, time_adj_00n_24f};  // add the delta
64
    time_adj_00n_24f <= time_adj_08n_32f[23: 0];                      // save the delta
65 3 ash_riple
  end
66
end
67 19 edn_walter
assign time_adj_08n_08f = time_adj_08n_32f[39:24];  // output w/o the delta
68 3 ash_riple
 
69
reg  [37:0] time_acc_30n_08f;  // 37:8 ns , 7:0 ns_fraction
70
reg  [47:0] time_acc_48s;      // 47:0 sec
71 19 edn_walter
reg         time_acc_48s_inc;
72 3 ash_riple
// time accumulator (48bit_s + 30bit_ns + 8bit_ns_fraction)
73
always @(posedge rst or posedge clk) begin
74
  if (rst) begin
75
    time_acc_30n_08f <= 38'd0;
76
    time_acc_48s     <= 48'd0;
77 19 edn_walter
    time_acc_48s_inc <=  1'b0;
78 3 ash_riple
  end
79
  else begin
80
    if (time_ld) begin  // direct write
81
      time_acc_30n_08f <= time_reg_ns_in;
82
      time_acc_48s     <= time_reg_sec_in;
83
    end
84
    else begin
85 19 edn_walter
 
86
      if (time_acc_30n_08f + {22'd0, time_adj_08n_08f} >= time_acc_modulo)
87
        time_acc_30n_08f <= time_acc_30n_08f + {22'd0, time_adj_08n_08f} - time_acc_modulo;
88
      else
89
        time_acc_30n_08f <= time_acc_30n_08f + {22'd0, time_adj_08n_08f};
90
 
91
      if (time_acc_48s_inc)
92
        time_acc_48s_inc <= 1'b0;
93
      else if (time_acc_30n_08f + {22'd0, time_adj_08n_08f} + {22'd0, time_adj_08n_08f} >= time_acc_modulo)
94
        time_acc_48s_inc <= 1'b1;
95
      else
96
        time_acc_48s_inc <= 1'b0;
97
 
98
      if (time_acc_48s_inc)
99
        time_acc_48s     <= time_acc_48s + 1;
100
      else
101
        time_acc_48s     <= time_acc_48s;
102
 
103 3 ash_riple
    end
104
  end
105
end
106
 
107
// time output (48bit_s + 30bit_ns + 8bit_ns_fraction)
108
assign time_reg_ns  = time_acc_30n_08f;
109
assign time_reg_sec = time_acc_48s;
110
 
111
endmodule

powered by: WebSVN 2.1.0

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