forked from jkelley/irig-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirig_testbench.v
More file actions
163 lines (137 loc) · 3.76 KB
/
irig_testbench.v
File metadata and controls
163 lines (137 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
`timescale 1 ns / 100 ps
module irig_testbench();
localparam MARK = 3'b100;
localparam D1 = 3'b010;
localparam D0 = 3'b001;
// Inputs to the DUT
reg clk;
reg rst;
reg irigb;
// Output of the DUT
wire pps;
wire [5:0] ts_second;
wire [5:0] ts_minute;
wire [4:0] ts_hour;
wire [8:0] ts_day;
wire [6:0] ts_year;
wire [16:0] ts_sec_day;
wire [3:0] state;
// Instantiate the DUT
irig i1(.clk(clk),
.rst(rst),
.irigb(irigb),
.pps(pps),
.ts_second(ts_second),
.ts_minute(ts_minute),
.ts_hour(ts_hour),
.ts_day(ts_day),
.ts_year(ts_year),
.ts_sec_day(ts_sec_day),
.state(state));
// Reset
initial begin
clk = 1'b0;
irigb = 1'b0;
rst = 1'b1;
// Reset goes low
#120 rst = 1'b0;
#100;
// Some garbage bits
irig_bit(D0);
irig_bit(MARK);
irig_bit(D1);
irig_bit(D0);
// End of second
irig_bit(MARK);
// Now send a full stream
irig_timestamp();
// Break the lock
irig_bit(D1);
// Now reestablish the lock
irig_bit(MARK);
irig_bit(MARK);
$stop;
end
always
#50 clk = ~clk;
// Send a full timestamp
task irig_timestamp;
begin
// Frame identifier
irig_bit(MARK); // 00
// Seconds: 42 = 100_0010
// only 8 bits here
irig_bitstream(9'bx10000010);
// Minutes: 59 = _101_1001
irig_bit(MARK); // 09
irig_bitstream(9'b010101001);
// Hours: 17 = __01_0111
irig_bit(MARK); // 19
irig_bitstream(9'b000100111);
// Day of year 293 (93) = 1001_0011
irig_bit(MARK); // 29
irig_bitstream(9'b100100011);
// Day of year 293 (2) = _______10
// Tenth of seconds unused
irig_bit(MARK); // 39
irig_bitstream(9'b000000010);
// Year 16 = 0001_0110
irig_bit(MARK); // 49
irig_bitstream(9'b000100110);
// Unused
irig_bit(MARK); // 59
irig_bitstream(9'b0);
irig_bit(MARK); // 69
irig_bitstream(9'b0);
// Seconds in day
// 17:59:42 = 64782 = _01111110100001110
irig_bit(MARK); // 79
irig_bitstream(9'b100001110);
irig_bit(MARK); // 89
irig_bitstream(9'b001111110);
irig_bit(MARK); // 99
end
endtask // irig_timestamp
// Send a stream of IRIG bits
// 'x' means skip completely FIX ME?
task irig_bitstream;
input [8:0] s;
begin
repeat (9)
begin
case (s[0])
1'b1:
irig_bit(D1);
1'b0:
irig_bit(D0);
endcase // case (s[0])
s = s >> 1'b1;
end
end
endtask
// Send a single width-encoded bit
task irig_bit;
input [2:0] ib; // mark, 1, 0
begin
@(posedge clk);
irigb = 1'b1;
case (ib)
D0:
begin
#2000500 irigb = 1'b0;
#7999500;
end
D1:
begin
#5000500 irigb = 1'b0;
#4999500;
end
MARK:
begin
#8000500 irigb = 1'b0;
#1999500;
end
endcase
end
endtask
endmodule