forked from jkelley/irig-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirig_width_decode.v
More file actions
46 lines (40 loc) · 1.68 KB
/
irig_width_decode.v
File metadata and controls
46 lines (40 loc) · 1.68 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
module irig_width_decode (
input clk,
input irigb,
output reg irig_mark,
output reg irig_d0,
output reg irig_d1,
input rst
);
// 10MHz clock and 10kHz IRIG-B
// Width encoding of the three states
// Add 0.1ms tolerance for shorter pulses
localparam CYCLES_ZERO = 17'd19000;
localparam CYCLES_ONE = 17'd49000;
localparam CYCLES_MARK = 17'd79000;
// Clock cycles in an IRIG bit
reg [16:0] clk_cnt = 17'b0;
reg irigb_last = 1'b0;
always @(posedge clk) begin
if (rst) begin
clk_cnt <= 17'b0;
irigb_last = 1'b0;
irig_d0 <= 1'b0;
irig_d1 <= 1'b0;
irig_mark <= 1'b0;
end else begin
// Check widths at irig falling edge and produce one-cycle pulse
irig_mark <= (clk_cnt >= CYCLES_MARK) && !irigb && irigb_last && !irig_mark;
irig_d1 <= (clk_cnt >= CYCLES_ONE) && (clk_cnt < CYCLES_MARK) && !irigb && irigb_last && !irig_d1;
irig_d0 <= (clk_cnt >= CYCLES_ZERO) && (clk_cnt < CYCLES_ONE) && !irigb && irigb_last && !irig_d0;
// Reset count on rising edge of irig bit
if (irigb && !irigb_last)
clk_cnt <= 17'b0;
else if (!irigb) // Freeze the counter if no pulse or edge
clk_cnt <= clk_cnt;
else
clk_cnt <= clk_cnt + 17'b1;
irigb_last <= irigb;
end
end
endmodule