3

I have just picked up The Designer's Guide to VHDL and I am working through the exercises in the first chapter. I ran into an issue with my 2 bit multiplexer that I don't understand.

The code for my multiplexer:

library ieee;
use ieee.std_logic_1164.all;

entity multi2 is
        port
        (
            a,b     : in bit;
            sel     : in boolean;
            z       : out bit   
        );
end multi2;

architecture behave of multi2 is

begin
    storage : process is
        variable stored_d0 : bit;
    begin
    wait for 1 ns;

    if sel then
        z <= a;
    else
        z <= b;
    end if;

    end process storage;
end architecture behave;

I can't figure out why I need the "wait for 1 ns;" line. If I move it to below the "end if" line the simulation won't work and I won't get my .vcd output from GHDL. Without the wait line, or it being in the wrong spot gives me an error in my vcd file about beginning and end time being the same.

Do I need wait statements in my process in order to work?

My test bench code is below:

    library ieee;
use ieee.std_logic_1164.all;

entity multi2_tb is
end multi2_tb;

architecture test of multi2_tb is
component multi2
    port
    (
        a,b     : in bit;
        sel     : in boolean;
        z       : out bit
    );
end component;

signal a,b       : bit;
signal sel       : boolean;
signal z         : bit;

begin
multiplexer2: multi2 port map (a => a, b => b, sel => sel, z => z);

process begin

    a <= '0';
    b <= '1';
    sel <= false;
    wait for 3 ns;

    a <= '0';
    b <= '1';
    sel <= true;
    wait for 3 ns;

    a <= '0';
    b <= '1';
    sel <= false;
    wait for 3 ns;


    assert false report "Reached end of test";
    wait;

    end process;
end test;
Paebbels
  • 15,573
  • 13
  • 70
  • 139
  • @user1155120 if he has no wait, he needs a sensitivity list, otherwise this process lets other processes starve. – Paebbels Nov 27 '18 at 20:06
  • If I remove the wait statement in my model ghdl will not successfully execute and I never get the "Reached end of test" output in the CMD window. – Greg McWilliams Nov 27 '18 at 20:13
  • The model is stuck repetitively executing the process. Processes suspend and resume in wait statements. A process with a sensitivity list has an implicit wait statement `wait on sensitivity_list;` as the last statement. Without that the process will continue with first statement.The VHDL standard doesn't require this condition be detected, it can be of limited specific use. As Patrick indicates you need a sensitivity list to get your process to suspend. The post is a Yes/No question which could be improved. –  Nov 27 '18 at 20:26
  • No you don't need an explicit wait statement in your process. Yes you need a wait statement. That can be supplied implicitly when providing a process sensitivity list. You could note that with the shown wait statement your process would execute every nano second regardless of events on signals being evaluated and your model would depend on a command line stop-time to finish simulation before reaching TIME'HIGH (GHDL has a 64 bit TIME). –  Nov 27 '18 at 20:29
  • Thanks. This helps a lot. Maybe I will look into other VHDL references. – Greg McWilliams Nov 27 '18 at 20:58
  • Stumbled across a new one - [A Tutorial Introduction to VHDL Programming](https://www.springer.com/us/book/9789811323089) by Orhan Gazi. Available 25 October 2018. A few of the author's personal biases show through but it's pretty extensive. –  Nov 30 '18 at 09:08

0 Answers0