x393
1.0
FPGAcodeforElphelNC393camera
rs232_rcv393.v
Go to the documentation of this file.
1
39
`timescale 1ns/1ps
40
41
module
rs232_rcv393
(
42
input
xclk
,
// half frequency (80 MHz nominal)
43
input
[
15
:
0
]
bitHalfPeriod
,
// half of the serial bit duration, in xclk cycles
44
input
ser_di
,
// rs232 (ttl) serial data in
45
input
ser_rst
,
// reset (force re-sync)
46
output
ts_stb
,
// strobe timestamp (start of message) (reset bit counters in nmea decoder)
47
output
reg
wait_just_pause
,
// may be used as reset for decoder
48
output
start
,
// serial character start (single pulse)
49
output
reg
ser_do
,
// serial data out(@posedge xclk) LSB first!
50
output
reg
ser_do_stb
,
// output data strobe (@posedge xclk), first cycle after ser_do becomes valid
51
// Next outputs are just fro debugging
52
output
[
4
:
0
]
debug
,
// {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset
53
output
[
15
:
0
]
bit_dur_cntr
,
54
output
[
4
:
0
]
bit_cntr
);
55
56
reg
[
4
:
0
]
ser_di_d
;
57
reg
ser_filt_di
;
58
reg
ser_filt_di_d
;
59
reg
bit_half_end
;
// last cycle in half-bit
60
reg
last_half_bit
;
61
reg
wait_pause
;
// waiting input to stay at 1 for 10 cycles
62
reg
wait_start
;
// (or use in_sync - set it after wait_pause is over?
63
reg
receiving_byte
;
64
reg
start_r
;
65
reg
[
15
:
0
]
bit_dur_cntr_r
;
// bit duration counter (half bit duration)
66
reg
[
4
:
0
]
bit_cntr_r
;
// counts half-bit intervals
67
wire
error
;
// low level during stop slot
68
reg
[
1
:
0
]
restart
;
69
wire
reset_wait_pause
;
70
reg
ts_stb_r
;
71
reg
shift_en
;
72
73
wire
sample_bit
;
74
wire
reset_bit_duration
;
75
wire
wstart
;
76
// reg [4:0] debug0; // {was_ts_stb, was_start, was_error, was_ser_di_1, was_ser_di_0} - once after reset
77
assign
reset_wait_pause
= (
restart
[
1
] && !
restart
[
0
]) || (
wait_pause
&& !
wait_start
&& !
ser_di
);
78
assign
error
= !
ser_filt_di
&&
last_half_bit
&&
bit_half_end
&&
receiving_byte
;
79
assign
sample_bit
=
shift_en
&&
bit_half_end
&& !
bit_cntr
[
0
];
80
assign
reset_bit_duration
=
reset_wait_pause
||
start
||
bit_half_end
||
ser_rst
;
81
82
assign
wstart
=
wait_start
&&
ser_filt_di_d
&& !
ser_filt_di
;
83
84
// assign debug[4:0] = {1'b0,wait_start,wait_pause,receiving_byte,shift_en};
85
assign
debug
[
4
:
0
] = {
error
,
wait_start
,
wait_pause
,
receiving_byte
,
shift_en
};
86
87
assign
bit_dur_cntr
=
bit_dur_cntr_r
;
// bit duration counter (half bit duration)
88
assign
bit_cntr
=
bit_cntr_r
;
// counts half-bit intervals
89
assign
start
=
start_r
;
90
assign
ts_stb
=
ts_stb_r
;
91
92
always
@ (
posedge
xclk
)
begin
93
ser_di_d
[
4
:
0
] <= {
ser_di_d
[
3
:
0
],
ser_di
};
94
95
if
(
ser_rst
|| &
ser_di_d
[
4
:
0
])
ser_filt_di
<=
1'b1
;
96
else
if
(~|
ser_di_d
[
4
:
0
])
ser_filt_di
<=
1'b0
;
97
98
ser_filt_di_d
<=
ser_filt_di
;
99
100
restart
[
1
:
0
] <= {
restart
[
0
],(
ser_rst
|| (
last_half_bit
&&
bit_half_end
&&
receiving_byte
))};
101
wait_pause
<= !
ser_rst
&& (
reset_wait_pause
||
102
(
receiving_byte
&&
last_half_bit
&&
bit_half_end
) ||
103
(
wait_pause
&& !(
last_half_bit
&&
bit_half_end
) && !(
wait_start
&& !
ser_filt_di
)));
104
start_r
<=
wstart
;
105
ts_stb_r
<= !
wait_pause
&&
wstart
;
// only first start after pause
106
bit_half_end
<=(
bit_dur_cntr_r
[
15
:
0
]==
16'h1
) && !
reset_bit_duration
;
107
108
wait_start
<= !
ser_rst
&& ((
wait_pause
||
receiving_byte
) &&
last_half_bit
&&
bit_half_end
|| (
wait_start
&& !
wstart
));
109
receiving_byte
<= !
ser_rst
&& (
start_r
|| (
receiving_byte
&& !(
last_half_bit
&&
bit_half_end
)));
110
wait_just_pause
<=
wait_pause
&& !
wait_start
;
111
112
113
if
(
reset_bit_duration
)
bit_dur_cntr_r
[
15
:
0
] <=
bitHalfPeriod
[
15
:
0
];
114
else
bit_dur_cntr_r
[
15
:
0
] <=
bit_dur_cntr_r
[
15
:
0
] -
1
;
115
116
if
(
reset_wait_pause
||
ser_rst
)
bit_cntr_r
[
4
:
0
] <=
5'h13
;
117
else
if
(
start_r
)
bit_cntr_r
[
4
:
0
] <=
5'h12
;
118
else
if
(
bit_half_end
)
bit_cntr_r
[
4
:
0
] <=
bit_cntr_r
[
4
:
0
] -
1
;
119
120
last_half_bit
<= ((
bit_cntr_r
[
4
:
0
] ==
5'h0
) && !
bit_half_end
);
121
shift_en
<=
receiving_byte
&& ((
bit_half_end
&& (
bit_cntr_r
[
3
:
0
]==
4'h2
))?
bit_cntr_r
[
4
]:
shift_en
);
122
123
if
(
sample_bit
)
ser_do
<=
ser_filt_di
;
124
ser_do_stb
<=
sample_bit
;
125
126
// if (ser_rst) debug0[4:0] <=5'b0;
127
// else debug0[4:0] <= debug | {ts_stb_r,start_r,error,ser_di_d[0],~ser_di_d[0]};
128
end
129
endmodule
rs232_rcv393.3849restart
3849restartreg[1:0]
Definition:
rs232_rcv393.v:68
rs232_rcv393.3855wstart
3855wstartwire
Definition:
rs232_rcv393.v:75
rs232_rcv393.3829ts_stb
3829ts_stb
Definition:
rs232_rcv393.v:46
rs232_rcv393.3838ser_filt_di
3838ser_filt_direg
Definition:
rs232_rcv393.v:57
rs232_rcv393.3848error
3848errorwire
Definition:
rs232_rcv393.v:67
rs232_rcv393.3851ts_stb_r
3851ts_stb_rreg
Definition:
rs232_rcv393.v:70
rs232_rcv393.3830wait_just_pause
reg 3830wait_just_pause
Definition:
rs232_rcv393.v:47
rs232_rcv393.3837ser_di_d
3837ser_di_dreg[4:0]
Definition:
rs232_rcv393.v:56
rs232_rcv393.3826bitHalfPeriod
[15:0] 3826bitHalfPeriod
Definition:
rs232_rcv393.v:43
rs232_rcv393.3841last_half_bit
3841last_half_bitreg
Definition:
rs232_rcv393.v:60
rs232_rcv393.3834debug
[4:0] 3834debug
Definition:
rs232_rcv393.v:52
rs232_rcv393.3840bit_half_end
3840bit_half_endreg
Definition:
rs232_rcv393.v:59
rs232_rcv393.3832ser_do
reg 3832ser_do
Definition:
rs232_rcv393.v:49
rs232_rcv393.3827ser_di
3827ser_di
Definition:
rs232_rcv393.v:44
rs232_rcv393.3835bit_dur_cntr
[15:0] 3835bit_dur_cntr
Definition:
rs232_rcv393.v:53
rs232_rcv393
Definition:
rs232_rcv393.v:41
rs232_rcv393.3846bit_dur_cntr_r
3846bit_dur_cntr_rreg[15:0]
Definition:
rs232_rcv393.v:65
rs232_rcv393.3836bit_cntr
[4:0] 3836bit_cntr
Definition:
rs232_rcv393.v:54
rs232_rcv393.3847bit_cntr_r
3847bit_cntr_rreg[4:0]
Definition:
rs232_rcv393.v:66
rs232_rcv393.3844receiving_byte
3844receiving_bytereg
Definition:
rs232_rcv393.v:63
rs232_rcv393.3853sample_bit
3853sample_bitwire
Definition:
rs232_rcv393.v:73
rs232_rcv393.3828ser_rst
3828ser_rst
Definition:
rs232_rcv393.v:45
rs232_rcv393.3850reset_wait_pause
3850reset_wait_pausewire
Definition:
rs232_rcv393.v:69
rs232_rcv393.3845start_r
3845start_rreg
Definition:
rs232_rcv393.v:64
rs232_rcv393.3843wait_start
3843wait_startreg
Definition:
rs232_rcv393.v:62
rs232_rcv393.3854reset_bit_duration
3854reset_bit_durationwire
Definition:
rs232_rcv393.v:74
rs232_rcv393.3833ser_do_stb
reg 3833ser_do_stb
Definition:
rs232_rcv393.v:50
rs232_rcv393.3842wait_pause
3842wait_pausereg
Definition:
rs232_rcv393.v:61
rs232_rcv393.3831start
3831start
Definition:
rs232_rcv393.v:48
rs232_rcv393.3839ser_filt_di_d
3839ser_filt_di_dreg
Definition:
rs232_rcv393.v:58
rs232_rcv393.3852shift_en
3852shift_enreg
Definition:
rs232_rcv393.v:71
rs232_rcv393.3825xclk
3825xclk
Definition:
rs232_rcv393.v:42
logger
rs232_rcv393.v
Generated by
1.8.12