SamDawg
SamDawg

Reputation: 3

VHDL MUX Test Bench Issue

I'm trying to learn VHDL through P. Ashenden's book: Designer's Guide to VHDL. Chapter one's exercise 10 asks you to write 2-to-1 (I'm assuming 1 bit wide) MUX in VHDL and simulate it. I apologize in advance for being a complete noob. This is my first VHDL code.

My MUX didn't produce any errors or warnings in synthesis. My test bench doesn't produce errors or warnings, either. However, the simulation comes up completely blank, except for the names of the signals.

I've tried looking at a multitude of other MUX examples online (as well as a bench test example from the book), all of which gave errors when I tried sythesizing them, so I wasn't confident enough to use them as guides and didn't get much out of them. I'm not sure what I'm doing wrong here. I'd include an image of the simulation, but I don't have enough rep points :(

Also, I realize that a good MUX should also have cases for when it receives no select input/high impedance values, ect.. In this case, I'm just trying to get the toy model working.

The MUX code is:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity MUXtop is
    Port (a, b, sel: in bit;
         z: out bit);
end MUXtop;

architecture behav of MUXtop is
begin
    choose: process is
    begin
        if sel = '0' then
            z <= b;
        else
            z <= a;
        end if;
    end process choose;
end architecture behav;

The test bench code is:

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY MUXtest IS
END MUXtest;

ARCHITECTURE behavior OF MUXtest IS 

-- Component Declaration for the Unit Under Test (UUT)

    COMPONENT MUXtop
    PORT(
        a : IN  bit;
        b : IN  bit;
        sel : IN  bit;
        z : OUT  bit
        );
    END COMPONENT MUXtop;


   --Inputs
   signal a : bit := '0';
   signal b : bit := '0';
   signal sel : bit := '0';

   --Outputs
   signal z : bit;

BEGIN

-- Instantiate the Unit Under Test (UUT)
    uut: MUXtop PORT MAP (
           a => a,
           b => b,
           sel => sel,
           z => z
           );

   -- Stimulus process
   stimulus: process
   begin
       wait for 10 ns;
       a <= '1';
       wait for 10 ns;
       sel <= '1';
       wait for 10 ns;
       b <= '1';
       wait;
   end process stimulus;
END architecture behavior;

Upvotes: 0

Views: 7031

Answers (1)

user1155120
user1155120

Reputation:

You don't need a use clause for package std_logic_1164 when using type bit (declared in package standard).

Your process statement choose in MUXtop has no sensitivity clause which cause the process to continually execute in simulation. (It won't do anything until you trip over a delta cycle iteration limit which might be set to infinity).

I added a sensitivity list, commented out the superfluous use clauses in the two design units and added some more stimulus steps as well as a final wait for 10 ns; to allow the last action to be seen in your testbench:

library IEEE;
-- use IEEE.STD_LOGIC_1164.ALL;

entity MUXtop is
    Port (a, b, sel: in bit;
         z: out bit);
end MUXtop;

architecture behav of MUXtop is
begin
    choose: process (a, b, sel)  -- is
    begin
        if sel = '0' then
            z <= b;
        else
            z <= a;
        end if;
    end process choose;
end architecture behav;

LIBRARY ieee;
-- USE ieee.std_logic_1164.ALL;

ENTITY MUXtest IS
END MUXtest;

ARCHITECTURE behavior OF MUXtest IS 

-- Component Declaration for the Unit Under Test (UUT)

    COMPONENT MUXtop
    PORT(
        a : IN  bit;
        b : IN  bit;
        sel : IN  bit;
        z : OUT  bit
        );
    END COMPONENT MUXtop;


   --Inputs
   signal a : bit := '0';
   signal b : bit := '0';
   signal sel : bit := '0';

   --Outputs
   signal z : bit;

BEGIN

-- Instantiate the Unit Under Test (UUT)
    uut: MUXtop PORT MAP (
           a => a,
           b => b,
           sel => sel,
           z => z
           );

   -- Stimulus process
   stimulus: process
   begin
       wait for 10 ns;
       a <= '1';
       wait for 10 ns;
       sel <= '1';
       wait for 10 ns;
       sel <= '0';     -- added
       wait for 10 ns; -- added
       b <= '1';
       wait for 10 ns; -- added
       wait;
   end process stimulus;
END architecture behavior;

And that gives:

muxtest.png (clickable)

Upvotes: 1

Related Questions