-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathintelligent_stimuli_comparison_unit.v
327 lines (298 loc) · 7.07 KB
/
intelligent_stimuli_comparison_unit.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 18:06:42 12/19/2015
// Design Name:
// Module Name: intelligent_stimuli_comparison_unit
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module intelligent_stimuli_comparison_unit(clk, E, asc, dsc, mode, read1, read2, colr1, colr2, colr, oe, dot_m, r_Addr1, r_Addr2);
input clk, E, mode, colr1, colr2;
input [6:0] asc, dsc;
input [11:0] read1, read2;
output reg colr, oe;
output reg [4:0] dot_m, r_Addr1, r_Addr2;
reg [4:0] state, nextstate, r_Addr1Next, r_Addr2Next;
reg [7:0] ascReg, ascRegNext, dscReg, dscRegNext,
remReg1, remReg1Next, remReg2, remReg2Next;
reg [27:0] cnt, cntNext;
//Sequential Logic
always @(posedge clk)
begin
state <= nextstate;
ascReg <= ascRegNext;
dscReg <= dscRegNext;
remReg1 <= remReg1Next;
remReg2 <= remReg2Next;
cnt <= cntNext;
r_Addr1 <= r_Addr1Next;
r_Addr2 <= r_Addr2Next;
end
//Combinational Logic
always @(*)
case(state)
5'b00000:
begin
ascRegNext = 8'b0;
dscRegNext = 8'b0;
cntNext = 28'b0;
remReg1Next = 8'b0;
remReg2Next = 8'b0;
nextstate = (mode)? 5'b00001: 5'b00000;
end
5'b00001:
begin
ascRegNext = {1'b0, asc[6:0]}; //Concatanation for zero extension
dscRegNext = {1'b0, dsc[6:0]};
nextstate = (E)? 5'b00010:5'b00011;
end
5'b00010:
begin
r_Addr1Next = 5'b0;
r_Addr2Next = 5'b0;
nextstate = 5'b00100;
end
5'b00011:
begin
r_Addr1Next = 5'b10100;
r_Addr2Next = 5'b10100;
nextstate = 5'b10001;
end
5'b00100:
begin
remReg1Next = ascReg - {1'b0, read1[11:5]};
remReg2Next = dscReg - {1'b0, read2[11:5]};
if ( !(r_Addr1 < 5'b10100) && !(r_Addr2 < 5'b10100))
nextstate = 5'b00000;
else if ( !(r_Addr1 < 5'b10100) && (r_Addr2 < 5'b10100))
nextstate = 5'b01011;
else if (r_Addr1 < 5'b10100)
nextstate = 5'b00101;
else
nextstate = 5'b00100;
end
5'b00101:
if (remReg1[7] == 1)
nextstate = 5'b00110;
else if (remReg1 == 8'b00000000)
nextstate = 5'b01000;
else if (remReg1 > 8'b00000000)
nextstate = 5'b01001;
else
nextstate = 5'b00101;
5'b00110:
begin
r_Addr1Next = r_Addr1 + 1;
nextstate = 5'b00111;
end
5'b00111:
if (r_Addr1 < 5'b10100)
nextstate = 5'b00101;
else if (!(r_Addr1 < 5'b10100))
nextstate = 5'b01011;
else
nextstate = 5'b00111;
5'b01000:
begin
colr = colr1;
dot_m = read1[4:0];
cntNext = cnt + 1;
oe = 1'b1;
if (cnt < 28'b1000111100001101000101111111)
nextstate = 5'b01000;
else if (!(cnt < 28'b1000111100001101000101111111))
nextstate = 5'b01010;
end
5'b01001:
begin
ascRegNext = remReg1;
nextstate = 5'b00010;
end
5'b01010:
begin
oe = 1'b0;
cntNext = 28'b0;
if (r_Addr1 < 5'b10100)
nextstate = 5'b00101;
else if (!(r_Addr1 < 5'b10100))
nextstate = 5'b01011;
else
nextstate = 5'b01010;
end
5'b01011:
if (remReg2[7] == 1)
nextstate = 5'b01100;
else if (remReg2 == 8'b00000000)
nextstate = 5'b01110;
else if (remReg2 > 8'b00000000)
nextstate = 5'b01111;
else
nextstate = 5'b01011;
5'b01100:
begin
r_Addr2Next = r_Addr2 + 1;
nextstate = 5'b01101;
end
5'b01101:
if (r_Addr2 < 5'b10100)
nextstate = 5'b01011;
else if (!(r_Addr2 < 5'b10100))
nextstate = 5'b00000;
else
nextstate = 5'b01101;
5'b01110:
begin
colr = colr2;
dot_m = read2[4:0];
cntNext = cnt + 1;
oe = 1'b1;
if (cnt < 28'b1000111100001101000101111111)
nextstate = 5'b01110;
else if (!(cnt < 28'b1000111100001101000101111111))
nextstate = 5'b10000;
else
nextstate = 5'b01110;
end
5'b01111:
begin
dscRegNext = remReg2;
r_Addr2Next = 5'b00000;
nextstate = 5'b00100;
end
5'b10000:
begin
oe = 1'b0;
cntNext = 28'b0;
if (r_Addr2 < 5'b10100)
nextstate = 5'b01011;
else if (!(r_Addr2 < 5'b10100))
nextstate = 5'b00000;
else
nextstate = 5'b10000;
end
5'b10001:
begin
remReg1Next = ascReg - {1'b0, read1[11:5]};
remReg2Next = dscReg - {1'b0, read2[11:5]};
cntNext = 28'b0;
oe = 1'b0;
if ((r_Addr1 == 5'b00000) && (r_Addr2 == 5'b00000))
nextstate = 5'b00000;
else if ((r_Addr1 == 5'b00000) && !(r_Addr2 == 5'b00000))
nextstate = 5'b10110;
else if ( !(r_Addr1 == 5'b00000))
nextstate = 5'b10010;
else
nextstate = 5'b10001;
end
5'b10010:
if (remReg1[7] > 8'b00000000)
nextstate = 5'b10100;
else if (remReg1 == 8'b00000000)
nextstate = 5'b10011;
else
nextstate = 5'b10010;
5'b10011:
begin
colr = colr1;
dot_m = read1[4:0];
oe = 1'b1;
cntNext = cnt + 1;
if (cnt < 28'b1000111100001101000101111111)
nextstate = 5'b10011;
else if (!(cnt < 28'b1000111100001101000101111111))
nextstate = 5'b10110;
else
nextstate = 5'b10011;
end
5'b10100:
begin
colr = colr1;
dot_m = read1[4:0];
oe = 1'b1;
r_Addr1Next = r_Addr1 - 1;
ascRegNext = remReg1;
nextstate = 5'b10101;
end
5'b10101:
begin
cntNext = cnt + 1;
if (cnt < 28'b1000111100001101000101111111)
nextstate = 5'b10101;
else if ( !(cnt < 28'b1000111100001101000101111111) && r_Addr1 != 8'b00000000)
nextstate = 5'b10001;
else if ( cnt < 28'b1000111100001101000101111111 && r_Addr1 == 8'b00000000)
nextstate = 5'b10110;
end
5'b10110:
begin
cntNext = 28'b0;
oe = 1'b0;
if (remReg2 == 8'b00000000)
nextstate = 5'b11000;
else if (remReg2 > 8'b00000000)
nextstate = 5'b10111;
else
nextstate = 5'b10110;
end
5'b10111:
begin
colr = colr2;
dot_m = read2[4:0];
oe = 1'b1;
r_Addr2Next = r_Addr2 - 1;
dscRegNext = remReg2;
nextstate = 5'b10101;
end
5'b11000:
begin
colr = colr2;
dot_m = read2[4:0];
oe = 1'b1;
cntNext = cnt + 1;
if (cnt < 28'b1000111100001101000101111111)
nextstate = 5'b11000;
else if (!(cnt < 28'b1000111100001101000101111111))
nextstate = 5'b00000;
else
nextstate = 5'b11000;
end
5'b11001:
begin
cntNext = cnt + 1;
if (cnt < 28'b1000111100001101000101111111)
nextstate = 5'b11001;
else if ( !(cnt < 28'b1000111100001101000101111111) && r_Addr2 == 8'b00000000)
nextstate = 5'b00000;
else if ( !(cnt < 28'b1000111100001101000101111111) && r_Addr2 != 8'b00000000)
nextstate = 5'b10110;
else
nextstate = 5'b11001;
end
default:
begin
ascRegNext = 8'b0;
dscRegNext = 8'b0;
cntNext = 28'b0;
remReg1Next = 8'b0;
remReg2Next = 8'b0;
r_Addr1Next = 5'b0;
r_Addr2Next = 5'b0;
colr = 1'b0;
dot_m = 5'b0;
oe = 1'b0;
end
endcase
endmodule