Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - VHDL Loops Execution

 
Thread Tools Search this Thread
Old 09-02-2008, 11:24 PM   #1
Default VHDL Loops Execution


I am learning VHDL and one thing i still dont get is how loops are
executed in the vhdl. For, example i have code that will write to a
file for debugging perposes and it is implemented using a while loop:
while word_write_count < 32 loop

write ( trace_line,string'("Address: "));
write ( trace_line,word_write_count);
write ( trace_line,string'(" "));
write
( trace_line,To_bitvector(frame_information(word_wri te_count)));
writeline (load_file,trace_line);

word_write_count := word_write_count + 1;

end loop;
But i still dont get in what sequence this code will execute. Will it
execute top to bottom? If so will changes made in the above line be
accessible to lines below it? how long will it take the code to
execute? Its obviously not synched with the systems clock so how would
i know when it has completed. Can some one help me understand how
loops are implemented behind the scenes in VHDL?

Thank you.


dionysian83@gmail.com
  Reply With Quote
Old 09-03-2008, 12:06 AM   #2
kennheinrich@sympatico.ca
 
Posts: n/a
Default Re: VHDL Loops Execution
On Sep 2, 6:24*pm, dionysia...@gmail.com wrote:
> I am learning VHDL and one thing i still dont get is how loops are
> executed in the vhdl. For, example i have code that will write to a
> file for debugging perposes and it is implemented using a while loop:
> while word_write_count < 32 loop
>
> * * * * * * * * * * * * * * * * * * * * write ( trace_line,string'("Address: "));
> * * * * * * * * * * * * * * * * * * * * write ( trace_line,word_write_count);
> * * * * * * * * * * * * * * * * * * * * write ( trace_line,string'(" "));
> * * * * * * * * * * * * * * * * * * * * write
> ( trace_line,To_bitvector(frame_information(word_wri te_count)));
> * * * * * * * * * * * * * * * * * * * * writeline (load_file,trace_line);
>
> * * * * * * * * * * * * * * * * * * * * word_write_count := word_write_count + 1;
>
> * * * * * * * * * * * * * * * * end loop;
> But i still dont get in what sequence this code will execute. Will it
> execute top to bottom? If so will changes made in the above line be
> accessible to lines below it? how long will it take the code to
> execute? Its obviously not synched with the systems clock so how would
> i know when it has completed. Can some one help me understand how
> loops are implemented behind the scenes in VHDL?
>
> Thank you.


Your 'while' statement is what's called a sequential statement, and
the code appears to reference only variables and function calls.
Therefore, the code as you wrote it, can be read in pretty much the
same way you'd read the equivalent piece of code in C, Pascal, or any
other vanilla programming language. Either of the complementary
constructs (concurrent statements, or signals) leads you into the
world of time, clocks, events, synchronization, and process semantics.
But you're not there yet.

So yes, it will run from top to bottom, the effect of executing each
line will be visible to the next line, and it completes
instantaneously. That means zero time only as far as the simulated
circuit goes; of course it will use real CPU time It will be
completed when the loop condition becomes false and the line below the
loop starts to execute.

- Kenn


kennheinrich@sympatico.ca
  Reply With Quote
Old 09-03-2008, 08:53 AM   #3
Tricky
 
Posts: n/a
Default Re: VHDL Loops Execution
On 2 Sep, 23:24, dionysia...@gmail.com wrote:
> I am learning VHDL and one thing i still dont get is how loops are
> executed in the vhdl. For, example i have code that will write to a
> file for debugging perposes and it is implemented using a while loop:
> while word_write_count < 32 loop
>
> * * * * * * * * * * * * * * * * * * * * write ( trace_line,string'("Address: "));
> * * * * * * * * * * * * * * * * * * * * write ( trace_line,word_write_count);
> * * * * * * * * * * * * * * * * * * * * write ( trace_line,string'(" "));
> * * * * * * * * * * * * * * * * * * * * write
> ( trace_line,To_bitvector(frame_information(word_wri te_count)));
> * * * * * * * * * * * * * * * * * * * * writeline (load_file,trace_line);
>
> * * * * * * * * * * * * * * * * * * * * word_write_count := word_write_count + 1;
>
> * * * * * * * * * * * * * * * * end loop;
> But i still dont get in what sequence this code will execute. Will it
> execute top to bottom? If so will changes made in the above line be
> accessible to lines below it? how long will it take the code to
> execute? Its obviously not synched with the systems clock so how would
> i know when it has completed. Can some one help me understand how
> loops are implemented behind the scenes in VHDL?
>
> Thank you.


As you have no wait statements inside the loop, it will execute and
write 32 lines to a file, each line containing the same results as
each other as it will all take place in the single delta cycle. You
need wait statements inside the loop. What are you trying to capture?


Tricky
  Reply With Quote
Old 09-03-2008, 01:50 PM   #4
kennheinrich@sympatico.ca
 
Posts: n/a
Default Re: VHDL Loops Execution
On Sep 3, 3:53*am, Tricky <Trickyh...@gmail.com> wrote:
> As you have no wait statements inside the loop, it will execute and
> write 32 lines to a file, each line containing the same results as
> each other as it will all take place in the single delta cycle.


The OP used variable assignment (the ':=' ) which means that each line
will be *different*, because variable updates take effect immediately.
The outputs would only be the same if the thing being printed was a
*signal*.

Ask Modelsim about this:

use std.textio.all;
entity e is begin
end entity e;

architecture a of e is
begin
process
variable v :integer := 1;
variable oline : line;
begin
while v < 10 loop
write(oline, v);
writeline(output,oline);
v := v+1;
end loop;
wait; -- all done
end process;
end architecture a;

And it will tell you:

# Loading work.e(a)
run
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9

HTH,

- Kenn


kennheinrich@sympatico.ca
  Reply With Quote
Old 09-03-2008, 02:05 PM   #5
Andy
 
Posts: n/a
Default Re: VHDL Loops Execution
On Sep 3, 2:53*am, Tricky <Trickyh...@gmail.com> wrote:
>
> As you have no wait statements inside the loop, it will execute and
> write 32 lines to a file, each line containing the same results as
> each other as it will all take place in the single delta cycle. You
> need wait statements inside the loop. What are you trying to capture?


That is false. The loop should write a different element from the
array on each line. All lines will be written at the same simulation
time tick, but that is probably what was intended anyway. The variable
write_word_count updates immediately after it is assigned, and does
not need a wait statement or other process suspension to update like a
signal does.

That said, it is generally not recommended to control a while-loop
with an incrementing index. That's what for-loops are for. Using the
appropriate type of loop tells the reader/reviewer/maintainer of your
code right up front what your loop does. But your code should work
just fine. Did you remember to set word_count to zero before entering
the loop? Here again, a for-loop does that for you (initialize, test
and loop in one statement).

The answer to the original question is that yes, statements in
sequential loop statements (excluding generate-loops) execute in
order, just like any sequential statements anywhere in a process or
subprogram. What does not happen in order is signal updating. Signals
do not update until the process suspends, waiting for another clock or
input to change. They do not wait to update until the clock or input
changes, just until the process suspends to wait for the input(s).
Variables, however, update immediately upon execution of the
assignment statement.

Andy





Andy
  Reply With Quote
Old 09-03-2008, 04:21 PM   #6
Tricky
 
Posts: n/a
Default Re: VHDL Loops Execution
On 3 Sep, 14:05, Andy <jonesa...@comcast.net> wrote:
> On Sep 3, 2:53*am, Tricky <Trickyh...@gmail.com> wrote:
>
>
>
> > As you have no wait statements inside the loop, it will execute and
> > write 32 lines to a file, each line containing the same results as
> > each other as it will all take place in the single delta cycle. You
> > need wait statements inside the loop. What are you trying to capture?

>
> That is false. *The loop should write a different element from the
> array on each line. All lines will be written at the same simulation
> time tick, but that is probably what was intended anyway. The variable
> write_word_count updates immediately after it is assigned, and does
> not need a wait statement or other process suspension to update like a
> signal does.
>
> That said, it is generally not recommended to control a while-loop
> with an incrementing index. That's what for-loops are for. Using the
> appropriate type of loop tells the reader/reviewer/maintainer of your
> code right up front what your loop does. But your code should work
> just fine. Did you remember to set word_count to zero before entering
> the loop? Here again, a for-loop does that for you (initialize, test
> and loop in one statement).
>
> The answer to the original question is that yes, statements in
> sequential loop statements (excluding generate-loops) execute in
> order, just like any sequential statements anywhere in a process or
> subprogram. What does not happen in order is signal updating. Signals
> do not update until the process suspends, waiting for another clock or
> input to change. They do not wait to update until the clock or input
> changes, just until the process suspends to wait for the input(s).
> Variables, however, update immediately upon execution of the
> assignment statement.
>
> Andy


Yup. My bad.

Must pay more attention next time.


Tricky
  Reply With Quote
Old 09-03-2008, 05:12 PM   #7
mreister
Junior Member
 
Join Date: Aug 2008
Posts: 6
Default
Thank you all very much for your replies. Yes, i was intending the statement to run sequentially just like in C. However, what i dont get is how is it physically implemented on the FPGA? If it is not synched with the system clock how can the variables be implemented with a flip flop?

I was told that using the while loops like i did will in general not synthesis and that is ok because it is just debugging code.

HTML Code:
So yes, it will run from top to bottom, the effect of executing each line will be visible to the next line, and it completes instantaneously. That means zero time only as far as the simulated circuit goes; of course it will use real CPU time It will be completed when the loop condition becomes false and the line below the loop starts to execute

If it executes in CPU time i take it that the FPGA cannot synthesize the code i used. If i understand you correctly you are saying that the CPU simulating this code runs my code and not the FPGA. But what if i wanted to use varabiles in code that will synthesize? How would the variables used be updated instantly? Wont there be latches used instead of flip flops? Isn't this undesireable?


mreister
mreister is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
constants as of array of integers, for loops octavsly Hardware 0 04-25-2009 11:53 AM
Nested FOR loops in VHDL... yokeshr Hardware 0 12-16-2008 08:43 AM
enterprisedb package execution kanchuparthi.rams Software 0 05-22-2008 01:59 PM
CHRISTMAS SALE: ANY 24 70'S/80'S GRINDHOUSE DVDS $50.00U.S............ desiree cousteau DVD Video 0 11-22-2007 09:42 PM
Windows XP - Startup Loops ARGzPunk General Help Related Topics 1 11-08-2006 12:24 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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