Hello everyone,
I'm an italian student, so I apologize for my english, and I'm new in
the forum, I have to do an exercise: the creation by MSF of a 5-bit
counter using VHDL.
I have various input signals: a STOP signal which stops the count at the
moment, a RESTART signal that resume the count, an UP_DOWN signal to
choose the direction of the count and the signal of RESET.
I have alse 3 output signals: a signal END_C which indicates the end of
the count, a signal START_C which indicates the start and a Q signal
which indicates the value of the count.
This is my VHDL code:
1
libraryieee;
2
useieee.std_logic_1164.all;
3
useieee.std_logic_unsigned.all;
4
5
entityesercizio3is
6
port(CK,stop,restart,reset,up_down:instd_logic;
7
end_c,start_c:outstd_logic;
8
Q:outstd_logic_vector(4downto0));
9
endesercizio3;
10
11
architecturearcofesercizio3is
12
typestatois(ST0,ST1,ST2,ST3);
13
signalps,ns:stato;
14
signaltemp:std_logic_vector(4downto0);
15
begin
16
seq_proc:process(CK,RESET)
17
begin
18
if(RESET='0')then
19
ps<=ST0;
20
elsif(rising_edge(CK))then
21
ps<=ns;
22
endif;
23
endprocessseq_proc;
24
25
comb_proc:process(RESTART,STOP,UP_DOWN,PS)
26
begin
27
end_c<='0';
28
start_c<='0';
29
casepsis
30
whenST0=>
31
temp<="00000";
32
if(stop='0')then
33
ns<=ST0;
34
elsif(up_down='0')then
35
ns<=ST1;
36
else
37
ns<=ST2;
38
endif;
39
40
whenST1=>
41
temp<=temp-"00001";
42
if(stop='0')then
43
ns<=ST3;
44
elsif(up_down='0')then
45
ns<=ST1;
46
else
47
ns<=ST2;
48
endif;
49
50
whenST2=>
51
temp<=temp+"00001";
52
if(stop='0')then
53
ns<=ST3;
54
elsif(up_down<='0')then
55
ns<=ST1;
56
else
57
ns<=ST2;
58
endif;
59
60
whenST3=>
61
if(Restart='1')then
62
ns<=ST3;
63
elsif(up_down='0')then
64
ns<=ST1;
65
else
66
ns<=ST2;
67
endif;
68
whenothers=>
69
ns<=ST0;
70
endcase;
71
Q<=temp;
72
if(temp="00000")then
73
start_c<='1';
74
elsif(temp="11111")then
75
end_c<='1';
76
endif;
77
endprocesscomb_proc;
78
endarc;
The compilation is successful but I get an error in model sim which is:
#**Error: (vsim-3601) Iteration limit reached at time 15ns.
I suppose there is a loop that does not allow proper execution.
Can you help me fix it? Thanks you.
Ok so i have an infinite loop but how can I move the counter into a
cloked process?? Can you please write me a couple of code strings,
because this is the first time I realze a MSF using VHDL and I'm not
practical with it??
Thanks you.
One minor question in advance: what's MSF?
Edoardo Bernardi wrote:> so i have an infinite loop
No. You have a combinatorial loop. That's something entirely
different...
Yes I guess FSM but I wrote it in italian.
Anyway how can I solve my problem? I tried to move the counter into a
cloked process in different way but anything worked.
Edoardo Bernardi wrote:> I tried to move the counter into a> cloked process in different way but anything worked.
What exactly is not working? How does your code look like now, and what
error messages do you get?
Achim S. wrote:> What exactly is not working?
With the code above the counter forms a (gated) combinatorial loop.
Edoardo Bernardi wrote:> Anyway how can I solve my problem?
If you wnat to use the 2 process style (1 clocked for the flipflops plus
1 combinatorial), then you must implement a counter_present and a
counter_next, as you did already for the FSM.
Keep in mind: even each counter is a finite state machine with defined.
First some hints:
1. Why do your states have such indifferent names like ST0, ST1, ST2,
ST3?
Use SPEAKING names for your own data type.
2. And think about clever identation. It helps reading and understanding
source code very much.
3. Do NOT use std_logic_vectors for calculations:
1
signaltemp:std_logic_vector(4downto0);
2
:
3
temp<=temp-"00001";
4
:
5
temp<=temp+"00001";
No one knows whether this calculation above is signed or unsigned...
4. "up_down" is a stupid name for a signal. Does it mean the counter
counts UP and DOWN at the same time? Or what? Is '0' = UP or is '1' =
UP?
5. "when others =>"
In your own type stato there is no other sate! All of the 4 states
ST!..4 are explicitly decoded in the case. So: why "when others"?
But if I had to do that job with using of a FSM for the counter
management, this could be my result:
Lothar Miller wrote:> With the code above the counter forms a (gated) combinatorial loop.
that's true, and in fact I had phrased my question wrongly. What I
really wanted to know was how the actual code looks like and what
error messages Edoardo gets, after he moved the counter to a clocked
process.
Achim S. wrote:> how the actual code looks like and what error messages Edoardo gets,> after he moved the counter to a clocked process.
Indeed, the latest code and its problems may be of interest here... ;-)