Skip to content

Commit 453e51c

Browse files
committed
Fix edge case bug in the transition from stop to start
1 parent cee44e1 commit 453e51c

File tree

4 files changed

+94
-18
lines changed

4 files changed

+94
-18
lines changed

Uart8Receiver.v

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ always @(posedge clk) begin
135135
// meets the preceding min high hold time -
136136
// note that {done} && !{err} encodes the fact that
137137
// the min hold time was met earlier in STOP_BIT state
138+
// or READY state
138139
sample_count <= 4'b1;
139140
err <= 1'b0;
140141
end else begin
@@ -256,17 +257,45 @@ always @(posedge clk) begin
256257
* Wait one full bit cycle to sustain the {out} data, the
257258
* {done} signal or the {err} signal
258259
*/
259-
sample_count <= sample_count + 4'b1;
260-
if (!err && !in_sample) begin
261-
// accept the trigger to start, right from stop signal high
262-
// (in this case transmit signaling of {done} is in progress)
263-
sample_count <= 4'b1;
264-
out_hold_count <= sample_count + 5'b00010; // continue counting
265-
state <= `IDLE;
260+
sample_count <= sample_count + 4'b1;
261+
if (!err && !in_sample || &sample_count) begin
262+
// check if this is the change to a start signal -
263+
// in_sample has met the min high hold time
264+
// any time it drops to low in this state
265+
// (also in these cases, namely !{err} or tick 15 special case,
266+
// signaling of {done} is in progress)
267+
if (&sample_count) begin // reached 15, last tick, and no error
268+
// (signaling of {done} is now complete)
269+
if (in_sample) begin
270+
// not transitioning to start bit -
271+
// sample_count wraps around to zero
272+
received_data <= 8'b0;
273+
busy <= 1'b0;
274+
end else begin
275+
// transitioning to start bit -
276+
// sustain the {busy} signal high
277+
sample_count <= 4'b1;
278+
end
279+
done <= 1'b0;
280+
out <= 8'b0;
281+
state <= `IDLE;
282+
end else begin
283+
// in_sample drops from high to low
284+
// (signaling of {done} continues)
285+
sample_count <= 4'b1;
286+
// continue the counting
287+
out_hold_count <= sample_count + 5'b00010;
288+
state <= `IDLE;
289+
end
266290
end else if (&sample_count[3:1]) begin // reached 14 -
267291
// additional tick 15 comes from transitting the READY state
268292
// to get to the RESET state
269-
state <= `RESET;
293+
if (err || !in_sample) begin
294+
state <= `RESET;
295+
end
296+
// otherwise, signaling of {done} is in progress (i.e. !{err}) -
297+
// in this case, on tick 15, will be checking if in_sample
298+
// dropped from high to low on the entry to IDLE state
270299
end
271300
end
272301

tests/28.gtkw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[*]
22
[*] GTKWave Analyzer v3.3.81 (w)1999-2017 BSI
3-
[*] Sun Nov 27 14:03:49 2022
3+
[*] Tue Jan 03 22:26:44 2023
44
[*]
55
[dumpfile] "28.vcd"
6-
[dumpfile_mtime] "Sun Jan 01 21:21:04 2023"
7-
[dumpfile_size] 873902
6+
[dumpfile_mtime] "Tue Jan 03 22:25:23 2023"
7+
[dumpfile_size] 767773
88
[savefile] "28.gtkw"
99
[timestart] 704900
1010
[size] 1536 937

0 commit comments

Comments
 (0)