Lets say we have two process statements in VHDL both reacting on the same clock edge.
Beside the clock we also have for example the reset signal. I know that only one process can modify the reset signal otherwise we get multiple drivers error.
Now lets assume one of the processes is modifying the signal and the other one is reading it. Which will evaluate first. Or in otherwords will the signal change be triggered in both processes and the code will work as expected ?
To clarify here is the VHDL code.
-- First process
process (clk, reset)
begin
if rising_edge(clk) and reset= '1' then
-- do work
end if;
end process;
-- Second process
process (clk)
begin
if rising_edge(clk) then
case reset is
when '1' => reset <= '0';
when '0' => reset <= '1';
end case;
end if;
end process;
The code is hypotetical and totaly irrelevant. But will the first process execute on every other clock or not.
Based on a test this will happen. But can I assume this will always happen or not.
Thanks in advance.
Best Answer
There are a number of nuances that come into play here.
Hence, your reset signal will update one delta cycle after clock. The "do work" portion of your process will see reset exactly one clock cycle after the clock cycle on which it was set. The VHDL simulation model is rock solid stable, so there will not be any uncertainty about how this particular process runs (like suggested by @MaximGi).
In a hardware design, you have put a flip-flop on reset and then fed that signal to other pieces of your design.
From a synthesis portability perspective, I caution you against putting any other logic in the same if condition as the clock. I would instead recommend re-writing your process as the following. Note your process is correct for simulation, it is just that some of the synthesis tools are fussy.
Also there is no need for reset on this sensitivity list since rising_edge(Clk) will only be true on the exact delta cycle in which clock changes. You only need reset on a sensitivity list when you use asynchronous reset.