SlideShare a Scribd company logo
Sequential VHDL
Dr. Hakem Beitollahi
Computer Engineering Department
Elmo Sanat University
Outline
 Concurrent and Sequential Statements
 Process statement
 Wait statement
 Signals & variables in process
 Global variables (Shared)
 Postponed Process
 If statements
 Case statements
 Loop statements
 Clk generation
 Flip-Flops
 Synchron and Asynchron reset 2
3
Concurrent and Sequential Statements
 VHDL provides two different types of execution:
sequential and concurrent
 Different types of execution are useful for
modeling of real hardware
 Sequential statements view hardware from a
programmer approach
 Concurrent statements are order-independent
and asynchronous
4
Concurrent and Sequential Statements
 Concurrent type such as: when-else, with-select,
signals, and etc.
 Sequential type such as: if-then-else, case statement,
loop statements, variables, inside process and etc
 Both sequential and concurrent such as: signal
assignment, constants, function and procedure calls,
after delay, and etc.
 Important: codes inside process, function and
procedures are sequential.
 Important: codes inside architecture are concurrent
5
Process statement (I)
 The process in VHDL is the mechanism by which
sequential statements can be executed in the
correct sequence.
 Several processes execute concurrently
 Processes in an architecture are executed
concurrently with all other concurrent
statements.
 Execution is controlled either via sensitivity list
(contains trigger signals), or wait-statements
 The statements inside the process is executed
whenever one or more elements of the sensitive
list change value.
6
Process statement (II)
 Process statements are executed
concurrently but the statements inside a
process are executed sequentially.
 Every process is executed once upon
initialization
 A process statement has a declaration
section and a statement part.
 In the declaration section, types, variables,
constants, subprograms, and so on can be
declared.
 The statement part contains only sequential
statements.
Process Definition
7
VARIABLES are optional. If used, they must be declared in the declarative part
of the PROCESS
The initial value is not synthesizable, being only taken into consideration in
simulations.
The use of a label is also optional. Its purpose is to improve code readability
8
Process
JustToShow: process
Begin
Some statement 1;
Some statement 2;
Some statement 3;
Some statement 4;
wait<condition>;
end process JustToShow;
JustToShow: process
Begin
Some statement 1;
Some statement 2;
Some statement 3;
Some statement 4;
Some statement 5;
end process JustToShow;
9
Process
JustToShow: process ( )
Begin
Some statement 1;
Some statement 2;
Some statement 3;
Some statement 4;
end process JustToShow;
 VHDL provides a construct called sensitivity list of a
process
 The list specified next to the process keyword.
 The same as wait on sensitivity_list at the end of a process
JustToShow: process
Begin
Some statement 1;
Some statement 2;
Some statement 3;
Some statement 4;
wait on
end process JustToShow;
SomeSig
10
Process
JustToShow: process (signa1,signal2,signal3)
Begin
Some statement 1;
Some statement 2;
Some statement 3;
Some statement 4;
Some statement 5;
end process JustToShow;
Signal2 has changed
Signal3 has changed
Sensitive list
11
Process: an example
ARCHITECTURE archlist OF list IS
BEGIN
nand_test: PROCESS (a,b)
BEGIN
c <= NOT (a AND b);
END PROCESS nand_test;
END archlist;
a
b
c
the process ‘nand’ is
sensitive to signals ‘a’
and ‘b’ i.e., whenever
signal ‘a’ or ‘b’ changes
value, the statements
inside of the process will
be evaluated
12
Wait statement
 A process may be suspended upon execution of a wait statement in
the process. The process remains suspended until its reactivation
condition is met
 Three kind of reactivation condition can be specified in a wait
statement
 Conditions can be mixed. e.g
wait on A, B until Enable = 1;
 It is illegal to use wait statement in a process with a sensitivity list
timeout wait for time-expression; //simulation only
condition wait until condition; //Synthesizable
signal sensitivity wait on signal-list; //Synthesizable
Wait Until
 WAIT UNTIL signal_condition;
 The WAIT UNTIL statement accepts only one
signal
 More appropriate for synchronous code than
asynchronous
 WAIT UNTIL must be the first statement in the
PROCESS
 The PROCESS will be executed every time
