OpenCores
URL https://opencores.org/ocsvn/neural_net_perceptron/neural_net_perceptron/trunk

Subversion Repositories neural_net_perceptron

[/] [neural_net_perceptron/] [trunk/] [rtl/] [vhdl/] [p0300_m00027_s_v01_train_fsm.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 fpga_is_fu
-- COPYRIGHT (C) 2022 by Jens Gutschmidt / VIVARE GmbH Switzerland
2
-- (email: opencores@vivare-services.com)
3
-- 
4
-- This program is free software: you can redistribute it and/or modify it
5
-- under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or any
7
-- later version.
8
-- 
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
-- See the GNU General Public License for more details.
13
-- 
14
-- You should have received a copy of the GNU General Public License
15
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
-- 
17
-- 
18
LIBRARY ieee;
19
USE ieee.std_logic_1164.all;
20
USE ieee.std_logic_arith.all;
21
--USE ieee.numeric_std.all;
22
LIBRARY work;
23
USE work.memory_vhd_v03_pkg.ALL;
24
 
25
ENTITY p0300_m00027_s_v01_train_fsm IS
26
   PORT(
27
      clk_i              : IN     std_logic;
28
      cnti_rdy_i         : IN     std_logic;
29
      cntj_rdy_i         : IN     std_logic;
30
      ctrl_clear_epoch_i : IN     std_logic;
31
      ctrl_maxepoch_i    : IN     WB_DATA_WIDTH_T;
32
      ctrl_rdy1_i        : IN     std_logic;
33
      ctrl_rdy2_i        : IN     std_logic;
34
      ctrl_rdy7_i        : IN     std_logic;
35
      ctrl_start_i       : IN     std_logic;
36
      ctrl_wchgd_i       : IN     std_logic;
37
      rst_n_i            : IN     std_logic;
38
      ctrl_epoch_o       : OUT    WB_DATA_WIDTH_T;
39
      ctrl_int_o         : OUT    std_logic;
40
      ctrl_not_rdy_o     : OUT    std_logic;
41
      ctrl_rdy_o         : OUT    std_logic;
42
      ctrl_start1_o      : OUT    std_logic;
43
      ctrl_start2_o      : OUT    std_logic
44
   );
45
 
46
-- Declarations
47
 
48
END p0300_m00027_s_v01_train_fsm ;
49
-- COPYRIGHT (C) 2022 Jens Gutschmidt /
50
-- VIVARE GmbH Switzerland
51
-- (email: opencores@vivare-services.com)
52
-- 
53
-- Versions:
54
-- Revision 1.0  2022/07/04
55
-- -- First draft
56
-- 
57
LIBRARY ieee;
58
USE ieee.std_logic_1164.all;
59
USE ieee.std_logic_arith.all;
60
--USE ieee.numeric_std.all;
61
LIBRARY work;
62
USE work.memory_vhd_v03_pkg.ALL;
63
 
64
ARCHITECTURE fsm OF p0300_m00027_s_v01_train_fsm IS
65
 
66
   -- Architecture Declarations
67
   SIGNAL cnti_rdy_reg : std_logic;
68
   SIGNAL cntj_rdy_reg : std_logic;
69
   SIGNAL ctrl_clear_epoch_reg : std_logic;
70
   SIGNAL ctrl_epoch_reg : WB_DATA_WIDTH_T;
71
   SIGNAL ctrl_int_reg : std_logic;
72
   SIGNAL ctrl_not_rdy_reg : std_logic;
73
   SIGNAL ctrl_rdy1_reg : std_logic;
74
   SIGNAL ctrl_rdy2_reg : std_logic;
75
   SIGNAL ctrl_start_reg : std_logic;
76
 
77
   TYPE STATE_TYPE IS (
78
      S00,
79
      S02,
80
      S03,
81
      S06,
82
      S07,
83
      S10,
84
      S01,
85
      S11,
86
      S12,
87
      S05,
88
      S08,
89
      S04,
90
      S09,
91
      S13
92
   );
93
 
94
   -- Declare current and next state signals
95
   SIGNAL current_state : STATE_TYPE;
96
   SIGNAL next_state : STATE_TYPE;
97
 
98
BEGIN
99
 
100
   -----------------------------------------------------------------
101
   clocked_proc : PROCESS (
102
      clk_i
103
   )
104
   -----------------------------------------------------------------
105
   BEGIN
106
      IF (clk_i'EVENT AND clk_i = '1') THEN
107
         IF (rst_n_i = '0') THEN
108
            current_state <= S00;
109
            -- Default Reset Values
110
            cnti_rdy_reg <= '0';
111
            cntj_rdy_reg <= '0';
112
            ctrl_clear_epoch_reg <= '0';
113
            ctrl_epoch_reg <= (others => '0');
114
            ctrl_int_reg <= '0';
115
            ctrl_not_rdy_reg <= '0';
116
            ctrl_rdy1_reg <= '0';
117
            ctrl_rdy2_reg <= '0';
118
            ctrl_start_reg <= '0';
119
         ELSE
120
            current_state <= next_state;
121
            -- Default Assignment To Internals
122
            cnti_rdy_reg <= cnti_rdy_i;
123
            cntj_rdy_reg <= cntj_rdy_i;
124
            ctrl_clear_epoch_reg <= ctrl_clear_epoch_i;
125
            ctrl_epoch_reg <= ctrl_epoch_reg;
126
            ctrl_int_reg <= '0';
127
            ctrl_not_rdy_reg <= ctrl_not_rdy_reg;
128
            ctrl_rdy1_reg <= ctrl_rdy1_i;
129
            ctrl_rdy2_reg <= ctrl_rdy2_i;
130
            ctrl_start_reg <= ctrl_start_i;
131
 
132
            -- Combined Actions
133
            CASE current_state IS
134
               -- Clear NOT READY
135
               -- register and test for
136
               -- READY
137
               WHEN S02 =>
138
                  ctrl_not_rdy_reg <= '0';
139
               -- Set interrupt
140
               -- flag
141
               WHEN S11 =>
142
                  ctrl_int_reg <= '1';
143
               -- Set NOT READY
144
               -- register if modules
145
               -- are NOT READY
146
               WHEN S12 =>
147
                  ctrl_not_rdy_reg <= '1';
148
               -- Dummy cycle
149
               -- and update
150
               -- EPOCH
151
               WHEN S04 =>
152
                  ctrl_epoch_reg <= unsigned (ctrl_epoch_reg) + ctrl_wchgd_i;
153
               -- Clear EPOCH
154
               -- register
155
               WHEN S13 =>
156
                  ctrl_epoch_reg <= (others => '0');
157
               WHEN OTHERS =>
158
                  NULL;
159
            END CASE;
160
         END IF;
161
      END IF;
162
   END PROCESS clocked_proc;
163
 
164
   -----------------------------------------------------------------
165
   nextstate_proc : PROCESS (
166
      cnti_rdy_reg,
167
      ctrl_clear_epoch_reg,
168
      ctrl_epoch_reg,
169
      ctrl_maxepoch_i,
170
      ctrl_rdy1_reg,
171
      ctrl_rdy2_reg,
172
      ctrl_rdy7_i,
173
      ctrl_start_reg,
174
      ctrl_wchgd_i,
175
      current_state
176
   )
177
   -----------------------------------------------------------------
178
   BEGIN
179
      CASE current_state IS
180
         -- Reset state
181
         WHEN S00 =>
182
            IF (ctrl_rdy7_i = '1') THEN
183
               next_state <= S01;
184
            ELSE
185
               next_state <= S00;
186
            END IF;
187
         -- Clear NOT READY
188
         -- register and test for
189
         -- READY
190
         WHEN S02 =>
191
            IF (ctrl_rdy1_reg = '0' OR
192
                ctrl_rdy2_reg = '0' OR
193
                cnti_rdy_reg = '0') THEN
194
               next_state <= S12;
195
            ELSE
196
               next_state <= S03;
197
            END IF;
198
         -- Start calculation
199
         -- of Y
200
         WHEN S03 =>
201
            next_state <= S04;
202
         -- Wait for CAL_Y
203
         -- is ready
204
         WHEN S06 =>
205
            IF (ctrl_rdy1_reg = '1') THEN
206
               next_state <= S07;
207
            ELSE
208
               next_state <= S06;
209
            END IF;
210
         -- Start calculation
211
         -- of BIAS and W
212
         WHEN S07 =>
213
            next_state <= S08;
214
         -- Loop again if
215
         -- W was changed
216
         WHEN S10 =>
217
            IF (ctrl_rdy2_reg = '1' AND
218
                ctrl_wchgd_i = '1' AND
219
                ( unsigned (ctrl_maxepoch_i) = 0 OR
220
                  unsigned (ctrl_maxepoch_i) >= unsigned (ctrl_epoch_reg) )) THEN
221
               next_state <= S03;
222
            ELSIF (ctrl_rdy2_reg = '1') THEN
223
               next_state <= S11;
224
            ELSE
225
               next_state <= S10;
226
            END IF;
227
         -- Wait for next
228
         -- training or clear
229
         -- EPOCH register
230
         WHEN S01 =>
231
            IF (ctrl_start_reg = '1' AND
232
                ctrl_clear_epoch_reg = '1') THEN
233
               next_state <= S13;
234
            ELSIF (ctrl_start_reg = '1') THEN
235
               next_state <= S02;
236
            ELSE
237
               next_state <= S01;
238
            END IF;
239
         -- Set interrupt
240
         -- flag
241
         WHEN S11 =>
242
            next_state <= S01;
243
         -- Set NOT READY
244
         -- register if modules
245
         -- are NOT READY
246
         WHEN S12 =>
247
            next_state <= S01;
248
         -- Dummy cycle
249
         WHEN S05 =>
250
            next_state <= S06;
251
         -- Dummy cycle
252
         WHEN S08 =>
253
            next_state <= S09;
254
         -- Dummy cycle
255
         -- and update
256
         -- EPOCH
257
         WHEN S04 =>
258
            next_state <= S05;
259
         -- Dummy cycle
260
         WHEN S09 =>
261
            next_state <= S10;
262
         -- Clear EPOCH
263
         -- register
264
         WHEN S13 =>
265
            next_state <= S02;
266
         WHEN OTHERS =>
267
            next_state <= S00;
268
      END CASE;
269
   END PROCESS nextstate_proc;
270
 
271
   -----------------------------------------------------------------
272
   output_proc : PROCESS (
273
      ctrl_epoch_reg,
274
      ctrl_int_reg,
275
      ctrl_not_rdy_reg,
276
      current_state
277
   )
278
   -----------------------------------------------------------------
279
   BEGIN
280
      -- Default Assignment
281
      ctrl_epoch_o <= ctrl_epoch_reg;
282
      ctrl_int_o <= ctrl_int_reg;
283
      ctrl_not_rdy_o <= ctrl_not_rdy_reg;
284
      ctrl_rdy_o <= '0';
285
      ctrl_start1_o <= '0';
286
      ctrl_start2_o <= '0';
287
 
288
      -- Combined Actions
289
      CASE current_state IS
290
         -- Start calculation
291
         -- of Y
292
         WHEN S03 =>
293
            ctrl_start1_o <= '1';
294
         -- Start calculation
295
         -- of BIAS and W
296
         WHEN S07 =>
297
            ctrl_start2_o <= '1';
298
         -- Wait for next
299
         -- training or clear
300
         -- EPOCH register
301
         WHEN S01 =>
302
            ctrl_rdy_o <= '1';
303
         WHEN OTHERS =>
304
            NULL;
305
      END CASE;
306
   END PROCESS output_proc;
307
 
308
END fsm;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.