Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Calculator with VHDL - simulation problem

Status
Not open for further replies.

true_niea

Newbie level 3
Joined
Feb 5, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,345
hai

hello could anyone can help me with this coding... im doing my mini project.. but the problem is after write the vhdl code for calculator coding show no prob but when i try to simulate show no output

here i attach the coding


Code VHDL - [expand]
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
 
entity calculator is
port(A,B : in integer range 0 to 7;
clk : in bit;
sel : in std_logic_vector(1 downto 0);
Q : out bit_vector(6 downto 0);
An : out bit_vector(3 downto 0));
 
end calculator;
 
architecture Behavioral of calculator is
signal sub : integer range 0 to 7;
signal sum : integer range 0 to 14;
signal div : integer range 0 to 7;
signal Mul : integer range 0 to 49;
 
signal Qsub,Qsum1,Qsum2,Qmul,Qmul2,Qdiv :bit_vector(6 downto 0);
signal minus : bit_vector(6 downto 0);
 
signal divRemainder:bit_vector(6 downto 0);
signal B1:bit_vector(6 downto 0);
 
signal clk1: bit;
 
 
begin
 
clkDiv : process
variable count :integer range 0 to 50000000;
begin
wait until clk'event and clk='1';
count := count + 1;
if (count = 50000000) then
count := 0;
elsif (count < 25000000) then
clk1 <= '0';
elsif (count > 25000000) then
clk1 <= '1';
end if;
end process clkDiv;
 
 
sub_opration : process(A,B)
begin
 
 
if(A>B) then
sub<=A-B;
minus<="1111111";
case sub is
when 0 =>Qsub <="1000000";
when 1 =>Qsub<="1111001";
when 2 =>Qsub<="0100100";
when 3 =>Qsub<="0110000";
when 4 =>Qsub<="0011001";
when 5 =>Qsub<="0010010";
when 6 =>Qsub<="0000010";
when 7 =>Qsub<="1011000";
when others => null;
end case;
 
else
sub<=B-A;
minus<="0111111";
case sub is
when 0 =>Qsub<="1000000";
when 1 =>Qsub<="1111001";
when 2 =>Qsub<="0100100";
when 3 =>Qsub<="0110000";
when 4 =>Qsub<="0011001";
when 5 =>Qsub<="0010010";
when 6 =>Qsub<="0000010";
when 7 =>Qsub<="1011000";
when others => null;
end case;
end if;
 
 
end process sub_opration;
 
sum_opration : process(A,B)
begin
 
sum<=A+B;
 
case sum is
 
when 0 =>Qsum1<="1000000";
Qsum2<="1111111";
when 1 =>Qsum1<="1111001";
Qsum2<="1111111";
when 2 =>Qsum1<="0100100";
Qsum2<="1111111";
when 3 =>Qsum1<="0110000";
Qsum2<="1111111";
when 4 =>Qsum1<="0011001";
Qsum2<="1111111";
when 5 =>Qsum1<="0010010";
Qsum2<="1111111";
when 6 =>Qsum1<="0000010";
Qsum2<="1111111";
when 7 =>Qsum1<="1011000";
Qsum2<="1111111";
when 8 =>Qsum1<="0000000";
Qsum2<="1111111";
when 9 =>Qsum1<="0010000";
Qsum2<="1111111";
when 10=>Qsum1<="1000000";
Qsum2<="1111001";
when 11=>Qsum1<="1111001";
Qsum2<="1111001";
when 12=>Qsum1<="0100100";
Qsum2<="1111001";
when 13=>Qsum1<="0110000";
Qsum2<="1111001";
when 14=>Qsum1<="0011001";
Qsum2<="1111001";
when others => null;
end case;
 
 
end process sum_opration;
 
Mul_operation : process(A,B)
variable Remm10:integer range 0 to 9;
variable C1: integer range 1 to 7 :=7;
begin
Mul<= A*B;
 
if(Mul<10) then
case Mul is
when 0 =>Qmul<="1000000";
Qmul2<="1111111";
when 1 =>Qmul<="1111001";
Qmul2<="1111111";
when 2 =>Qmul<="0100100";
Qmul2<="1111111";
when 3 =>Qmul<="0110000";
Qmul2<="1111111";
when 4 =>Qmul<="0011001";
Qmul2<="1111111";
when 5 =>Qmul<="0010010";
Qmul2<="1111111";
when 6 =>Qmul<="0000010";
Qmul2<="1111111";
when 7 =>Qmul<="1011000";
Qmul2<="1111111";
when 8 =>Qmul<="0000000";
Qmul2<="1111001";
when 9 =>Qmul<="0010000";
Qmul2<="1111111";
when others => null;
end case;
 
