VHDL: Time elapsed between two events

Joined
Oct 18, 2007
Messages
4
Reaction score
0
Hi there,

I am new on this forum and would like to get some assistance with a vhdl program I am writing.

I am using an Altera DE2 development and education board together with the Altera Quartus II v.7.1 software. I would like to determine the time elapsed between two events. Either my time determination isn't working or I just cannot output the value to anywhere. The two processes that should determine the time is below:

-- Process that determines whether the signal is back or not
count_clk_cycles: PROCESS (output_xcorr, load, EXT_CLOCK)
VARIABLE counter : INTEGER := 5;
VARIABLE str_counter : STRING(1 TO 6) := "000111";
BEGIN

IF (loaded = '1' AND xcorr = '0') THEN
counter := counter + 1;
END IF;

IF (loaded = '1' AND xcorr = '1') THEN
str_counter := fix(INTEGER'IMAGE(counter));
display(str_counter);
END IF;

END PROCESS;


-- Process that determines the state of the entire process.
set_state : PROCESS(load, loaded, output_xcorr, xcorr, EXT_CLOCK)
BEGIN
IF (load = '1') THEN
loaded <= '1';
END IF;

IF (output_xcorr = '1') THEN
xcorr <= '1';
END IF;

IF (loaded = '1' AND xcorr = '1') THEN
loaded <= '0';
xcorr <= '0';
END IF;
END PROCESS;

Let me describe the project a little. When the 'load' signal is high, a code is loaded into a shift register and sent out. The code is then received back and cross-correlated with the original to produce the output, 'output_xcorr'. I would like to determine the time from which the code is loaded until cross-correlation is successful.

The 'display' function displays the value of counter on a 7-segment display, but this isn't working. It only displays zero. When I however give counter a value like 'counter := 123', then it displays the correct value '123'.

I only need the time between the two events and output it from the board to anywhere, as long as I can get the value. I would really appreciate any assistance in this regard.

Best Regards.
 
Joined
Oct 23, 2007
Messages
5
Reaction score
0
Hi,
How you are trying to calculate the time in first process,i mean with respect to which clock reference?
 
Joined
Oct 23, 2007
Messages
5
Reaction score
0
VHDL : Time elapsed between two events

Hi,
With respect to which time reference (clock) you are incrementing the counter in first process?
 
Joined
Oct 18, 2007
Messages
4
Reaction score
0
Hi,

Will the counter not increment each time the process is executed??

Or should I include something like:
if (rising_edge(EXT_CLOCK))

Thank you for the interest.
 
Joined
Oct 23, 2007
Messages
5
Reaction score
0
Hi,
i think there should be clock reference to count time.
Also can u please explain aim of the 1st process, i'm bit confused that the signals (loaded,xcorr) which you are using in it are not in the sensitivity list or you want it to be sensitive to other signals (as you have mentioned in list)?
 
Joined
Oct 18, 2007
Messages
4
Reaction score
0
Hi,

I have changed the first process and it now looks like this:

-- Process that determines whether the signal is back or not
count_clk_cycles: PROCESS (xcorr, loaded, EXT_CLOCK)
VARIABLE counter : INTEGER := 5;
VARIABLE str_counter : STRING(1 TO 6) := "000111";
BEGIN
IF (RISING_EDGE(EXT_CLOCK)) THEN
IF (loaded = '1' AND xcorr = '0') THEN
counter := counter + 1;
END IF;

IF (loaded = '1' AND xcorr = '1') THEN
str_counter := fix(INTEGER'IMAGE(counter));
display(str_counter);
END IF;
END IF;
END PROCESS;

This however makes no difference.
This process should start counting when loaded goes high and then stop and display the value of counter when xcorr goes high. Counter will then be equivalent to the time between the events 'loaded from 0 to 1' and 'xcorr from 0 to 1'.

Thank you.
 
Joined
Oct 23, 2007
Messages
5
Reaction score
0
Hi,
i simulated the following code,insted of 'string display' i assigned one signal ='1'.
For reinitialising 'loaded' and 'xcorr' = 0 when time calculation is complete, u'll have to take another signal which will be set when display of string is done.



entity time_calc is
port(load : in std_logic;
output_xcorr : in std_logic;
clk : in std_logic;
display_string : out std_logic
);
end time_calc;

architecture Behavioral of time_calc is
signal loaded : std_logic;

signal xcorr : std_logic;
begin


count_clk_cycles: PROCESS (xcorr, loaded, clk)
VARIABLE counter : INTEGER := 5;
--VARIABLE str_counter : STRING(1 TO 6) := "000111";
BEGIN

IF (loaded = '1' AND xcorr = '0') THEN
counter := counter + 1;
END IF;

IF (loaded = '1' AND xcorr = '1') THEN
display_string <= '1';
--str_counter := fix(INTEGER'IMAGE(counter));
--display(str_counter);
END IF;

END PROCESS;

set_state : PROCESS(load,output_xcorr,loaded,xcorr)
BEGIN
IF (load = '1') THEN
loaded <= '1';
END IF;

IF (output_xcorr = '1') THEN
xcorr <= '1';
else
xcorr <= '0';
END IF;

-- IF (loaded = '1' AND xcorr = '1') THEN
-- loaded <= '0';
-- xcorr <= '0';
-- END IF;
END PROCESS;




end Behavioral;
 

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

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top