LIBRARY ieee use ieee std_logic_1164 all ENTITY div_cu1 IS PORT reset

  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
LIBRARY ieee;
use ieee.std_logic_1164.all;
ENTITY div_cu1 IS
PORT(reset: IN std_logic;
start: IN std_logic;
c_ex: IN std_logic;
clk: IN std_logic;
r_mode0: OUT std_logic;
r_mode1: OUT std_logic;
alu_enable: OUT std_logic;
alu_type: OUT std_logic ;
bit_enable: OUT std_logic;
b_enable: OUT std_logic;
q_mode0: OUT std_logic;
q_mode1: OUT std_logic);
END div_cu1;
ARCHITECTURE state_machine OF div_cu1 IS
SUBTYPE count_integer IS INTEGER RANGE 0 TO 4;
TYPE states IS(idle,init,beg_shift,sub,test1,r_neg,shift,test2,fin_shift);
SIGNAL present_state: states:=idle;
SIGNAL next_state: states:=idle;
SIGNAL present_count: count_integer:=0;
SIGNAL next_count: count_integer:=0;
BEGIN
--------------------Работа счетчиков цикла---------------------
CLKD: PROCESS(clk,reset)
BEGIN
IF(reset='1')THEN
present_state<=idle;
present_count<=0;
ELSIF(clk'EVENT AND clk='1') THEN
present_state<=next_state;
present_count<=next_count;
END IF;
END PROCESS CLKD;
----------------Процесс перехода из одного состояния-------------
STATE_TRANS: PROCESS(present_state,present_count,start,c_ex)
BEGIN
next_state <= present_state;
next_count <= present_count;
CASE present_state IS
WHEN idle=>
IF(start='1')THEN
next_state<=init;
ELSE
next_state<=idle;
END IF;
next_count<=present_count;
WHEN init=>
next_state<=beg_shift;
next_count<=present_count;
WHEN beg_shift=>
next_state<=sub;
next_count<=present_count;
WHEN sub=>
next_state<=test1;
next_count<=present_count;
WHEN test1=>
IF c_ex = '1' THEN
next_state<=r_neg;
ELSE next_state<=shift;
END IF;
next_count<=present_count;
WHEN r_neg=>
next_state<=shift;
next_count<=present_count;
WHEN shift=>
next_state<=test2;
next_count<=present_count+1;
WHEN test2=>
IF present_count < 4 THEN
next_state <= sub;
ELSE next_state <= fin_shift;
END IF;
next_count<=present_count;
WHEN fin_shift=>
next_state <= idle;
next_count<=present_count;
WHEN OTHERS=>
next_state<=idle;
next_count<=present_count;
END CASE;
END PROCESS STATE_TRANS;
---Процесс выдачи управляющих сигналов в блок обработки данных DP ---
OUTPUT: PROCESS(present_state)
BEGIN
CASE present_state IS
WHEN idle=>
r_mode0 <= '0';
r_mode1 <= '0';
alu_enable <= '0';
alu_type <= '0';
bit_enable <= '0';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
WHEN init=>
r_mode0 <= '1';
r_mode1 <= '1';
alu_enable <= '1';
alu_type <= '0';
bit_enable <= '0';
b_enable <= '1';
q_mode0 <= '1';
q_mode1 <= '1';
WHEN beg_shift=>
r_mode0 <= '1';
r_mode1 <= '0';
alu_enable <= '0';
alu_type <= '0';
bit_enable <= '1';
b_enable <= '0';
q_mode0 <= '1';
q_mode1 <= '0';
WHEN sub=>
r_mode0 <= '1';
r_mode1 <= '1';
alu_enable <= '1';
alu_type <= '1';
bit_enable <= '1';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
WHEN test1=>
r_mode0 <= '0';
r_mode1 <= '0';
alu_enable <= '0';
alu_type <= '0';
bit_enable <= '1';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
WHEN r_neg=>
r_mode0 <= '1';
r_mode1 <= '1';
alu_enable <= '1';
alu_type <= '0';
bit_enable <= '0';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
WHEN shift=>
r_mode0 <= '1';
r_mode1 <= '0';
alu_enable <= '0';
bit_enable <= '1';
b_enable <= '0';
q_mode0 <= '1';
q_mode1 <= '0';
WHEN test2=>
r_mode0 <= '0';
r_mode1 <= '0';
alu_enable <= '0';
bit_enable <= '0';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
WHEN fin_shift=>
r_mode0 <= '0';
r_mode1 <= '1';
alu_enable <= '0';
bit_enable <= '0';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
WHEN OTHERS=>
r_mode0 <= '0';
r_mode1 <= '0';
alu_enable <= '0';
bit_enable <= '0';
b_enable <= '0';
q_mode0 <= '0';
q_mode1 <= '0';
END CASE;
END PROCESS OUTPUT;
END state_machine;