the condition is met.
13
Wait Until (Example)
14
PROCESS -- no sensitivity list
BEGIN
WAIT UNTIL (clk'EVENT AND clk='1');
IF (rst='1') THEN
output <= "00000000";
ELSIF (clk'EVENT AND clk='1') THEN
output <= input;
END IF;
END PROCESS;
WAIT ON
 WAIT ON signal1 [, signal2, ... ];
 WAIT ON accepts multiple signals
 The PROCESS is put on hold until any of the
signals listed changes
15
PROCESS
BEGIN
WAIT ON clk, rst;
IF (rst='1') THEN
output <= "00000000";
ELSIF (clk'EVENT AND clk='1') THEN
output <= input;
END IF;
END PROCESS;
16
Wait: an Example
Or_process : process (In1,
In2)
begin
Output <= In1 or In2;
end process;
Or_process : process
begin
Output <= In1 or In2;
wait on In1, In2;
end process;
• Wait for type expression
• Wait until condition
• Wait on sensitivity list
• Complex wait
Wait for 10ns (simulation)
Wait until CLK=‘1’
Wait on Enable
Wait unit date after 10ns(simulation)
Variables vs. signals in process
 Variables and signals show a
fundamentally different behavior.
 In a process, the last signal assignment to
a signal is carried out when the process
execution is suspended.
 Value assignments to variables, however,
are carried out immediately.
17
Signals and Processes
 Goal: the difference between how a signal
assignment and variable assignment behave in
the process statement.
18
...
signal x,y,z : bit;
...
process (y)
begin
x<=y;
z<=not x;
end process;
If the signal y changes then an event will be
scheduled on x to make it the same as y.
An event is scheduled on z to make it the
opposite of x.
Question: will the value of z be the
opposite of y?
The answer is NO, because when the
second statement is executed, the event
on x has not been processed yet, and the
event scheduled on z will be the opposite
of the value of x
Variables and Processes
19
process (y)
variable x,z : bit;
begin
x:=y;
z:=not x;
end process;
The value of the variable z would be the
opposite of the value of y because the
value of the variable x is changed
immediately.
•Variables are only available within
processes:
• Name within process declarations
• Known only in this process Possible assignments:
Signal to variable
Variable to signal
Types have to match
Variables in process
20
architecture RTL of XYZ is
signal A, B, C : integer range 0 to 7;
signal Y, Z : integer range 0 to 15;
begin
process (A, B, C)
variable M, N : integer range 0 to 7;
begin
M := A;
N := B;
Z <= M + N;
M := C;
Y <= M + N;
end process;
end RTL;
Variables vs. signals in process
21
signal A,B,C:
integer;
signal Y, Z :
integer;
begin
process (A,B,C)
variable M, N:
integer;
begin
M := A;
N := B;
Z <= M + N;
M := C;
Y <= M + N;
end process;
signal A,B,C:
integer;
signal Y, Z : integer;
signal M, N :
integer;
begin
process
(A,B,C,M,N)
begin
M <= A;
N <= B;
Z <= M + N;
M <= C;
Y <= M + N;
end process;
Variables vs. signals in process (II)
 Signal values are assigned after the
process execution
 Only the last signal assignment is carried
out
 M ⇐ A; is overwritten by M ⇐ C;
 The 2nd adder input is connected to C
22
Global variables (Shared)
23
Global variables
 In VHDL 93, global variables are allowed.
 These variables are not only visible within a
process but within the entire architecture.
 The problem may occur, that two processes
assign a different value to a global variable at the
same time. It is not clear then, which of these
processes assigns the value to the variable last.
 This can lead to a non-deterministic behaviour!
 In synthesizable VHDL code global variables must
not be used.
24
Global variables (II)
25
architecture BEHAVE of SHARED is
shared variable S : integer;
begin
process (A, B)
begin
S := A + B;
end process;
process (A, B)
begin
S := A - B;
end process;
end BEHAVE;
• Accessible by all processes of an
architecture (shared variables)
• Can introduce non-determinism
Not to be used in synthesizable code
Postponed Process
26
Postponed Process (I)
27
Ex:Process (a, b, c)
Begin
. . . . . .
End Process;
 IF a, b, c Change in Zero-Time but with one d-Delay from one another 
 Multiple Process Activation (within d-Delay of Each other)
 The final Activation Signal Transactions will Dominate
 Unnecessary Execution of Processes result in Slower Operation
 Postponed Processes Activate Only After All Sensitivity List Signals
Stabilize.
Activates 3 Times
Once Per Sensitivity
List Signal Change
Postponed Process (II)
28
Ex: Postponed Process (a, b, c)
Begin
. . . . . .
End Process;
 Concurrent Statements, e.g. Signal Assignment, Are
Also Sensitive to Changes in Signals on Their Right
Hand Side  Postponed Keyword Can Be Used in
This Case As Well.
Example
Concurrent1: Postponed a <= b AND c OR d ;
Activates Only After
All Sensitivity List
Signals Stabilize (c
in this case).
If Statement
29
30
If Statement
 The general form is
if condition1 then
statement1
elsif condition2 then
statement2
else
statement3
end if;
If Example: Two-input NAND gate
31
LIBRARY IEEE;
USE
IEEE.std_logic_1164.ALL;
ENTITY mynand2 is
PORT( a, b : IN std_logic;
c : OUT std_logic);
END entity;
ARCHITECTURE mynand OF mynand2 IS
BEGIN
PROCESS( a, b )
VARIABLE temp : std_logic;
BEGIN
temp := NOT (a and b);
IF (temp = '1') THEN
c <= temp AFTER 6 ns;
ELSIF (temp = '0') THEN
c <= temp AFTER 5 ns;
ELSE
c <= temp AFTER 6 ns;
END IF;
END PROCESS;
END architecture;
Declares a VHDL package that provides the necessary
information with 9 state logic.
The architecture contains only one statement, a
concurrent process statement.
The process declaration section declares a
local variable named temp.
The process statement part has two
sequential statements in it
explicit sensitivity list
32
If: an Example
library ieee;
use ieee.std_logic_1164.all;
entity myand is
port(in1, in2: in std_logic;
out1: out std_logic);
end entity;
architecture myand of myand is
constant Delay: time:= 5 ns;
begin
And_process : process (in1, in2)
begin
if In1 = '0' or In2 = '0' then
Out1 <= '0' after Delay;
elsif In1 = 'X' or In2 = 'X' then
Out1 <= 'X' after Delay;
else
Out1 <= '1' after Delay;
end if;
end process;
end architecture;
The name of the architecture is the same name as the entity
name. This is legal
Logical or for checking a
condition. It is not a gate!
In an if statement, using
parenthesis is optional
33
If: an Example
process
begin
if (reset = ‘1’) then
A <= ‘0’ ;
elsif (clk’event and clk = ‘1’) then
A <= ‘B’;
end if;
wait on reset, clk;
end process;
process (clk,reset)
begin
if (reset = ‘1’) then
A <= ‘0’;
elsif (clk’event and clk = ‘1’) then
A <= ‘B’;
end if;
end process;
If: an Example
34
IF (x<y) THEN temp:="11111111";
ELSIF (x=y AND w='0') THEN
temp:="11110000";
ELSE temp:=(OTHERS =>'0');
End if;
One-digit Counter
35
LIBRARY ieee;
USE ieee.std_logic_1164.all;
---------------------------------------------
ENTITY counter IS
PORT (clk : IN STD_LOGIC;
digit : OUT INTEGER RANGE 0 TO 9);
END counter;
---------------------------------------------
ARCHITECTURE counter OF counter IS
BEGIN
count: PROCESS(clk)
VARIABLE temp : INTEGER RANGE 0 TO 10;
BEGIN
IF (clk'EVENT AND clk='1') THEN
temp := temp + 1;
IF (temp=10) THEN temp := 0;
END IF;
END IF;
digit <= temp;
END PROCESS count;
END counter;
Case Statements
36
37
Case statement
 Syntax
case expression is
when choice 1 =>
statement_A;
when choice 3 to 5 =>
statement_B;
when choice 8 downto 6 =>
statement_C;
when choice 9 | 13 | 17 =>
statement_D;
when others =>
statement_E;
end case;
38
Case statement: an Example
 MUX (41)
mycase_pro: process (s, c, d, e, f)
begin
case s is
when "00" =>
pout <= c;
when "01" =>
pout <= d;
when "10" =>
pout <= e;
when others =>
pout <= f;
end case;
end process mycase_pro;
C
D
E
F
S
POUT
Case statement
 CASE allows multiple assignments for
each test condition
39
WHEN value -- single value
WHEN value1 to value2 -- range, for enumerated data types only
WHEN value1 | value2 |... -- value1 or value2 or ...
40
Null
 Nothing to do
 It can be used by case statement
process (count)
begin
case count is
when 0 =>
dout <= “00”;
when 1 to 15 =>
dout <= “01”;
when 16 to 255 =>
dout <= “10”;
when others =>
null;
end case;
end process;
Loops
41
Loop (I)
 The LOOP statement is used whenever an
operation needs to be repeated.
 The LOOP statement has an optional
label, which can be used to identify the
LOOP statement.
 VHDL provides three kinds of Loop statements
 Simple loop
 for loop
 while loop
42
43
Simple Loop
 Simple loop
 Simple loop encloses a set of statements in a
structure which is set to loop forever
 The general form is
label1 : loop
statements
end loop label1;
44
Simple loop: Example
library ieee;
use ieee.std_logic_1164.all;
entity WhileTest is
port(A: in integer range 0 to 31;
Z: out std_logic_vector(3 downto 0));
end entity;
architecture test of WhileTest is
begin
process (A)
variable I : integer range 0 to 4;
begin
Z <= "0000";
I := 0;
L1: loop
exit L1 when I = 4;
if (A = I) then
Z(I) <= '1';
end if;
I := I + 1;
end loop;
end process;
Note VHDL allows maximum 10000 iterations.
45
For loop (I)
 The FOR loop loops as many times as specified in the
discrete_range, unless the loop is exited
 The general form
loop_label: -- optional
for loop_variable in range loop
statements
end loop loop_label;
 Example
For Loop Example
46
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity LoopTest is
port(A: in std_logic_vector(1 downto 0);
Z: out std_logic_vector(3 downto 0));
end entity;
architecture LoopTest of LoopTest
is
signal t: integer;
begin
t<= to_integer(unsigned(A));
process(A)
begin
Z<="0000";
for i in 0 to 3 loop
if i=t then
Z(i)<='1';
end if;
end loop;
end process;
end architecture;
Package for converting std_logic to integer
For loop (II)
 In some languages, the loop index (in this
example, i) can be assigned a value inside
the loop to change its value.
 VHDL does not allow any assignment to the
loop index.
 The index value i is locally declared by the
FOR statement.
 The variable i does not need to be declared
explicitly in the process, function, or procedure
 If another variable of the same name exists in
the process, then these two variables are
treated as separate variables
47
For loop (III)
48
PROCESS(i)
BEGIN
x <= i + 1; -- x is a signal
FOR i IN 1 to a/2 LOOP
q(i) := a; -- q is a variable
END LOOP;
END PROCESS;
 The index value i is not the same object as the signal i that was used to
calculate the new value for signal x.
 Inside the FOR loop, when a reference is made to i, the local index is
retrieved.
 But outside the FOR loop, when a reference is made to i, the value of the
signal i in the sensitivity list of the process is retrieved.
For loop (IV)
 The values used to specify the range in the
FOR loop need not be specific integer
values.
 The range can be any discrete range.
 See Examples
49
For loop (V)
50
PROCESS(clk)
TYPE day_of_week IS (sun, mon, tue, wed, thur, fri, sat);
BEGIN
FOR i IN day_of_week LOOP
IF i = sat THEN
son <= mow_lawn;
ELSIF i = sun THEN
church <= family;
ELSE
dad <= go_to_work;
END IF;
END LOOP;
END PROCESS;
 The range is specified by the type.
 Here, the compiler determines that the
leftmost value is sun, and the rightmost
value is sat.
 The range then is determined as from
sun to sat.
For loop (VI)
 If an ascending range is desired, use the
to clause. The downto clause can be
used to create a descending range.
 See Example
51
PROCESS(x, y)
BEGIN
FOR i IN x downto y LOOP
q(i) := w(i);
END LOOP;
END PROCESS;
While Loop
52
53
While loop (I)
 The WHILE condition LOOP statement loops as long as
the condition expression is TRUE.
 The general form:
loop_label:
while condition loop
statements
end loop loop_label;
 See Example
While loop (II)
54
library ieee;
use ieee.std_logic_1164.all;
entity WhileTest is
port(A: in integer range 0 to 3;
Z: out std_logic_vector(3 downto 0));
end entity;
architecture test of WhileTest is
begin
process (A)
variable I :
integer range 0 to 4;
begin
Z <= "0000";
I := 0;
while (I <= 3) loop
if (A = I) then
Z(I) <= '1';
end if;
I := I + 1;
end loop;
end process;
end architecture;
55
Exit and Next statement
 Exit statement is a sequential statement closely
associated with loops and causes the loop to be exited
for i in 0 to 7 loop
if ( i = 4 ) then
exit;
end if;
end loop;
 Next statement is used to advance control to the next iteration of the
loop
for i in 0 to 7 loop
if ( i = 4 ) then
next;
end if;
end loop;
56
Nested loop
process
begin
for i in 0 to 3 loop
for j in 0 to 3 loop
wait for 10 ns;
b <= b + 1;
end loop;
a <= a + 1;
end loop;
wait;
end process;
Clock Generation
57
58
CLK Generation
 The most popular clk generation
Process (clk)
Begin
if( clk’event and clk=‘1’) then
….
end if;
end process;
Process (clk)
Begin
if( clk=‘1’) then
….
end if;
end process;
Process (clk)
Begin
if( clk’event and clk=‘1’ and clk’last_value=‘0’) then
….
end if;
end process;
Process (clk)
Begin
wait until clk=‘1’;
….
end process;
Selection depends on
synthesis tools
59
D-Flip Flop
library IEEE;
use IEEE.std_logic_1164.all;
entity d_ff is
port (data, clk : in std_logic;
q : out std_logic);
end d_ff;
architecture behav of d_ff is
begin
process (clk) begin
if (clk'event and clk = '1') then
q <= data;
end if;
end process;
end behav;
60
D-Flip Flop with asynchron reset
library IEEE;
use IEEE.std_logic_1164.all;
entity d_ff is
port (data, clk,reset : in std_logic;
q : out std_logic);
end d_ff;
architecture behav of d_ff is
begin
process (clk, reset) begin
if reset=‘1’ then
q<=‘0’;
elsif (clk'event and clk = '1') then
q <= data;
end if;
end process;
end behav;
reset
61
D-Flip Flop with synchron reset
library IEEE;
use IEEE.std_logic_1164.all;
entity d_ff is
port (data, clk,reset : in std_logic;
q : out std_logic);
end d_ff;
architecture behav of d_ff is
begin
process (clk, reset) begin
if( clk’event and clk=‘1’) then
if reset=‘1’ then
q<=‘0’;
elsif
q <= data;
end if;
end if;
end process;
end behav;
reset
Using Sequential Code to Design
Combinational Circuits
62
Using Sequential Code to Design Combinational
Circuits
 Sequential code can be used to implement
either sequential or combinational circuits.
 To design a combinational circuit, the
following rules should be observed
 Rule 1: Make sure that all input signals used
(read) in the PROCESS appear in its
sensitivity list.
 Rule 2: Make sure that all combinations of the
input/output signals are included in the code;
63
Example
64
ENTITY example IS
PORT (a, b, c, d: IN STD_LOGIC;
sel: IN INTEGER RANGE 0 TO 3;
x, y: OUT STD_LOGIC);
END example;
ARCHITECTURE example OF example IS
BEGIN
PROCESS (a, b, c, d, sel)
BEGIN
IF (sel=0) THEN
x<=a;
y<='0';
ELSIF (sel=1) THEN
x<=b;
y<='1';
ELSIF (sel=2) THEN
x<=c;
ELSE
x<=d;
END IF;
END PROCESS;
END example;

More Related Content

PPT
Chapter 6 - Process Synchronization
PPTX
VHDL Behavioral Description
PPT
OS Process Synchronization, semaphore and Monitors
PPT
PDF
Os unit 3
PPT
Section06-Syncopkojiojoijnnjkhuubgfffppt
Chapter 6 - Process Synchronization
VHDL Behavioral Description
OS Process Synchronization, semaphore and Monitors
Os unit 3
Section06-Syncopkojiojoijnnjkhuubgfffppt

Similar to Lecture_6_Process.ppt (20)

PDF
CH05.pdf
PDF
OS Process synchronization Unit3 synchronization
PDF
Vhdl introduction
PPTX
Writing more complex models
PPT
Verilog Lecture3 hust 2014
PPTX
Behavioral modelling in VHDL
PPT
Operating System
PPT
Process synchronization(deepa)
PPT
Ch7 OS
 
PPT
Mca ii os u-2 process management & communication
PPTX
Seminar on Digital Multiplier(Booth Multiplier) Using VHDL
PDF
Practical file
PPT
Basic-VHDL-Constructs1.ppt, VHDL constructs are explained indetailed
PPT
Process Synchronization -1.ppt
PPTX
EXPLAINS ABOUT ALGORITHM and FLOWCHART.pptx
PPT
Process Synchronization
PDF
Yokogawa CX 2000 DAQ Station
PPTX
digital system design using verilog Module 5 ppt.pptx
CH05.pdf
OS Process synchronization Unit3 synchronization
Vhdl introduction
Writing more complex models
Verilog Lecture3 hust 2014
Behavioral modelling in VHDL
Operating System
Process synchronization(deepa)
Ch7 OS
 
Mca ii os u-2 process management & communication
Seminar on Digital Multiplier(Booth Multiplier) Using VHDL
Practical file
Basic-VHDL-Constructs1.ppt, VHDL constructs are explained indetailed
Process Synchronization -1.ppt
EXPLAINS ABOUT ALGORITHM and FLOWCHART.pptx
Process Synchronization
Yokogawa CX 2000 DAQ Station
digital system design using verilog Module 5 ppt.pptx
Ad

More from wafawafa52 (20)

PPTX
496479546-Drop-Counter- Tree(1).pptx
PPTX
421275892-3G-Retainability-SSP-Final-v1-0(1).pptx
PPT
360762795-If-Load-Sharing-in-Multi-carrier-Network.ppt
PPTX
CDC-F-solution-on-1830PSS-MAR2015-ED6-5B2-5D(2).pptx
PPTX
372988826-Cell-Dependency-in-Ericsson-scripting(2).pptx
PPT
rbs-6201-2g-commisioning1-151219095532.ppt
PPT
dugintegration-240811195422-dfdcf3a6.ppt
PPTX
685201759-LTE-KPIs- troubleshooting.pptx
PPTX
512606295-Ericsson-vs-Huawei-SIB-and-Parameter-Comparison1.pptx
PPTX
372988826-Cell-Dependency-in-Ericsson-scripting(1).pptx
PPTX
436934181-Coriant-MTera-Presentation(1).pptx
PPT
361300678-HW-Differences-Between-Apg40-Apg43.ppt
PPTX
384754914- LTE Timers .pptx
PPT
3900458 LTE Accessibilty case study.ppt
PPT
3374547 LTE Retainability .ppt
PPT
4759182 Availlabilty .ppt
PPTX
730003648-Baseband-G3-1-HW-Presentation-CBC-Copy(2).pptx
PPTX
501411220-Moshell-commands-and-read-through(2).pptx
PPT
EnodeB_Moshell_important_commands .ppt
PDF
Useful Moshell commands .pdf
496479546-Drop-Counter- Tree(1).pptx
421275892-3G-Retainability-SSP-Final-v1-0(1).pptx
360762795-If-Load-Sharing-in-Multi-carrier-Network.ppt
CDC-F-solution-on-1830PSS-MAR2015-ED6-5B2-5D(2).pptx
372988826-Cell-Dependency-in-Ericsson-scripting(2).pptx
rbs-6201-2g-commisioning1-151219095532.ppt
dugintegration-240811195422-dfdcf3a6.ppt
685201759-LTE-KPIs- troubleshooting.pptx
512606295-Ericsson-vs-Huawei-SIB-and-Parameter-Comparison1.pptx
372988826-Cell-Dependency-in-Ericsson-scripting(1).pptx
436934181-Coriant-MTera-Presentation(1).pptx
361300678-HW-Differences-Between-Apg40-Apg43.ppt
384754914- LTE Timers .pptx
3900458 LTE Accessibilty case study.ppt
3374547 LTE Retainability .ppt
4759182 Availlabilty .ppt
730003648-Baseband-G3-1-HW-Presentation-CBC-Copy(2).pptx
501411220-Moshell-commands-and-read-through(2).pptx
EnodeB_Moshell_important_commands .ppt
Useful Moshell commands .pdf
Ad

Recently uploaded (20)

PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
PPT on Performance Review to get promotions
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
web development for engineering and engineering
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Construction Project Organization Group 2.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
bas. eng. economics group 4 presentation 1.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT on Performance Review to get promotions
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
web development for engineering and engineering
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Geodesy 1.pptx...............................................
Construction Project Organization Group 2.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
CH1 Production IntroductoryConcepts.pptx
Sustainable Sites - Green Building Construction
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

Lecture_6_Process.ppt

  • 1. Sequential VHDL Dr. Hakem Beitollahi Computer Engineering Department Elmo Sanat University
  • 2. Outline  Concurrent and Sequential Statements  Process statement  Wait statement  Signals & variables in process  Global variables (Shared)  Postponed Process  If statements  Case statements  Loop statements  Clk generation  Flip-Flops  Synchron and Asynchron reset 2
  • 3. 3 Concurrent and Sequential Statements  VHDL provides two different types of execution: sequential and concurrent  Different types of execution are useful for modeling of real hardware  Sequential statements view hardware from a programmer approach  Concurrent statements are order-independent and asynchronous
  • 4. 4 Concurrent and Sequential Statements  Concurrent type such as: when-else, with-select, signals, and etc.  Sequential type such as: if-then-else, case statement, loop statements, variables, inside process and etc  Both sequential and concurrent such as: signal assignment, constants, function and procedure calls, after delay, and etc.  Important: codes inside process, function and procedures are sequential.  Important: codes inside architecture are concurrent
  • 5. 5 Process statement (I)  The process in VHDL is the mechanism by which sequential statements can be executed in the correct sequence.  Several processes execute concurrently  Processes in an architecture are executed concurrently with all other concurrent statements.  Execution is controlled either via sensitivity list (contains trigger signals), or wait-statements  The statements inside the process is executed whenever one or more elements of the sensitive list change value.
  • 6. 6 Process statement (II)  Process statements are executed concurrently but the statements inside a process are executed sequentially.  Every process is executed once upon initialization  A process statement has a declaration section and a statement part.  In the declaration section, types, variables, constants, subprograms, and so on can be declared.  The statement part contains only sequential statements.
  • 7. Process Definition 7 VARIABLES are optional. If used, they must be declared in the declarative part of the PROCESS The initial value is not synthesizable, being only taken into consideration in simulations. The use of a label is also optional. Its purpose is to improve code readability
  • 8. 8 Process JustToShow: process Begin Some statement 1; Some statement 2; Some statement 3; Some statement 4; wait<condition>; end process JustToShow; JustToShow: process Begin Some statement 1; Some statement 2; Some statement 3; Some statement 4; Some statement 5; end process JustToShow;
  • 9. 9 Process JustToShow: process ( ) Begin Some statement 1; Some statement 2; Some statement 3; Some statement 4; end process JustToShow;  VHDL provides a construct called sensitivity list of a process  The list specified next to the process keyword.  The same as wait on sensitivity_list at the end of a process JustToShow: process Begin Some statement 1; Some statement 2; Some statement 3; Some statement 4; wait on end process JustToShow; SomeSig
  • 10. 10 Process JustToShow: process (signa1,signal2,signal3) Begin Some statement 1; Some statement 2; Some statement 3; Some statement 4; Some statement 5; end process JustToShow; Signal2 has changed Signal3 has changed Sensitive list
  • 11. 11 Process: an example ARCHITECTURE archlist OF list IS BEGIN nand_test: PROCESS (a,b) BEGIN c <= NOT (a AND b); END PROCESS nand_test; END archlist; a b c the process ‘nand’ is sensitive to signals ‘a’ and ‘b’ i.e., whenever signal ‘a’ or ‘b’ changes value, the statements inside of the process will be evaluated
  • 12. 12 Wait statement  A process may be suspended upon execution of a wait statement in the process. The process remains suspended until its reactivation condition is met  Three kind of reactivation condition can be specified in a wait statement  Conditions can be mixed. e.g wait on A, B until Enable = 1;  It is illegal to use wait statement in a process with a sensitivity list timeout wait for time-expression; //simulation only condition wait until condition; //Synthesizable signal sensitivity wait on signal-list; //Synthesizable
  • 13. Wait Until  WAIT UNTIL signal_condition;  The WAIT UNTIL statement accepts only one signal  More appropriate for synchronous code than asynchronous  WAIT UNTIL must be the first statement in the PROCESS  The PROCESS will be executed every time the condition is met. 13
  • 14. Wait Until (Example) 14 PROCESS -- no sensitivity list BEGIN WAIT UNTIL (clk'EVENT AND clk='1'); IF (rst='1') THEN output <= "00000000"; ELSIF (clk'EVENT AND clk='1') THEN output <= input; END IF; END PROCESS;
  • 15. WAIT ON  WAIT ON signal1 [, signal2, ... ];  WAIT ON accepts multiple signals  The PROCESS is put on hold until any of the signals listed changes 15 PROCESS BEGIN WAIT ON clk, rst; IF (rst='1') THEN output <= "00000000"; ELSIF (clk'EVENT AND clk='1') THEN output <= input; END IF; END PROCESS;
  • 16. 16 Wait: an Example Or_process : process (In1, In2) begin Output <= In1 or In2; end process; Or_process : process begin Output <= In1 or In2; wait on In1, In2; end process; • Wait for type expression • Wait until condition • Wait on sensitivity list • Complex wait Wait for 10ns (simulation) Wait until CLK=‘1’ Wait on Enable Wait unit date after 10ns(simulation)
  • 17. Variables vs. signals in process  Variables and signals show a fundamentally different behavior.  In a process, the last signal assignment to a signal is carried out when the process execution is suspended.  Value assignments to variables, however, are carried out immediately. 17
  • 18. Signals and Processes  Goal: the difference between how a signal assignment and variable assignment behave in the process statement. 18 ... signal x,y,z : bit; ... process (y) begin x<=y; z<=not x; end process; If the signal y changes then an event will be scheduled on x to make it the same as y. An event is scheduled on z to make it the opposite of x. Question: will the value of z be the opposite of y? The answer is NO, because when the second statement is executed, the event on x has not been processed yet, and the event scheduled on z will be the opposite of the value of x
  • 19. Variables and Processes 19 process (y) variable x,z : bit; begin x:=y; z:=not x; end process; The value of the variable z would be the opposite of the value of y because the value of the variable x is changed immediately. •Variables are only available within processes: • Name within process declarations • Known only in this process Possible assignments: Signal to variable Variable to signal Types have to match
  • 20. Variables in process 20 architecture RTL of XYZ is signal A, B, C : integer range 0 to 7; signal Y, Z : integer range 0 to 15; begin process (A, B, C) variable M, N : integer range 0 to 7; begin M := A; N := B; Z <= M + N; M := C; Y <= M + N; end process; end RTL;
  • 21. Variables vs. signals in process 21 signal A,B,C: integer; signal Y, Z : integer; begin process (A,B,C) variable M, N: integer; begin M := A; N := B; Z <= M + N; M := C; Y <= M + N; end process; signal A,B,C: integer; signal Y, Z : integer; signal M, N : integer; begin process (A,B,C,M,N) begin M <= A; N <= B; Z <= M + N; M <= C; Y <= M + N; end process;
  • 22. Variables vs. signals in process (II)  Signal values are assigned after the process execution  Only the last signal assignment is carried out  M ⇐ A; is overwritten by M ⇐ C;  The 2nd adder input is connected to C 22
  • 24. Global variables  In VHDL 93, global variables are allowed.  These variables are not only visible within a process but within the entire architecture.  The problem may occur, that two processes assign a different value to a global variable at the same time. It is not clear then, which of these processes assigns the value to the variable last.  This can lead to a non-deterministic behaviour!  In synthesizable VHDL code global variables must not be used. 24
  • 25. Global variables (II) 25 architecture BEHAVE of SHARED is shared variable S : integer; begin process (A, B) begin S := A + B; end process; process (A, B) begin S := A - B; end process; end BEHAVE; • Accessible by all processes of an architecture (shared variables) • Can introduce non-determinism Not to be used in synthesizable code
  • 27. Postponed Process (I) 27 Ex:Process (a, b, c) Begin . . . . . . End Process;  IF a, b, c Change in Zero-Time but with one d-Delay from one another   Multiple Process Activation (within d-Delay of Each other)  The final Activation Signal Transactions will Dominate  Unnecessary Execution of Processes result in Slower Operation  Postponed Processes Activate Only After All Sensitivity List Signals Stabilize. Activates 3 Times Once Per Sensitivity List Signal Change
  • 28. Postponed Process (II) 28 Ex: Postponed Process (a, b, c) Begin . . . . . . End Process;  Concurrent Statements, e.g. Signal Assignment, Are Also Sensitive to Changes in Signals on Their Right Hand Side  Postponed Keyword Can Be Used in This Case As Well. Example Concurrent1: Postponed a <= b AND c OR d ; Activates Only After All Sensitivity List Signals Stabilize (c in this case).
  • 30. 30 If Statement  The general form is if condition1 then statement1 elsif condition2 then statement2 else statement3 end if;
  • 31. If Example: Two-input NAND gate 31 LIBRARY IEEE; USE IEEE.std_logic_1164.ALL; ENTITY mynand2 is PORT( a, b : IN std_logic; c : OUT std_logic); END entity; ARCHITECTURE mynand OF mynand2 IS BEGIN PROCESS( a, b ) VARIABLE temp : std_logic; BEGIN temp := NOT (a and b); IF (temp = '1') THEN c <= temp AFTER 6 ns; ELSIF (temp = '0') THEN c <= temp AFTER 5 ns; ELSE c <= temp AFTER 6 ns; END IF; END PROCESS; END architecture; Declares a VHDL package that provides the necessary information with 9 state logic. The architecture contains only one statement, a concurrent process statement. The process declaration section declares a local variable named temp. The process statement part has two sequential statements in it explicit sensitivity list
  • 32. 32 If: an Example library ieee; use ieee.std_logic_1164.all; entity myand is port(in1, in2: in std_logic; out1: out std_logic); end entity; architecture myand of myand is constant Delay: time:= 5 ns; begin And_process : process (in1, in2) begin if In1 = '0' or In2 = '0' then Out1 <= '0' after Delay; elsif In1 = 'X' or In2 = 'X' then Out1 <= 'X' after Delay; else Out1 <= '1' after Delay; end if; end process; end architecture; The name of the architecture is the same name as the entity name. This is legal Logical or for checking a condition. It is not a gate! In an if statement, using parenthesis is optional
  • 33. 33 If: an Example process begin if (reset = ‘1’) then A <= ‘0’ ; elsif (clk’event and clk = ‘1’) then A <= ‘B’; end if; wait on reset, clk; end process; process (clk,reset) begin if (reset = ‘1’) then A <= ‘0’; elsif (clk’event and clk = ‘1’) then A <= ‘B’; end if; end process;
  • 34. If: an Example 34 IF (x<y) THEN temp:="11111111"; ELSIF (x=y AND w='0') THEN temp:="11110000"; ELSE temp:=(OTHERS =>'0'); End if;
  • 35. One-digit Counter 35 LIBRARY ieee; USE ieee.std_logic_1164.all; --------------------------------------------- ENTITY counter IS PORT (clk : IN STD_LOGIC; digit : OUT INTEGER RANGE 0 TO 9); END counter; --------------------------------------------- ARCHITECTURE counter OF counter IS BEGIN count: PROCESS(clk) VARIABLE temp : INTEGER RANGE 0 TO 10; BEGIN IF (clk'EVENT AND clk='1') THEN temp := temp + 1; IF (temp=10) THEN temp := 0; END IF; END IF; digit <= temp; END PROCESS count; END counter;
  • 37. 37 Case statement  Syntax case expression is when choice 1 => statement_A; when choice 3 to 5 => statement_B; when choice 8 downto 6 => statement_C; when choice 9 | 13 | 17 => statement_D; when others => statement_E; end case;
  • 38. 38 Case statement: an Example  MUX (41) mycase_pro: process (s, c, d, e, f) begin case s is when "00" => pout <= c; when "01" => pout <= d; when "10" => pout <= e; when others => pout <= f; end case; end process mycase_pro; C D E F S POUT
  • 39. Case statement  CASE allows multiple assignments for each test condition 39 WHEN value -- single value WHEN value1 to value2 -- range, for enumerated data types only WHEN value1 | value2 |... -- value1 or value2 or ...
  • 40. 40 Null  Nothing to do  It can be used by case statement process (count) begin case count is when 0 => dout <= “00”; when 1 to 15 => dout <= “01”; when 16 to 255 => dout <= “10”; when others => null; end case; end process;
  • 42. Loop (I)  The LOOP statement is used whenever an operation needs to be repeated.  The LOOP statement has an optional label, which can be used to identify the LOOP statement.  VHDL provides three kinds of Loop statements  Simple loop  for loop  while loop 42
  • 43. 43 Simple Loop  Simple loop  Simple loop encloses a set of statements in a structure which is set to loop forever  The general form is label1 : loop statements end loop label1;
  • 44. 44 Simple loop: Example library ieee; use ieee.std_logic_1164.all; entity WhileTest is port(A: in integer range 0 to 31; Z: out std_logic_vector(3 downto 0)); end entity; architecture test of WhileTest is begin process (A) variable I : integer range 0 to 4; begin Z <= "0000"; I := 0; L1: loop exit L1 when I = 4; if (A = I) then Z(I) <= '1'; end if; I := I + 1; end loop; end process; Note VHDL allows maximum 10000 iterations.
  • 45. 45 For loop (I)  The FOR loop loops as many times as specified in the discrete_range, unless the loop is exited  The general form loop_label: -- optional for loop_variable in range loop statements end loop loop_label;  Example
  • 46. For Loop Example 46 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity LoopTest is port(A: in std_logic_vector(1 downto 0); Z: out std_logic_vector(3 downto 0)); end entity; architecture LoopTest of LoopTest is signal t: integer; begin t<= to_integer(unsigned(A)); process(A) begin Z<="0000"; for i in 0 to 3 loop if i=t then Z(i)<='1'; end if; end loop; end process; end architecture; Package for converting std_logic to integer
  • 47. For loop (II)  In some languages, the loop index (in this example, i) can be assigned a value inside the loop to change its value.  VHDL does not allow any assignment to the loop index.  The index value i is locally declared by the FOR statement.  The variable i does not need to be declared explicitly in the process, function, or procedure  If another variable of the same name exists in the process, then these two variables are treated as separate variables 47
  • 48. For loop (III) 48 PROCESS(i) BEGIN x <= i + 1; -- x is a signal FOR i IN 1 to a/2 LOOP q(i) := a; -- q is a variable END LOOP; END PROCESS;  The index value i is not the same object as the signal i that was used to calculate the new value for signal x.  Inside the FOR loop, when a reference is made to i, the local index is retrieved.  But outside the FOR loop, when a reference is made to i, the value of the signal i in the sensitivity list of the process is retrieved.
  • 49. For loop (IV)  The values used to specify the range in the FOR loop need not be specific integer values.  The range can be any discrete range.  See Examples 49
  • 50. For loop (V) 50 PROCESS(clk) TYPE day_of_week IS (sun, mon, tue, wed, thur, fri, sat); BEGIN FOR i IN day_of_week LOOP IF i = sat THEN son <= mow_lawn; ELSIF i = sun THEN church <= family; ELSE dad <= go_to_work; END IF; END LOOP; END PROCESS;  The range is specified by the type.  Here, the compiler determines that the leftmost value is sun, and the rightmost value is sat.  The range then is determined as from sun to sat.
  • 51. For loop (VI)  If an ascending range is desired, use the to clause. The downto clause can be used to create a descending range.  See Example 51 PROCESS(x, y) BEGIN FOR i IN x downto y LOOP q(i) := w(i); END LOOP; END PROCESS;
  • 53. 53 While loop (I)  The WHILE condition LOOP statement loops as long as the condition expression is TRUE.  The general form: loop_label: while condition loop statements end loop loop_label;  See Example
  • 54. While loop (II) 54 library ieee; use ieee.std_logic_1164.all; entity WhileTest is port(A: in integer range 0 to 3; Z: out std_logic_vector(3 downto 0)); end entity; architecture test of WhileTest is begin process (A) variable I : integer range 0 to 4; begin Z <= "0000"; I := 0; while (I <= 3) loop if (A = I) then Z(I) <= '1'; end if; I := I + 1; end loop; end process; end architecture;
  • 55. 55 Exit and Next statement  Exit statement is a sequential statement closely associated with loops and causes the loop to be exited for i in 0 to 7 loop if ( i = 4 ) then exit; end if; end loop;  Next statement is used to advance control to the next iteration of the loop for i in 0 to 7 loop if ( i = 4 ) then next; end if; end loop;
  • 56. 56 Nested loop process begin for i in 0 to 3 loop for j in 0 to 3 loop wait for 10 ns; b <= b + 1; end loop; a <= a + 1; end loop; wait; end process;
  • 58. 58 CLK Generation  The most popular clk generation Process (clk) Begin if( clk’event and clk=‘1’) then …. end if; end process; Process (clk) Begin if( clk=‘1’) then …. end if; end process; Process (clk) Begin if( clk’event and clk=‘1’ and clk’last_value=‘0’) then …. end if; end process; Process (clk) Begin wait until clk=‘1’; …. end process; Selection depends on synthesis tools
  • 59. 59 D-Flip Flop library IEEE; use IEEE.std_logic_1164.all; entity d_ff is port (data, clk : in std_logic; q : out std_logic); end d_ff; architecture behav of d_ff is begin process (clk) begin if (clk'event and clk = '1') then q <= data; end if; end process; end behav;
  • 60. 60 D-Flip Flop with asynchron reset library IEEE; use IEEE.std_logic_1164.all; entity d_ff is port (data, clk,reset : in std_logic; q : out std_logic); end d_ff; architecture behav of d_ff is begin process (clk, reset) begin if reset=‘1’ then q<=‘0’; elsif (clk'event and clk = '1') then q <= data; end if; end process; end behav; reset
  • 61. 61 D-Flip Flop with synchron reset library IEEE; use IEEE.std_logic_1164.all; entity d_ff is port (data, clk,reset : in std_logic; q : out std_logic); end d_ff; architecture behav of d_ff is begin process (clk, reset) begin if( clk’event and clk=‘1’) then if reset=‘1’ then q<=‘0’; elsif q <= data; end if; end if; end process; end behav; reset
  • 62. Using Sequential Code to Design Combinational Circuits 62
  • 63. Using Sequential Code to Design Combinational Circuits  Sequential code can be used to implement either sequential or combinational circuits.  To design a combinational circuit, the following rules should be observed  Rule 1: Make sure that all input signals used (read) in the PROCESS appear in its sensitivity list.  Rule 2: Make sure that all combinations of the input/output signals are included in the code; 63
  • 64. Example 64 ENTITY example IS PORT (a, b, c, d: IN STD_LOGIC; sel: IN INTEGER RANGE 0 TO 3; x, y: OUT STD_LOGIC); END example; ARCHITECTURE example OF example IS BEGIN PROCESS (a, b, c, d, sel) BEGIN IF (sel=0) THEN x<=a; y<='0'; ELSIF (sel=1) THEN x<=b; y<='1'; ELSIF (sel=2) THEN x<=c; ELSE x<=d; END IF; END PROCESS; END example;

Editor's Notes

  • #2: 20 January 2023