I am working on a project using VHDL and I am facing a problem during one of my test benches. I testing all input combinations for a combinational component using a for loop in my stimulus process, but I have a case statement inside the foor loop which is not behaving the way I wish it to.
This is the code segment that isn't behaving the way I want it to:
for i in 0 to 20 loop
case opcode is
when "01001" | "01010" | "01100" | "01110" | "10000" =>
d <= '0';
wait for period;
d <= '1';
when "00010" | "00100" | "00101" | "00110" | "10001" | "10010" | "10011" =>
d <= '1';
when others =>
d <= '0';
end case;
wait for period;
opcode <= opcode + 1;
end loop;
As an example, I expect d
to become 1
when opcode
is 00010
. In the simulation, however, d
becomes 1
when opcode
becomes 00011
rather than 00010
(same for all other cases too), as if the value the case statement checks is decremented by 1. I changed opcode
inside the case statement to opcode+1
and it worked correctly. I do know that VHDL is a hardware description language and that its behavior differs from a programming language, but I still cannot wrap my head around why this is happening, and would like an explanation.
wait for period
trywait until rising_edge(clk)
instead. I suspect you have a delta race – Trickyopcode
is updated but still not sensed by stimulus process so the case statement checks for outdatedopcode
, and its only updated once I hit await for period
. I inserted await for 0 ns;
at the start of my for loop to trigger the new delta cycle manually and it worked! Thank you! – Omar Hurani