5) Sequential - Statement
5) Sequential - Statement
COEN313 - 2
1. VHDL Process
• Contains a set of sequential statements to be
executed sequentially
• The whole process is a concurrent statement
• Can be interpreted as a circuit part enclosed inside of
a black box
• May or may not be able to be mapped to physical
hardware
COEN313 - 3
• Two types of process
– A process with a sensitivity list
– A process with wait statement
COEN313 - 4
A process with a sensitivity list
• Syntax
process(sensitivity_list)
declarations;
begin
sequential statement;
sequential statement;
...
end process;
COEN313 - 5
• A process is like a circuit part, which can be
– active (known activated)
– inactive (known as suspended).
• A process is activated when a signal in the sensitivity
list changes its value
• Its statements will be executed sequentially until the
end of the process
COEN313 - 6
• E.g, 3-input and circuit
signal a,b,c,y: std_logic;
process(a,b,c)
begin
y <= a and b and c;
end process;
• How to interpret this:
process(a)
begin
y <= a and b and c;
end process;
• For a combinational circuit, all input should be
included in the sensitivity list
COEN313 - 7
A process with wait statement
COEN313 - 8
• E.g, 3-input and circuit
process
begin
y <= a and b and c;
wait on a, b, c;
end process;
COEN313 - 9
2. Sequential signal
assignment statement
• Syntax
signal_name <= value_expression;
• Syntax is identical to the simple
concurrent signal assignment
• Caution:
– Inside a process, a signal can be assigned
multiple times, but only the last assignment
takes effect
COEN313 - 10
• E.g.,
process(a,b,c,d)
begin -- yentry := y
y <= a or c; -- yexit := a or c;
y <= a and b; -- yexit := a and b;
y <= c and d; -- yexit := c and d;
end process; -- y <= yexit
• It is same as
process(a,b,c,d)
begin
y <= c and d;
end process;
• What happens if the 3 statements are
concurrent statements?
COEN313 - 11
Process
COEN313 - 12
Example 1
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY another_mux_def IS
PORT ( data_in1,data_in2 : IN STD_ULOGIC;
select_in : IN STD_LOGIC;
output : OUT STD_ULOGIC);
END ENTITY;
ARCHITECTURE beh OF another_mux_def IS
BEGIN
p0: PROCESS (data_in1, data_in2, select_in)
BEGIN
IF select_in = '0' THEN
output <= data_in1;
ELSE
output <= data_in2;
END IF;
COEN313 - 13
END PROCESS; END beh;
simulation
COEN313 - 14
Example 2
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
COEN313 - 15
COEN313 - 16
Execution inside a process
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY sig_ass IS END ENTITY;
COEN313 - 18
Signal assignment
COEN313 - 19
Another example!
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY and_or IS
PORT ( a,b,c,d : IN STD_LOGIC;
output : OUT STD_ULOGIC);
END ENTITY;
BEGIN
my_process : PROCESS (a,b,c,d)
BEGIN
x <= a OR b;
y <= c OR d;
output <= x AND y;
END PROCESS;
END beh;
COEN313 - 20
Simulation/Synthesis
• compile well!
• simulation shows a
problem!
• synthesis with a
warning concerning the
x,y signals! to a
correct circuit!
• post-level simulation
will show a mismatch
between the VHDL
code and the netlist
obtained from
synthesis!
COEN313 - 21
Why the simulation fails?
my_process : PROCESS (a,b,c,d)
BEGIN
x (new_value)<= a(event_value) OR b(old_value);
y (new_value)<= c(old_value) OR d(old_value);
output(new_value) <= x(old_value) AND y(old_value)
END PROCESS;
COEN313 - 22
COEN313 - 23
Why the simulation fails?
COEN313 - 24
Why the simulation fails?
COEN313 - 25
Why the simulation fails?
• compile well!
• simulation well!
• synthesis well!
• the resulting
hardware is the
same as for
and_or(beh).
COEN313 - 29
my_process : PROCESS (a,b,c,d)
BEGIN
x (new_value)<= a(event_value)OR b(old_value);
y (new_value)<= c(old_value) OR d(old_value);
END PROCESS;
output(new_value)<= x(new_value)AND y(new_value);
COEN313 - 32
3. Variable assignment
statement
• Syntax
variable_name := value_expression;
• Assignment takes effect immediately
• No time dimension (i.e., no delay)
• Behave like variables in C
• Difficult to map to hardware (depending
on context)
COEN313 - 33
• E.g.,
process(a,b,c)
variable tmp: std_logic;
begin
tmp := '0';
tmp := tmp or a;
tmp := tmp or b;
y <= tmp;
end process;
COEN313 - 34
• interpretation:
process(a,b,c)
variable tmp0, tmp1, tmp2: std_logic;
begin
tmp0 := '0';
tmp1 := tmp0 or a;
tmp2 := tmp1 or b;
y <= tmp2;
end process;
COEN313 - 35
• What happens if signal is used?
process(a,b,c,tmp)
begin -- tmpentry := tmp
tmp <= '0'; -- tmpexit := ‘0’;
tmp <= tmp or a; -- tmpexit := tmpentry or a;
tmp <= tmp or b; -- tmpexit := tmpentry or b;
end process; -- tmp <= tmpexit
• Same as:
process(a,b,c,tmp)
begin
tmp <= tmp or b;
end process;
COEN313 - 36
3. IF statement
• Syntax
• Examples
• Comparison to conditional signal assignment
• Incomplete branch and incomplete signal assignment
• Conceptual Implementation
COEN313 - 37
Syntax
if boolean_expr_1 then
sequential_statements;
elsif boolean_expr_2 then
sequential_statements;
elsif boolean_expr_3 then
sequential_statements;
...
else
sequential_statements;
end if;
COEN313 - 38
E.g., 4-to-1 mux
COEN313 - 39
E.g., 2-to-22 binary decoder
COEN313 - 40
E.g., 4-to-2 priority encoder
COEN313 - 41
Comparison to conditional
signal assignment
• Two statements are the same if there
is only one output signal in if statement
• If statement is more flexible
• Sequential statements can be used in
then, elsif and else branches:
– Multiple statements
– Nested if statements
COEN313 - 42
COEN313 - 43
e.g., find the max of a, b, c
COEN313 - 44
e.g., 2 conditional sig assignment codes
COEN313 - 45
• 2 conditional sig assign implementations
COEN313 - 46
e.g., “sharing” boolean condition
COEN313 - 47
COEN313 - 48
Incomplete branch and
incomplete signal
assignment
• According to VHDL definition:
– Only the “then” branch is required; “elsif”
and “else” branches are optional
– Signals do not need to be assigned in all
branch
– When a signal is unassigned due to
omission, it keeps the “previous
value” (implying “memory”)
COEN313 - 49
Incomplete branch
COEN313 - 50
• fix
COEN313 - 51
Incomplete signal assignment
• E.g.,
COEN313 - 52
• Fix #1: • Fix #2
COEN313 - 53
Conceptual implementation
COEN313 - 54
e.g.
COEN313 - 55
e.g.
COEN313 - 56
COEN313 - 57
4. Case statement
• Syntax
• Examples
• Comparison to selected signal assignment statement
• Incomplete signal assignment
• Conceptual Implementation
COEN313 - 58
Syntax
case case_expression is
when choice_1 =>
sequential statements;
when choice_2 =>
sequential statements;
...
when choice_n =>
sequential statements;
end case;
COEN313 - 59
E.g., 4-to-1 mux
COEN313 - 60
E.g., 2-to-22 binary decoder
COEN313 - 61
E.g., 4-to-2 priority encoder
COEN313 - 62
Comparison to selected
signal assignment
• Two statements are the same if there
is only one output signal in case
statement
• Case statement is more flexible
• Sequential statements can be used in
choice branches
COEN313 - 63
COEN313 - 64
Incomplete signal
assignment
• According to VHDL definition:
– Signals do not need to be assigned in all
choice branch
– When a signal is unassigned, it keeps the
“previous value” (implying “memory”)
COEN313 - 65
Incomplete signal assignment
• E.g.,
COEN313 - 66
• Fix #1:
COEN313 - 67
• Fix #2:
COEN313 - 68
Conceptual implementation
COEN313 - 69
e.g.
COEN313 - 70
COEN313 - 71
5. Simple for loop statement
• Syntax
• Examples
• Conceptual Implementation
COEN313 - 72
• VHDL provides a variety of loop constructs
• Only a restricted form of loop can be synthesized
• Syntax of simple for loop:
for index in loop_range loop
sequential statements;
end loop;
• loop_range must be static
• Index assumes value of loop_range from left to
right
COEN313 - 73
• E.g., bit-wide xor
COEN313 - 74
• E.g., reduced-xor
COEN313 - 75
Conceptual implementation
COEN313 - 76
• E.g., reduced-xor
COEN313 - 77
Synthesis of
sequential statements
• Concurrent statements
– Modeled after hardware
– Have clear, direct mapping to physical structures
• Sequential statements
– Intended to describe “behavior”
– Flexible and versatile
– Can be difficult to be realized in hardware
– Can be easily abused
COEN313 - 78
• Think hardware
• Designing hardware is
not converting a C
program to a VHDL
program
COEN313 - 79
Parity generator using a signal
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY parity_generator IS
PORT ( in1 : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
parity_out : OUT STD_LOGIC);
END parity_generator;
COEN313 - 80
Parity generator using a signal (Cont’D)
PROCESS (in1, parity_internal)
BEGIN
parity_internal <= '0';
parity_internal <= parity_internal XOR in1(3);
parity_internal <= parity_internal XOR in1(2);
parity_internal <= parity_internal XOR in1(1);
parity_internal <= parity_internal XOR in1(0);
END PROCESS;
COEN313 - 81
Parity generator using a signal (Cont’D)
• In general, if within a
combinational process, a
signal appears on both
sides of the signal
assignment operator,
combinational feedback
will be inferred
COEN313 - 82
Parity generator using a variable
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY parity_generator IS
PORT ( in1 : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
parity_out : OUT STD_LOGIC);
END parity_generator;
ARCHITECTURE rtl OF parity_generator IS
BEGIN
PROCESS (in1)
VARIABLE parity_internal : STD_LOGIC;
BEGIN
parity_internal := '0';
FOR index IN in1'RANGE LOOP
parity_internal := parity_internal XOR in1(index);
END LOOP;
parity_out <= parity_internal;
END PROCESS;
END rtl;
COEN313 - 83
Parity generator using a variable (Cont’D)
PROCESS (in1)
BEGIN
parity_internal := '0';
parity_internal := parity_internal XOR in1(3);
parity_internal := parity_internal XOR in1(2);
parity_internal := parity_internal XOR in1(1);
parity_internal := parity_internal XOR in1(0);
parity_out <= parity_internal;
END PROCESS;
in1(3:0) 0001 0011 0111 1111
parity_internal 1 0 1 0
parity_out 1 0 1 0
COEN313 - 84
Parity generator using a
variable (Cont’D)
COEN313 - 85