@@ -8,16 +8,26 @@ module Conv(
88 output reg out_st
99);
1010
11+ // //////////////////////////////Load Data////////////////////////////
1112reg start_conv, load_data_status;
12- reg [15 :0 ] conv_result [0 :35 ];
1313reg [7 :0 ] input_feature [0 :63 ];
14- reg cycle ;
15- reg [2 :0 ] line, row;
16- reg [15 :0 ] temp[0 :8 ];
1714reg [5 :0 ] data_counter ;
15+ // //////////////////////////////////////////////////////////////////
16+
17+ // //////////////////////////////Convolution/////////////////////////
18+ reg [19 :0 ] conv_result [0 :35 ]; // 原來是 20 bits , 但我們只取 16 bits(6,10)fixed point
19+ reg [19 :0 ] temp[0 :8 ];
20+ reg [2 :0 ] line, row;
21+ reg cycle ;
22+ // //////////////////////////////////////////////////////////////////
23+
1824
25+ // /////////////////////////////Output///////////////////////////////
26+ reg [5 :0 ] output_counter ;
27+ reg output_data_status;
28+ // //////////////////////////////////////////////////////////////////
1929
20- // 3x3 fixed -point kernel
30+ // //////////////////////////////Fixed -point Kernel///////////////////
2131reg [7 :0 ] fixed_kernel [0 :8 ] ;
2232initial begin
2333 fixed_kernel[0 ] = 8'b00001000 ; // 0.0625 -> 00001000
@@ -29,15 +39,22 @@ initial begin
2939 fixed_kernel[6 ] = 8'b00001000 ; // 0.0625 -> 00001000
3040 fixed_kernel[7 ] = 8'b00010000 ; // 0.125 -> 00010000
3141 fixed_kernel[8 ] = 8'b00001000 ; // 0.0625 -> 00001000
32-
33- start_conv = 1'b0 ;
34- load_data_status = 1'b0 ;
35- cycle = 1'b0 ;
36- line = 3'b000 ;
37- row = 3'b000 ;
38- data_counter = 6'b000000 ;
39- out_st = 1'b0 ;
4042end
43+ // //////////////////////////////////////////////////////////////////
44+
45+ // //////////////////////////////initial/////////////////////////////
46+ initial begin
47+ start_conv <= 1'b0 ;
48+ load_data_status <= 1'b0 ;
49+ data_counter <= 6'b000000 ;
50+ line <= 3'b000 ;
51+ row <= 3'b000 ;
52+ cycle <= 1'b0 ;
53+ out_st <= 1'b0 ;
54+ output_counter <= 6'b000000 ;
55+ output_data_status <= 1'b0 ;
56+ end
57+ // //////////////////////////////////////////////////////////////////
4158
4259always @(posedge clk) begin
4360
@@ -48,6 +65,16 @@ always @(posedge clk) begin
4865 data_counter <= 6'b000000 ;
4966 load_data_status <= 1'b0 ;
5067 start_conv <= 1'b1 ;
68+ $display ("Input Feature Get From RAM: " );
69+ $display (" %b %b %b %b %b %b %b %b" , input_feature[0 ], input_feature[1 ], input_feature[2 ], input_feature[3 ], input_feature[4 ], input_feature[5 ], input_feature[6 ], input_feature[7 ]);
70+ $display (" %b %b %b %b %b %b %b %b" , input_feature[8 ], input_feature[9 ], input_feature[10 ], input_feature[11 ], input_feature[12 ], input_feature[13 ], input_feature[14 ], input_feature[15 ]);
71+ $display (" %b %b %b %b %b %b %b %b" , input_feature[16 ], input_feature[17 ], input_feature[18 ], input_feature[19 ], input_feature[20 ], input_feature[21 ], input_feature[22 ], input_feature[23 ]);
72+ $display (" %b %b %b %b %b %b %b %b" , input_feature[24 ], input_feature[25 ], input_feature[26 ], input_feature[27 ], input_feature[28 ], input_feature[29 ], input_feature[30 ], input_feature[31 ]);
73+ $display (" %b %b %b %b %b %b %b %b" , input_feature[32 ], input_feature[33 ], input_feature[34 ], input_feature[35 ], input_feature[36 ], input_feature[37 ], input_feature[38 ], input_feature[39 ]);
74+ $display (" %b %b %b %b %b %b %b %b" , input_feature[40 ], input_feature[41 ], input_feature[42 ], input_feature[43 ], input_feature[44 ], input_feature[45 ], input_feature[46 ], input_feature[47 ]);
75+ $display (" %b %b %b %b %b %b %b %b" , input_feature[48 ], input_feature[49 ], input_feature[50 ], input_feature[51 ], input_feature[52 ], input_feature[53 ], input_feature[54 ], input_feature[55 ]);
76+ $display (" %b %b %b %b %b %b %b %b" , input_feature[56 ], input_feature[57 ], input_feature[58 ], input_feature[59 ], input_feature[60 ], input_feature[61 ], input_feature[62 ], input_feature[63 ]);
77+
5178 end
5279 else begin
5380 data_counter <= data_counter + 1 ;
6491always @ (posedge clk) begin
6592 if (start_conv == 1'b1 ) begin
6693 if (cycle == 1 ) begin
67- if (row < 6 ) begin // 檢查 row 的範圍
94+ if (row < 5 ) begin // 檢查 row 的範圍
6895 row <= row + 1 ;
6996 end
7097 else begin
7198 row <= 0 ;
72- if (line < 6 ) begin // 檢查 line 的範圍
99+ if (line < 5 ) begin // 檢查 line 的範圍
73100 line <= line + 1 ;
74101 end
75102 else begin
76103 line <= 0 ;
77104 start_conv <= 1'b0 ;
78105 out_st <= 1'b1 ;
106+ output_data_status <= 1'b1 ;
79107 end
80108 end
81109 cycle <= 0 ;
@@ -104,12 +132,13 @@ end
104132
105133// Output the result 6x6 matrix
106134always @(posedge clk) begin
107- if ( out_st == 1'b1 ) begin
108- dout = conv_result[data_counter] ;
109- data_counter <= data_counter + 1 ;
110- if (data_counter == 35 ) begin
111- data_counter <= 6'b000000 ;
112- out_st <= 0 ;
135+ if ( output_data_status == 1'b1 ) begin
136+ dout = conv_result[output_counter] ;
137+ output_counter <= output_counter + 1 ;
138+ out_st <= 1'b0 ;
139+ if (output_counter == 36 ) begin // 6x6 matrix
140+ output_counter <= 6'b000000 ;
141+ output_data_status <= 1'b0 ;
113142 end
114143 end
115144end
0 commit comments