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

Subversion Repositories ha1588

[/] [ha1588/] [trunk/] [sim/] [rtc/] [rtc_timer_tb.v] - Blame information for rev 14

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
module rtc_timer_tb  ;
4
 
5
  reg rst;
6
  reg clk;
7
  wire [37:0]  time_reg_ns;
8
  wire [47:0]  time_reg_sec;
9
  reg period_ld;
10
  reg [39:0]  period_in;
11
  reg [37:0]  time_acc_modulo;
12
  reg adj_ld;
13
  reg [31:0]  adj_ld_data;
14
  reg [39:0]  period_adj;
15
  reg time_ld;
16
  reg [37:0] time_reg_ns_in;
17
  reg [47:0] time_reg_sec_in;
18
  rtc_timer
19
   DUT  (
20
      .rst (rst ) ,
21
      .clk (clk ) ,
22
      .time_ld (time_ld ) ,
23
      .time_reg_ns_in (time_reg_ns_in ) ,
24
      .time_reg_sec_in (time_reg_sec_in ) ,
25
      .time_reg_ns (time_reg_ns ) ,
26
      .time_reg_sec (time_reg_sec ) ,
27
      .period_ld (period_ld ) ,
28
      .period_in (period_in ) ,
29
      .time_acc_modulo (time_acc_modulo ) ,
30
      .adj_ld (adj_ld ) ,
31
      .period_adj (period_adj ) ,
32
      .adj_ld_data (adj_ld_data ) );
33
 
34
 
35
initial begin
36
        clk = 1'b0;
37
        forever #4  clk = !clk;
38
end
39
initial begin
40
        rst = 1'b0;
41
        @(posedge clk);
42
        rst = 1'b1;
43
        @(posedge clk);
44
        rst = 1'b0;
45
end
46
initial begin
47
        #2000 $stop;
48
end
49
 
50
// main process
51
integer i;
52
initial begin
53
 
54
        /////////////////////////
55
        // reset default values
56
        /////////////////////////
57
 
58
        @(posedge rst);
59
        // frequency load
60
        period_ld        =  1'b0;
61
        period_in[39:32] =  8'h00;        // ns
62
        period_in[31: 0] = 32'h00000000;  // ns fraction
63
        time_acc_modulo  = 38'd256_000000000;
64
        // time load
65
        time_ld              =  1'b0;
66
        time_reg_ns_in[37:8] = 30'd0;          // ns
67
        time_reg_ns_in[ 7:0] =  8'h00;         // ns fraction
68
        time_reg_sec_in      = 48'd0;
69
        // time fine tune load
70
        adj_ld      =  1'b0;
71
        adj_ld_data = 32'd10;
72
        period_adj  = 40'h00_00000000;
73
        @(negedge rst);
74
 
75
        ////////////////////
76
        // time adjustment
77
        ////////////////////
78
 
79
        for (i=0; i<20; i=i+1) @(posedge clk);
80
        // load default period
81
        period_ld          =  1'b1;
82
        period_in[39:32]   =  8'h08;        // ns
83
        period_in[31: 0]   = 32'h00000000;  // ns fraction
84
        @(posedge clk);
85
        period_ld          =  1'b0;
86
 
87
        for (i=0; i<20; i=i+1) @(posedge clk);
88
        // fine tune time difference by 0
89
        adj_ld            =  1'b1;
90
        adj_ld_data       = 32'd10;
91
        period_adj[39:32] =  8'h00;        // ns           // can be negative?
92
        period_adj[31: 0] = 32'h00000000;  // ns fraction
93
        @(posedge clk);
94
        adj_ld            =  1'b0;
95
 
96
        for (i=0; i<20; i=i+1) @(posedge clk);
97
        // load time ToD values
98
        time_ld              =  1'b1;
99
        time_reg_ns_in[37:8] = 30'd999999990;  // ns
100
        time_reg_ns_in[ 7:0] =  8'h00;         // ns fraction
101
        time_reg_sec_in      = 48'd10;
102
        @(posedge clk);
103
        time_ld              =  1'b0;
104
 
105
        for (i=0; i<20; i=i+1) @(posedge clk);
106
        // fine tune frequency difference
107
        period_ld          =  1'b1;
108
        period_in[39:32]   =  8'h08;        // ns
109
        period_in[31: 0]   = 32'h10200000;  // ns fraction
110
        @(posedge clk);
111
        period_ld          =  1'b0;
112
 
113
        for (i=0; i<20; i=i+1) @(posedge clk);
114
        // fine tune time difference
115
        adj_ld            =  1'b1;
116
        adj_ld_data       = 32'd10;
117
        period_adj[39:32] =  8'h02;        // ns           // can be negative?
118
        period_adj[31: 0] = 32'h20800000;  // ns fraction
119
        @(posedge clk);
120
        adj_ld            =  1'b0;
121
end
122
 
123
// sec+ns watchpoint
124
wire [29:0] time_acc_modulo_ns_ = time_acc_modulo[37:8];
125
wire [47:0] time_reg_sec_in_    = time_reg_sec_in[47:0];
126
wire [29:0] time_reg_ns_in_     = time_reg_ns_in[37:8];
127
wire [47:0] time_reg_sec_       = time_reg_sec[47:0];
128
wire [29:0] time_reg_ns_        = time_reg_ns[37:8];
129
wire [ 7:0] period_ns_          = period_in[39:32];
130
wire [ 7:0] period_adj_ns_      = period_adj[39:32];
131
// ns fraction watchpoint
132
wire [ 7:0] time_acc_modulo_ns_f = time_acc_modulo[7:0];
133
wire [ 7:0] time_reg_ns_in_f     = time_reg_ns_in[7:0];
134
wire [ 7:0] time_reg_ns_f        = time_reg_ns[7:0];
135
wire [31:0] period_ns_f          = period_in[31:0];
136
wire [31:0] period_adj_ns_f      = period_adj[31:0];
137
 
138
// ns time incremental watchpoint
139
reg  [47:0] time_reg_sec__d1;
140
reg  [29:0] time_reg_ns__d1;
141
always @(posedge clk) begin
142
        time_reg_sec__d1 <= time_reg_sec_;
143
        time_reg_ns__d1  <= time_reg_ns_;
144
end
145
wire [29:0] time_reg_ns__delta = (time_reg_sec__d1!=time_reg_sec_)?
146
                                (time_acc_modulo_ns_-(time_reg_ns__d1-time_reg_ns_)):
147
                                (time_reg_ns_-time_reg_ns__d1);
148
 
149
// Delta-Sigma circuit watchpoint
150
wire [23:0] time_adj_08n_32f_24f = rtc_timer_tb.DUT.time_adj_08n_32f[23:0];
151
 
152
endmodule
153
 

powered by: WebSVN 2.1.0

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