How to make a loop correctly?

I

Ilkka Pajari

Hello.

I'm quite noobie with VHDL and I'm trying to make a delay procedure.
Could someone tell me what's the most reasonable way to make at least
~13 clock cycles delay inside procedure. Maybe I'm thinking too much
about C, because none of my tries haven't been succeeded yet. Here is
one what I have tried so far:

(Procedure is inside clocked process)

procedure delay_s is begin
while (counter < 12) loop
..
..
counter <= counter + 1;
end loop;
counter <= '0';
end procedure delay_s;

What's wrong with procedure above, because loop is infinite?


- Ilkka Pajari
 
A

ALuPin

signal Clk : std_logic;
....
process
procedure delay_clk is
begin
for i in 0 to 12 loop
wait until rising_edge(Clk);
end loop;
end delay_clk;

begin

delay_clk;

wait;
end process;

What are you going to try ?

Rgds
André
 
M

Mike Treseler

Ilkka said:
(Procedure is inside clocked process)

procedure delay_s is begin
while (counter < 12) loop
..
..
counter <= counter + 1;
end loop;
counter <= '0';
end procedure delay_s;

What's wrong with procedure above, because loop is infinite?

The loop never exits because the
value of counter never changes
because signals only update at
the end of a process
(normally at the next rising edge clk)

You don't need a while loop.
Your base process loops automatically
every clock.
Have the procedure call check for
the terminal value. The calling
process does the waiting.

A while loop can't make a delay
because it runs in zero time.

-- Mike Treseler
 
I

Ilkka Pajari

Ok, thanks for the answers. I was trying to do a loop, because in one
architecture writing to the register lasts approximately 13 clock
cycles. During the writing trig-signals must be set high. The wait
statement inside procedure doesn't work, because wait-statements are not
allowed inside procedure.

Counter was type constant. Doesn't it update immediately? I have one
solution to my problem, but it's quite tricky. It's something like this:

SOME_PROCESS:
process(clk, rst)
begin
if clk'event and clk = '1' then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top