else
for j in 7 downto 1 loop
 
if(10*C1<Mul or 10*C1= Mul)then
Mul<=10*C1;
Remm10:=10*C1-Mul;
end if;
C1:=C1-1;
 
end loop;
 
case Mul is
when 0 =>Qmul2<="1000000";
when 1 =>Qmul2<="1111001";
when 2 =>Qmul2<="0100100";
when 3 =>Qmul2<="0110000";
when 4 =>Qmul2<="0011001";
when 5 =>Qmul2<="0010010";
when 6 =>Qmul2<="0000010";
when 7 =>Qmul2<="1011000";
when 8 =>Qmul2<="0000000";
when 9 =>Qmul2<="0010000";
when others => null;
end case;
 
case Remm10 is
when 0 =>Qmul<="1000000";
when 1 =>Qmul<="1111001";
when 2 =>Qmul<="0100100";
when 3 =>Qmul<="0110000";
when 4 =>Qmul<="0011001";
when 5 =>Qmul<="0010010";
when 6 =>Qmul<="0000010";
when 7 =>Qmul<="1011000";
when 8 =>Qmul<="0000000";
when 9 =>Qmul<="0010000";
when others => null;
end case;
 
end if;
 
end process Mul_operation;
 
div_operation: process(A,B)
variable C : integer range 1 to 7 :=7;
variable Remm:integer range 0 to 9;
begin
 
for I in 7 downto 1 loop
 
if(A=B)then
div<=1;
Remm:=0;
 
elsif(B>A)then
div<=0;
 
elsif(A>B)then
if(B*C<A)then
div<=B*C;
Remm:=B*C-A; --the result will display as: div _| Remainder _| B
end if;
C:=C-1;
end if;
 
end loop;
 
case div is
when 0 =>Qdiv<="1000000";
when 1 =>Qdiv<="1111001";
when 2 =>Qdiv<="0100100";
when 3 =>Qdiv<="0110000";
when 4 =>Qdiv<="0011001";
when 5 =>Qdiv<="0010010";
when 6 =>Qdiv<="0000010";
when 7 =>Qdiv<="1011000";
when others => null;
end case;
 
case Remm is
when 0 =>divRemainder<="1000000";
when 1 =>divRemainder<="1111001";
when 2 =>divRemainder<="0100100";
when 3 =>divRemainder<="0110000";
when 4 =>divRemainder<="0011001";
when 5 =>divRemainder<="0010010";
when 6 =>divRemainder<="0000010";
when 7 =>divRemainder<="1011000";
when others => null;
end case;
 
case B is
when 0 =>B1<="1000000";
when 1 =>B1<="1111001";
when 2 =>B1<="0100100";
when 3 =>B1<="0110000";
when 4 =>B1<="0011001";
when 5 =>B1<="0010010";
when 6 =>B1<="0000010";
when 7 =>B1<="1011000";
when others => null;
end case;
 
end process div_operation;
 
 
choice : process(clk1,sel)
variable m : integer range 0 to 3 := 0;
begin
if(clk1'event and clk1 = '1') then
 
case m is
when 0 =>
if(sel = "00") then
Q <= Qsub;
elsif(sel="01") then
Q<=Qsum1;
elsif(sel="10") then
Q<=Qmul;
elsif(sel="11") then
Q<=B1;
end if;
An<="1110";
 
when 1 =>
if(sel = "00") then
Q <= minus;
elsif(sel="01") then
Q<=Qsum2;
elsif(sel="10") then
Q<=Qmul2;
elsif(sel="11") then
Q<="1110011"; -- display _|
end if;
An<="1101";
 
when 2 =>
if(sel="11") then
Q<= divRemainder;
end if;
An<="1011";
 
when 3 =>
if (sel="11") then
Q<= Qdiv;
end if;
An<="0111";
 
end case;
m := m + 1;
end if;
end process choice;
end Behavioral;

 
Last edited by a moderator:

Marcel Majoor

Full Member level 2
Joined
Jan 17, 2004
Messages
148
Helped
69
Reputation
138
Reaction score
39
Trophy points
1,308
Activity points
1,569
Re: hai

You are not 'patient' enough.

You seem to use Clk1 to update Q and An. This Clk1 is derived from the 'main' clock Clk, which is basically divided by 25000000. In your simulation you only have 1 Clk cycle ... Just wait 25000000 cycles and more, and you will see some result appearing in Q and An.
Or, change the clkDiv process so Clk1 runs 'faster' ....
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top