-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeuralNet.v
More file actions
63 lines (48 loc) · 1.5 KB
/
NeuralNet.v
File metadata and controls
63 lines (48 loc) · 1.5 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
module ModularNeuralNet(
input clk_, c, d, wr, output [1:0] checkP, output [2:0] check
);
reg [17:0] shf; //shift register
wire [8:0] ADDR; //addres word
wire [7:0] DATA; //data word
wire RS;
assign ADDR = shf[16:8];
assign DATA = shf[7:0];
assign RS = shf[17];
always@(posedge c)begin //shift register driver
shf = shf >> 1;
shf[17] = d;
end
parameter multiSum = 399;
net#(multiSum) ALU(clk_, wr, ADDR, DATA, RS, checkP, check);
endmodule
module net#(multiSum = 2)(
input clk_, wr, [8:0] ADDR, [7:0] DATA, [0:0] RS, output reg [1:0] checkP, output [2:0] check, reg [3:0] data
);
reg signed [7:0] A [multiSum:0]; //input neuron values
reg signed [7:0] B [multiSum:0]; //neural connection weights
always@(posedge wr)begin //saving the sent message in acordation to RS
case(RS)
0 : A[ADDR] = DATA;
1 : B[ADDR] = DATA;
endcase
end
reg signed [25:0] SUM;
integer j;
always@(1)begin
SUM = 0;
for(j = 0; j <= multiSum; j = j + 1)begin
SUM = SUM + (A[j] * B[j]);
end
end
assign check[0] = SUM == 0;
assign check[1] = SUM > 0;
assign check[2] = SUM < 0;
always@(1)begin
case(check)
'd1 : checkP = 'd1;
'd2 : checkP = 'd2;
'd4 : checkP = 'd3;
default : checkP = 'd0;
endcase
end
endmodule