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

Subversion Repositories ha1588

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

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 15 edn_walter
  rtc
19 3 ash_riple
   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 19 edn_walter
wire        time_reg_sec_inc_   = DUT.time_acc_48s_inc;
132 3 ash_riple
// ns fraction watchpoint
133
wire [ 7:0] time_acc_modulo_ns_f = time_acc_modulo[7:0];
134
wire [ 7:0] time_reg_ns_in_f     = time_reg_ns_in[7:0];
135
wire [ 7:0] time_reg_ns_f        = time_reg_ns[7:0];
136
wire [31:0] period_ns_f          = period_in[31:0];
137
wire [31:0] period_adj_ns_f      = period_adj[31:0];
138
 
139
// ns time incremental watchpoint
140
reg  [47:0] time_reg_sec__d1;
141
reg  [29:0] time_reg_ns__d1;
142
always @(posedge clk) begin
143
        time_reg_sec__d1 <= time_reg_sec_;
144
        time_reg_ns__d1  <= time_reg_ns_;
145
end
146
wire [29:0] time_reg_ns__delta = (time_reg_sec__d1!=time_reg_sec_)?
147
                                (time_acc_modulo_ns_-(time_reg_ns__d1-time_reg_ns_)):
148
                                (time_reg_ns_-time_reg_ns__d1);
149
 
150
// Delta-Sigma circuit watchpoint
151
wire [23:0] time_adj_08n_32f_24f = rtc_timer_tb.DUT.time_adj_08n_32f[23:0];
152
 
153
endmodule
154
 

powered by: WebSVN 2.1.0

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