forked from umangs30/fpga-team-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart_receiver.v
146 lines (119 loc) · 3.2 KB
/
uart_receiver.v
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
module receiver(input rx, input s_tick,input clk, output reg [7:0] dout);
parameter [3:0] IDLE=4'd0;
parameter [3:0] DATA0=4'd1;
parameter [3:0] DATA1=4'd2;
parameter [3:0] DATA2=4'd3;
parameter [3:0] DATA3=4'd4;
parameter [3:0] DATA4=4'd5;
parameter [3:0] DATA5=4'd6;
parameter [3:0] DATA6=4'd7;
parameter [3:0] DATA7=4'd8;
reg [5:0]counter;
reg [3:0] state;
reg [7:0] dout_tp;
reg [3:0] count;
always @(posedge s_tick) begin
case(state)
IDLE:
if(rx==0 && counter ==4'd7)begin
state <= DATA0;
counter<=0;
dout_tp<=0;
end
else begin
counter<=counter+1;
end
DATA0:
if (counter == 4'd15) begin
state<=DATA1;
counter<=0;
dout_tp[0]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA1:
if (counter == 4'd15) begin
state<=DATA2;
counter<=0;
dout_tp[1]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA2:
if (counter == 4'd15) begin
state<=DATA3;
counter<=0;
dout_tp[2]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA3:
if (counter == 4'd15) begin
state<=DATA4;
counter<=0;
dout_tp[3]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA4:
if (counter == 4'd15) begin
state<=DATA5;
counter<=0;
dout_tp[4]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA5:
if (counter == 4'd15) begin
state<=DATA6;
counter<=0;
dout_tp[5]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA6:
if (counter == 4'd15) begin
state<=DATA7;
counter<=0;
dout_tp[6]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
DATA7:
if (counter == 4'd15) begin
state<=IDLE;
counter<=0;
dout_tp[7]<=rx;
count<=count+1;
end
else begin
counter<=counter+1;
end
endcase
end
always @(posedge clk) begin
if (count==4'd8) begin
for (integer i =0 ;i<8 ; i++) begin
dout[i]<=dout_tp[i];
dout_tp[i]<=0;
end
count<=0;
counter<=0;
state<=IDLE;
end
end
endmodule