vhdlsimulationtiming

Simulation Time in Concurrent VHDL Procedures


Simulating in EdaPlayground the following code, gives me the simulation results below the code


--CONCURRENT PROCEDURE CALL TIMING PROBLEM
ENTITY tb IS
END ENTITY tb;

ARCHITECTURE sim OF tb IS
  SIGNAL cnt  : integer RANGE 0 TO 3 := 0;
  SIGNAL str  : string(1 TO 5) := (OTHERS => ' ');
 
  PROCEDURE test (CONSTANT number  : IN integer RANGE 0 TO 3 := 0;
                  SIGNAL   num_str : OUT string(1 TO 5)) IS
  BEGIN
 
  
    CASE number IS
      WHEN 0      => num_str <= "zero "; REPORT "Zero";
      WHEN OTHERS => num_str <= "one  "; REPORT "One";
    END CASE;
  END PROCEDURE;
  
BEGIN
  test(cnt, str);  -- CONCURRENT CALL TO PROCEDURE TEST
  
 PROCESS 
 BEGIN
 
  
  FOR i IN 0 TO 3 LOOP
    WAIT FOR 10 ns;   --this timing is not OK. Second transaction is @20ns WHY not @10ns
     cnt <= i;
     --WAIT FOR 10 ns;  --this timing is OK
  END LOOP;
 WAIT;
 END PROCESS;
 
 ----Process
-- begin
 --wait until cnt'transaction;
 --report "*******************Transaction happen at report current time = " & time'image(now);
 --end process;
 
END ARCHITECTURE sim;

My question is, why simulation Time advances 0ns,20ns, 30ns, 40ns and not 0ns, 10ns, 20ns, 30ns ? If i move the 'WAIT FOR 10 ns;' after cnt <=i; simulation timing looks correct. Is it some sort of race condition?


Solution

  • The simulation algorithm consists of an initialisation phase, followed by a repeated simulation cycle. During initialisation cnt is driven with 0, and all processes will run until they suspend.

    So, what does that actually mean? First, your test procedure is sensitive to cnt, and so wakes up, and reports 'Zero', at time 0.

    Second, your process runs until the wait statement, and suspends. It's scheduled to wake up at 10ns. Initialisation is now complete, and the simulation cycle starts. At 10ns the process resumes, and assigns 0 to cnt; however, cnt is already 0, so nothing happens. The loop repeats, and it suspends at the wait, and is scheduled to resume at 20ns. At 20ns it resumes, and drives cnt with 1. The procedure is sensitive to this change, executes, and reports 'One' at time 20.