-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrx.v
More file actions
94 lines (81 loc) · 1.77 KB
/
rx.v
File metadata and controls
94 lines (81 loc) · 1.77 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
module rx(
input clk_3125,
input rx,
output reg [7:0] rx_msg,
output reg rx_parity,
output reg rx_complete
);
initial begin
rx_msg = 8'b0;
rx_parity = 1'b0;
rx_complete = 1'b0;
end
//////////////////DO NOT MAKE ANY CHANGES ABOVE THIS LINE//////////////////
localparam START_BIT=2'b00, DATA_BIT= 2'b01, PARITY_BIT=2'b10, STOP_BIT= 2'b11 ;
reg [1:0] state;
reg [4:0] counter;
reg [2:0] pointer;
reg [7:0] data;
reg data_parity;
reg first;
initial begin
counter <= 0;
pointer = 0;
state <= START_BIT;
first = 1;
end
always @ (posedge clk_3125) begin
case (state)
START_BIT: begin
if (counter >= 26) begin
counter <= 0;
state <= DATA_BIT;
end else if (rx == 0) begin
counter <= counter + 1;
end
end
DATA_BIT: begin
if (counter >= 26) begin
counter <= 0;
pointer <= pointer + 1;
if (pointer == 7) state <= PARITY_BIT;
end else begin
counter <= counter + 1;
end
end
PARITY_BIT: begin
if (counter >= 26) begin
counter <= 0;
state <= STOP_BIT;
end else begin
counter <= counter + 1;
end
end
STOP_BIT: begin
if (counter >= 26) begin
counter <= 0;
state <= START_BIT;
end else begin
counter <= counter + 1;
end
end
endcase
end
always @(*) begin
if (state == START_BIT)begin
if (counter == 0 && ~first) begin
rx_parity = data_parity;
rx_complete = 1;
rx_msg = (^data == data_parity) ? data : 63;
end else begin
rx_complete = 0;
first = 0;
end
end
if (state == DATA_BIT) begin
if (counter == 15) data[7-pointer] = rx; // reading bit in mid of pulse to avoid reading at last
end
if (state == PARITY_BIT && counter == 15) data_parity = rx;
end
//////////////////DO NOT MAKE ANY CHANGES BELOW THIS LINE//////////////////
endmodule