-
Notifications
You must be signed in to change notification settings - Fork 2
/
direction_ganglion.v
126 lines (114 loc) · 2.53 KB
/
direction_ganglion.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: Hyperflexion
// Engineer: Mert İnan
//
// Create Date: 16:31:40 12/19/2015
// Design Name:
// Module Name: direction_ganglion
// Project Name: BRAIN:M
// Target Devices: Basys2 FPGA Board
// Tool versions:
// Description: This is the direction recognizing neural code that is used in the
// BRAIN:M module.
// Revision:
// Revision 0.01 - File Created
//////////////////////////////////////////////////////////////////////////////////
module direction_ganglion(clk, dist, start, dir, colrcode, flat);
input clk, start, dir;
input [99:0] dist;
output reg colrcode;
output reg [6:0] flat;
reg [3:0] state, nextstate;
reg [25:0] cnt, cntNext;
reg [6:0] ascnt, ascntNext, dscnt, dscntNext;
reg [99:0] dReg, dRegNext, prevReg, prevRegNext;
//Sequential Logic
always @(posedge clk)
begin
state <= nextstate;
cnt <= cntNext;
ascnt <= ascntNext;
dscnt <= dscntNext;
dReg <= dRegNext;
prevReg <= prevRegNext;
end
//Combinational Logic
always @(state or dir or prevReg or dscnt or dReg or
cnt or ascnt or start or dist)
case(state)
4'b0000:
begin
cntNext = 26'b0;
ascntNext = 7'b0;
dscntNext = 7'b0;
dRegNext = 100'b0;
prevRegNext = 100'b0;
nextstate= (start)? 4'b0001:4'b0000;
end
4'b0001:
begin
dRegNext = dist;
nextstate = 4'b0010;
end
4'b0010:
begin
cntNext = cnt + 1;
if(cnt < 26'b10111110101111000001111111)
nextstate = 4'b0010;
else
nextstate = 4'b0011;
end
4'b0011:
begin
prevRegNext = dReg;
dRegNext = dist;
cntNext = 26'b0;
nextstate = 4'b0100;
end
4'b0100:
begin
if (prevReg > dReg)
nextstate = 4'b0101;
else if (prevReg < dReg)
nextstate = 4'b0110;
else
nextstate = 4'b0010;
end
4'b0101:
begin
dscntNext = dscnt + 1;
nextstate = (start)? 4'b0010:4'b0111;
end
4'b0110:
begin
ascntNext = ascnt + 1;
nextstate = (start)? 4'b0010:4'b0111;
end
4'b0111:
nextstate = (dir)? 4'b1000:4'b1001;
4'b1000:
begin
flat = ascnt;
colrcode = 1'b1;
nextstate = 4'b0000;
end
4'b1001:
begin
flat = dscnt;
colrcode = 1'b0;
nextstate = 4'b0000;
end
default:
begin
nextstate = 4'b0000;
cntNext = 26'b0;
ascntNext = 7'b0;
dscntNext = 7'b0;
dRegNext = 100'b0;
prevRegNext = 100'b0;
flat = 7'b0;
colrcode = 1'b0;
end
endcase
endmodule