Search code examples
variablessignalsvhdl

Why won't a signal be updated instantly in process statement? VHDL


In VHDL, you need to use a variable in a process statement for it to be updated instantaneously. The use of a signal can be done, but it won't be updated immediately. Repeating my question from above: Why won't a signal be updated instantly in process statement?


Solution

  • The short answer is the VHDL execution model. The VHDL execution model does a simulation cycle in two separate steps: Update and then Execution. A limited perspective (there are many details that I have abstracted away) of the a simulation cycle is:

    • During the update phase all signals that will be updated during a simulation cycle are.
    • When signals are updated and change, processes that are sensitive to a signal changing are marked for execution.
    • Execute statements and processes that were marked for execution until they encounter either a wait statement or loop back to the process sensitivity list (and the process has one).

    Your question is why do this? It guarantees that every compliant VHDL simulator executes the same code with exactly the same number of simulation cycles and produces the exact same result.

    To understand why it would be problematic if signals updated instantaneously, consider the following code:

    proc1 : process(Clk)
    begin
      if rising_edge(Clk) then
        Reg1 <= A ;
      end if ; 
    end process ; 
    
    proc2 : process(Clk)
    begin
      if rising_edge(Clk) then
        Reg2 <= Reg1 ; 
      end if ; 
    end process ; 
    

    In the above code, if signals updated instantaneously like variables, and the processes ran in the order proc1 then proc2, then in the simulator we would see 1 flip-flop for A to be received by Reg2. OTOH, if the processes ran in the order proc2 then proc1, then in the simulator we would see 2 flip-flops for A to be received by Reg2.

    This is also why shared variables of an ordinary type in VHDL were only introduced temporarily in 1993 and removed in 2000 when a more appropriate feature was able to be introduced (shared variables of a protected type).