0
0
VHDLprogramming~20 mins

Component instantiation in testbench in VHDL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
VHDL Component Instantiation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple component instantiation in a testbench

Consider the following VHDL testbench code that instantiates a component. What will be the output on the signal out_signal after 10 ns?

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity tb is
end tb;

architecture behavior of tb is
  signal in_signal : std_logic := '0';
  signal out_signal : std_logic;

  component inverter is
    port(
      a : in std_logic;
      y : out std_logic
    );
  end component;

begin
  uut: inverter port map(a => in_signal, y => out_signal);

  process
  begin
    in_signal <= '0';
    wait for 5 ns;
    in_signal <= '1';
    wait for 5 ns;
    wait;
  end process;
end behavior;
Aout_signal = '1' at 10 ns
Bout_signal = '0' at 10 ns
Cout_signal toggles between '0' and '1' every 5 ns
Dout_signal remains undefined (U) at 10 ns
Attempts:
2 left
💡 Hint

Think about what an inverter does to the input signal.

Predict Output
intermediate
2:00remaining
Signal value after component instantiation with delayed input

Given the following testbench snippet, what is the value of out_signal at 15 ns?

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity tb is
end tb;

architecture behavior of tb is
  signal in_signal : std_logic := '0';
  signal out_signal : std_logic;

  component buffer is
    port(
      a : in std_logic;
      y : out std_logic
    );
  end component;

begin
  uut: buffer port map(a => in_signal, y => out_signal);

  process
  begin
    in_signal <= '0';
    wait for 10 ns;
    in_signal <= '1';
    wait for 10 ns;
    wait;
  end process;
end behavior;
Aout_signal = 'U' (undefined) at 15 ns
Bout_signal = '0' at 15 ns
Cout_signal = '1' at 15 ns
Dout_signal toggles every 5 ns
Attempts:
2 left
💡 Hint

Remember that signal assignments take effect after the delta cycle or delay.

🔧 Debug
advanced
2:00remaining
Identify the error in component instantiation

Examine the following testbench code snippet. What error will occur when compiling or simulating?

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity tb is
end tb;

architecture behavior of tb is
  signal in_signal : std_logic := '0';
  signal out_signal : std_logic;

  component and_gate is
    port(
      a : in std_logic;
      b : in std_logic;
      y : out std_logic
    );
  end component;

begin
  uut: and_gate port map(a => in_signal, y => out_signal);

  process
  begin
    in_signal <= '1';
    wait;
  end process;
end behavior;
ACompilation error: missing port 'b' in port map
BRuntime error: signal 'b' is undefined
CSimulation runs but output is always '0'
DNo error, simulation runs correctly
Attempts:
2 left
💡 Hint

Check if all ports of the component are connected in the port map.

📝 Syntax
advanced
2:00remaining
Syntax error in component instantiation

Which option contains a syntax error in the component instantiation within a testbench?

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity tb is
end tb;

architecture behavior of tb is
  signal in_signal : std_logic := '0';
  signal out_signal : std_logic;

  component not_gate is
    port(
      a : in std_logic;
      y : out std_logic
    );
  end component;

begin
  -- component instantiation here
end behavior;
Auut: not_gate port map(a => in_signal y => out_signal);
B;)langis_tuo >= y ,langis_ni >= a(pam trop etag_ton :tuu
Cuut: not_gate port map(a => in_signal, y => out_signal);
Dut: not_gate port map(a => in_signal, y => out_signal);
Attempts:
2 left
💡 Hint

Look carefully at the punctuation between port mappings.

🚀 Application
expert
2:00remaining
Number of component instances in a testbench

In the following testbench code, how many instances of the component flip_flop are created?

VHDL
library ieee;
use ieee.std_logic_1164.all;

entity tb is
end tb;

architecture behavior of tb is
  signal d, clk, q1, q2 : std_logic := '0';

  component flip_flop is
    port(
      d : in std_logic;
      clk : in std_logic;
      q : out std_logic
    );
  end component;

begin
  ff1: flip_flop port map(d => d, clk => clk, q => q1);
  ff2: flip_flop port map(d => q1, clk => clk, q => q2);
  ff3: flip_flop port map(d => q2, clk => clk, q => open);
end behavior;
A0
B2
C1
D3
Attempts:
2 left
💡 Hint

Count each unique label that instantiates the component.