0
0
VHDLprogramming~20 mins

Signal vs variable vs constant in VHDL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
VHDL Signal-Variable-Constant Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this VHDL process?

Consider the following VHDL process. What will be the value of sig_out after the process executes?

VHDL
signal sig_out : integer := 0;
process
  variable var_temp : integer := 0;
begin
  var_temp := 5;
  sig_out <= var_temp;
  var_temp := 10;
  wait;
end process;
Asig_out = 5
Bsig_out = 10
Csig_out = 0
Dsig_out = undefined
Attempts:
2 left
💡 Hint

Remember that signals update after the process suspends, variables update immediately.

🧠 Conceptual
intermediate
1:30remaining
Which statement about constants in VHDL is true?

Choose the correct statement about constants in VHDL.

AConstants can be assigned new values inside a process.
BConstants can be used to store temporary values inside a process.
CConstants must be initialized at declaration and cannot change.
DConstants behave like signals and update after a delta cycle.
Attempts:
2 left
💡 Hint

Think about the meaning of the word 'constant'.

🔧 Debug
advanced
2:30remaining
Why does this VHDL code cause a simulation mismatch?

Given the following code snippet, why does the output signal not update as expected?

VHDL
signal clk : std_logic := '0';
signal out_sig : integer := 0;
process(clk)
  variable temp_var : integer := 0;
begin
  if rising_edge(clk) then
    temp_var := temp_var + 1;
    out_sig <= temp_var;
  end if;
end process;
AThe signal <code>clk</code> is not toggling, so the process never runs.
BSignal <code>out_sig</code> cannot be assigned inside a clocked process.
CVariable <code>temp_var</code> resets to 0 on every clock cycle, so <code>out_sig</code> never increments.
DThe process is missing a sensitivity list entry for <code>temp_var</code>.
Attempts:
2 left
💡 Hint

Is there code shown that toggles the clock signal?

📝 Syntax
advanced
2:00remaining
Which option correctly declares a constant and uses it in a process?

Identify the correct VHDL code snippet that declares a constant and uses it inside a process.

A
signal MAX_VAL : integer := 10;
process
begin
  if input &gt; MAX_VAL then
    output &lt;= '1';
  end if;
  wait;
end process;
B
constant MAX_VAL : integer;
process
begin
  MAX_VAL := 10;
  if input &gt; MAX_VAL then
    output &lt;= '1';
  end if;
  wait;
end process;
C
variable MAX_VAL : integer := 10;
process
begin
  if input &gt; MAX_VAL then
    output &lt;= '1';
  end if;
  wait;
end process;
D
constant MAX_VAL : integer := 10;
process
begin
  if input &gt; MAX_VAL then
    output &lt;= '1';
  end if;
  wait;
end process;
Attempts:
2 left
💡 Hint

Remember how constants are declared and assigned in VHDL.

🚀 Application
expert
2:30remaining
How many times does the variable update inside this VHDL process?

Given the following process, how many times will var_count increment during one simulation cycle?

VHDL
process
  variable var_count : integer := 0;
begin
  var_count := var_count + 1;
  var_count := var_count + 1;
  var_count := var_count + 1;
  wait;
end process;
ADepends on the number of wait statements
B3 times
C0 times
D1 time
Attempts:
2 left
💡 Hint

Variables update immediately within a process execution.