-Combinational Circuits
Lecture 4
Amit Degada
Asst Prof, EC
IT-NU
Amit.degada@nirmauni.ac.in
Presentation Outline
Why HDLs
Feature of HDL
HDL Implementation Design
Cycle
Advantage of HDL
A Brief History of VHDL
Writing Code
Other HDLs
Verilog
Paracore http://www.dilloneng.com/paracore.shtml
Ruby HDL
http://www.aracnet.com/~ptkwt/ruby_stuff/RHDL/index.shtml
My HD
JHDL http://www.jhdl.org/
Lava http://www.xilinx.com/labs/lava/
HDL maker http://www.polybus.com/hdlmaker/users_guide/
System C
AHDL http://www.polybus.com/hdlmaker/users_guide/
Sequential Language
Statements execute one at a time in a
sequential manner
Why HDLs?
In software everything is sequential
Sequence of statements is significant, since they
are executed in that order
In hardware events are concurrent, so a software
language cannot be used for describing and
simulating hardware.
Example
C = (not (X) and Y) or (not (X))
Case 1
A = not X
B = A and Y
C = A or B
Result:
C=1
Case 2
B = A and Y
C = A or B
A = not X
Result:
C=0
Case 3
C = A or B
A = not X
B = A and Y
Result:
C=0
Technology Independence
The design of VHDL components can be technologyindependent or more-or-less technology independent for a
technical family
The components can be stored in a library for reuse in several
different designs
VHDL models of commercial IC standard components can now
be bought, which is a great advantage when it comes to verifying
entire circuit boards
Design Level
Design Reuse
All this results in low risk, high convergence, fast time to market,
more money.
What is VHDL?
VHDL Stands for
About VHDL
VHDL is not case sensitive
VHDL is a free form language. You can write the
whole program on a single line.
-- This is a VHDL comment
entity my_exor is -- one more comment
Port(
...);
end my_exor;
Entity Syntax
entity <name> is
[generic(
<gen_name> : <type*>[:=<init>];
.
.
. )]
port (
<port_name> : <dir**> <type>;
.
.
. );
end <name>;
* <type> is any VHDL type
** <dir> is a direction of the port:
IN, OUT, or INOUT
my EXOR gate
-- This is my first VHDL program
library IEEE;
use IEEE.std_logic_1164.all;
entity my_exor is
port (ip1
: in std_logic;
ip2
: in std_logic;
op1
: out std_logic
);
end my_exor;
entity
entitydeclaration
declaration--describes
describesthe
the
boundaries
boundariesof
ofthe
theobject.
object.
It
Itdefines
definesthe
thenames
namesof
ofthe
theports,
ports,
Their
Theirmode
modeand
andtheir
theirtype.
type.
my EXOR gate
library IEEE;
use IEEE.std_logic_1164.all;
entity my_exor is
port (ip1
: in std_logic;
ip2
: in std_logic;
op1
: out std_logic
);
end my_exor;
entity
entity--defines
definesthe
the
interface.
interface.
Mode
Modeof
ofthe
theport
port::
Direction
Directionof
offlow.
flow.
It
Itcan
canbe
be
in,
in,out,
out,inout,
inout,buffer
buffer
my EXOR gate
library IEEE;
use IEEE.std_logic_1164.all;
entity
entity my_exor is
entity--defines
definesthe
the
interface.
port (ip1
: in std_logic;
interface.
ip2
: in std_logic;
op1
: out std_logic
);
std_logic
std_logicis
isthe
thetype
typeof
ofthe
the
Mode
Modeof
ofthe
theport
port: :
end my_exor;
port.
ItItcan
port.
canbe
be
Standard
in,
Standardlogic
logicis
isdefined
defined
in,out,
out,inout,
inout,buffer
buffer
by
bythe
thestandard
standard
IEEE
IEEE1164.
1164.
It
Itis
isdefined
definedin
inthe
theIEEE
IEEE
library.
library.
Any
Anynode
nodeof
oftype
typestd_logic
std_logic
can
cantake
take99different
differentvalues.
values.
0
0,,1
1,,H
H,,L
L,,Z
Z,,
U
U,,X
X,,W
W,,-
-
my EXOR gate
library IEEE;
use IEEE.std_logic_1164.all;
entity my_exor is
port (ip1
: in std_logic;
ip2
: in std_logic;
op1
: out std_logic
);
end my_exor;
Library
Library::Collection
Collectionof
ofdesign
design
elements,
elements,type
typedeclarations,
declarations,
sub
subprograms,
programs,etc.
etc.
my EXOR gate
--Program 1.1
library IEEE;
use IEEE.std_logic_1164.all;
entity my_exor is
port (ip1
: in std_logic;
ip2
: in std_logic;
op1
: out std_logic
Mode
Modeof
ofthe
theport
port: :
);
ItItcan
canbe
be
end my_exor;
in,
out
in, outor
orinout
inout
Library
Library: :Collection
Collectionof
ofdesign
design
elements,
type
declarations,sub
elements, type declarations,sub
programs,
programs,etc.
etc.
entity
entity--defines
definesthe
the
interface.
interface.
std_logic
std_logicisisthe
thetype
typeof
ofthe
theport
port
ItItis
isdefined
definedin
inthe
theIEEE
IEEElibrary.
library.
Any
Anynode
nodeof
oftype
typestd_logic
std_logiccan
cantake
take
99different
values.
different values.
0,1,H,L
0,1,H,L, ,Z
Z, ,U
U, ,X
X, ,W
W, ,-
-
my EXOR gate
library IEEE;
use IEEE.std_logic_1164.all;
entity my_exor is
port (ip1
: in std_logic;
ip2
: in std_logic;
op1
: out std_logic
);
Mode
end my_exor;
Modeof
ofthe
theport
port: :
ItItcan
canbe
be
in,
out
or
in, out orinout
inout
Library
Library: :Collection
Collectionof
ofdesign
design
elements,
type
declarations,
elements, type declarations,
sub
subprograms,
programs,etc.
etc.
entity
entity- -defines
definesthe
the
interface.
interface.
std_logic
std_logicisisthe
thetype
typeof
ofthe
theport
port
ItItisisdefined
in
the
IEEE
library.
defined in the IEEE library.
Any
node
Any nodeof
oftype
typestd_logic
std_logiccan
cantake
take
99different
value.
different value.
0
0, ,1
1, ,H
H, ,L
L, ,Z
Z, ,U
U, ,X
X, ,W
W, ,-
-
The
Thearchitecture
architecturedescribes
describesthe
the
behaviour(function),
interconnections
behaviour(function), interconnections
and
andthe
therelationship
relationshipbetween
betweendifferent
different
inputsand
outputs.
inputsand outputs.
The
Theconfiguration
configurationisisoptional.
optional.
ItItdefines
the
entity
architecture
defines the entity architecture
bindings.
bindings.
More
Moreabout
aboutconfigurations
configurationslater.
later.
architecture
architecture my_exor_beh
my_exor_beh of
of my_exor
my_exor is
is
signal
signal temp1
temp1 :: std_logic;
std_logic;
signal
signal temp2
temp2 :: std_logic;
std_logic;
begin
begin
......
......
end
end my_exor_beh;
my_exor_beh;
--Program 1.2
library
library IEEE;
IEEE;
use
use IEEE.std_logic_1164.all;
IEEE.std_logic_1164.all;
entity
entity my_exor
my_exor is
is
port
(ip1
:
in
port (ip1
: in std_logic;
std_logic;
ip2
ip2 :: in
in std_logic;
std_logic;
op1
op1 :: out
out std_logic
std_logic
);
);
end
my_exor;
end my_exor;
architecture
architecture exor_w_sig
exor_w_sig of
of my_exor
my_exor is
is
signal
temp1,
temp2
:
std_logic;
signal temp1, temp2 : std_logic;
begin
begin
temp1
temp1 <=
<= ip1
ip1 and
and (not
(not ip2);
ip2);
temp2
<=
ip2
and
(not
ip1);
temp2 <= ip2 and (not ip1);
op1
op1 <=
<= temp1
temp1 or
or temp2;
temp2;
end
exor_w_sig;
end exor_w_sig;
configuration
configuration my_exor_C
my_exor_C of
of my_exor
my_exor is
is
for
for exor_w_sig
exor_w_sig
end
end for;
for;
end
my_exor_C;
end my_exor_C;
Syntax of an Architecture
architecture <name> of <entity> is
<declarations>
begin
<statements>
end <name>;
23
Presentation Outline
Signal in VHDL
Types of Architecture
Some intuitive way to find diff bet
architectures
VHDL Design Example: Combinational
Circuits
24
Lect Intro
Oh yeah, For all you C people --forget
everything you know.
18/10/15
25
Combinational
Logic
Combinational
Logic
Registers
Signals
SIGNAL a : STD_LOGIC;
a
1
wire
SIGNAL b : STD_LOGIC_VECTOR(7
DOWNTO 0);
bus
library IEEE;
use
use IEEE.std_logic_1164.all;
IEEE.std_logic_1164.all;
entity
entity my_exor
my_exor is
is
port
(ip1
:
in
port (ip1
: in std_logic;
std_logic;
ip2
:
in
std_logic;
ip2
: in std_logic;
op1
op1 :: out
out std_logic
std_logic
);
);
end
my_exor;
end my_exor;
architecture
architecture exor_w_sig
exor_w_sig of
of my_exor
my_exor is
is
signal
signal temp1,
temp1, temp2
temp2 :: std_logic;
std_logic;
begin
begin
temp1
temp1 <=
<= ip1
ip1 and
and (not
(not ip2);
ip2);
temp2
<=
ip2
and
(not
ip1);
temp2 <= ip2 and (not ip1);
op1
op1 <=
<= temp1
temp1 or
or temp2;
temp2;
end
end exor_w_sig;
exor_w_sig;
configuration
configuration my_exor_C
my_exor_C of
of my_exor
my_exor is
is
for
exor_w_sig
for exor_w_sig
end
end for;
for;
end
end my_exor_C;
my_exor_C;
Functional Delay
Syntax: Concurrent statement AFTER
delay;
REMEMBER: Its functional delay, not
inherent delay
ARCHITECTURE dataflow OF xor_gate IS
BEGIN
f <= (a AND NOT b) OR (NOT a AND b)
AFTER 20 ns;
END dataflow;
Entity
Equivalent to pin configuration of an IC
Syntax
entity entity_name is
port (port_list);
end entity_name
Example:
entity not_gate is
port ( a1,a2,a3: in std_logic;
a4,a5,a6: in std_logic;
b1,b2,b3:out std_logic;
b4,b5,b6:out std_logic
);
end not_gate;
1
4
1
3
1
2
1
1
1
0
Entity
VHDL design description must include,
- only one entity
- at-least one corresponding architecture.
Entity declaration
- Defines the input and output ports of the design
- Each port in the port list must be given
- a name
- data flow direction
- a type
Can be used as a component in other entities after being
compiled into library
Entity
Proper documentation of the ports in an entity is very
important
cin
in2
opsel mode
cou
t
ALU
result
Entity
entity ALU is
port (
in1 : in std_logic_vector(3 downto 0);
operand
in2 : in std_logic_vector(3 downto 0);
operand
opsel: in std_logic_vector(3 downto 0);
sel.
cin : in std_logic;
-- carry
mode: in std_logic;
--mode
arithmetic/logic
in1 in2 opsel mode
result: out std_logic_vector (3 downto 0);
result
cou
cout: out std_logic);
cin
ALU
t
carry output
end ALU
result
-- first
-- second
-- operation
input
--operation
--
Modes
Signal in the port has a mode which indicates the driver
direction
Mode also indicate whether or not the port can be read
from within the entity
Four types of modes are used in VHDL
- mode IN
- mode OUT
- mode INOUT
- mode BUFFER
The assignment of hardware I/O buffers to the ports (push-pull, tristate, differential output, etc.) depends on the implementation and the
target technology .
Use of buffer ports is not recommended.
Mode IN
Value can be read but not assigned
Example:
entity driver is
port (
A: in std_logic;
B: out std_logic;
data: inout std_logic;
count: buffer std_logic
);
end driver;
Entity
Port
signal
A
Driver reside
outside the entity
Mode OUT
Value can be assigned but not read
Entity
Example:
entity driver is
port (
A: in std_logic;
B: out std_logic;
data: inout std_logic;
count: buffer std_logic
);
end driver;
Port
signal
Driver reside
inside the entity
Mode INOUT
Value can be read and assigned
Example:
entity driver is
port (
A: in std_logic;
B: out std_logic;
data: inout std_logic;
count: buffer std_logic
);
end driver;
Port signal
Entity
data
Mode BUFFER
Example:
entity driver is
port (
A: in std_logic;
B: out std_logic;
data: inout std_logic;
count: buffer std_logic
);
end driver;
Port
signal
coun
t
Driver reside
inside the entity
Architecture
Test benches
dataflow
Concurrent
statements
structural
Components and
interconnects
behavioral
(sequential)
Sequential statements
Registers
State machines
Instruction decoders
Architecture
architecture [architecture_name] of [entity_name] is
[declarations]
begin
[statements]
end [ architecture_name ];
Carry = A.B
Entity HA_AD is
port ( A, B : in std_logic;
Sum, Carry : out std_logic);
End HA_AD;
Note:
It contains sequential
statements
Use of ifelse if, case,
45
Data-Flow VHDL
Concurrent Statements
46
Define overall
system
P
R
Q
Composed of
2
Components
XOR, AND
Gate
--Same as you
component [component_identifier]
--Another Component
port(P,Q : in std_logic; R: out std_logic);
end component;
Signals, variables
begin
label 1: [component identifier] port map ( )
label 1: [component identifier] port map ( )
end [arch_Identifier]
Entity FA_AD is
port ( A, B, Cin : in
std_logic;
S, Co : out
std_logic);
End FA_AD;
Process Statement
A process statement contains sequential
statements that describe the functionality of a
portion of an entity in sequential terms.
Syntax:
[process-label:] process [(sensitivity-list)] [is]
[process-itemdeclarations]
begin
Sequential statements; these are
variable-assignmentstatement,
waitstatements,
if- statement,
case-statement and so on..
end process [process label];
Process Statement
A set of signal to which process
signal is sensitive is defined
by the sensitivity list.
Sequential statements within the
process are executed in a
sequential order, that is, in the
order in which they appear.
Items declared in the item
declarations part is available for
use only within the process.
Process statement
The process concept comes from software and can be compared to a
sequential program.
If there are several processes in an architecture, they are executed concurrently.
A process can be in Waiting or Executing state.
Executing
Waiting
on
CLOCK;
until
Clock = 1;
for
150 ns;
Concurrent Process
Equivalents
All concurrent statements correspond to a
process equivalent.
U0: q <= a xor b after 5 ns;
is short hand notation for
U0: process
begin
q <= a xor b after 5 ns;
wait on a, b;
end process;
Variable assignment
Variables can bestatement
declared and used inside a
process statement
Variable identifier : type [:=initial value] ;
e.g. variable sum : bit ;
A variable is assigned a value using the variable
assignment statement that is typically has the form;
variable-object := expression;
The expression is evaluated when the statement is
executed, and the computed value is assigned to the
variable object instantaneously, that is, at the
current simulation time
Time
0
10
10 +
20
20 +
30
30 +
p1: process
variable sum1, sum2:
integer;
begin
wait for 10 ns;
sum1:=sum1+1;
sum2:=sum1+1;
end process;
Sum1 Sum2 Sum1 Sum2
0
0
1
1
2
2
3
0
0
1
1
2
2
3
0
1
1
2
2
3
3
0
2
2
3
3
4
4
Information transfer
Variables cannot transfer information outside the sequential part of VHDL in
which it is declared, in the previous example process p1.
If access is needed to the value of sum1 or sum2, they must be declared as
signals/out or the value of the variable assigned to a signal.
Entity ex is
port(sum1_sig, sum2_sig: out
integer);
end;
Architecture bhv of ex is
begin
p1: process
variable sum1, sum2:
integer;
begin
wait for 10 ns;
sum1:=sum1+1;
sum2:=sum1+1;
sum1_sig<=sum1;
sum2_sig<=sum2;
end process;
end;
Case Statement
[ case _label : ] case expression is
{ case_statement_alternative }
When - Else
target_signal <= value1 when condition1 else
value2 when condition2 else
...
valueN-1 when conditionN-1
else
Default_value;
0
1
0
1
0
1
Value 2
Value 1
Condition N-1
Condition 2
Condition 1
Prof Amit Degada
Target Signal
choices_N
choice expression
Prof Amit Degada
Multiplexer
IN0
IN1
IN2
IN3
4: 1
Multiplex
er
S0 S1
Output
Multiplexer
The multiplexer is described in VHDL with following statements
IF
CASE
WHEN Else
WITH select When.
Library ieee;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
numerical computation.
Entity mux4_1 is
port ( s0 : in std_logic;
s1 : in std_logic;
in0 : in std_logic;
in1 : in std_logic;
in2 : in std_logic;
in3 : in std_logic;
output : out std_logic );
End mux4_1;
-- package to be include
-- provides unsigned
IF
Architecture if_example of mux4_1 is
Statement
Begin
CASE
Statement
ARCHITECTURE case_example
OF mux4_1 IS
BEGIN
mux: PROCESS (s0, s1, in0, in1, in2, in3)
VARIABLE sel : STD_LOGIC_VECTOR (1 DOWNTO 0);
BEGIN
sel := s1 & s0;
-- concatenate s1 and s0
CASE sel IS
WHEN "00" => output <= in0;
WHEN "01" => output <= in1;
WHEN "10" => output <= in2;
WHEN "11" => output <= in3;
WHEN OTHERS => output <= 'X';
END CASE;
When
ARCHITECTUREStatement
when_example OF mux4_1 IS
BEGIN
WITH-SELECT-WHEN
Statement
ARCHITECTURE with_example OF mux4_1 IS
75
compare
Incorrect
when a = b and c else
equivalent to
when (a = b) and c else
Correct
when a = (b and c) else
Prof Amit Degada
a = bc
Logic Operators
and
xnor
or
nand
nor
xor
Highest
and
or
not
nand
nor
not
only in VHDL-93
or later
xor
xnor
Lowest
77
Prof Amit Degada
Operators
Relational operators
/=
<
<=
>
>=
not
=
/=
<
<= >
>=
and or nand nor xor xnor
78
No Implied Precedence
Wanted: y = ab + cd
Incorrect
y <= a and b or c and d ;
equivalent to
y <= ((a and b) or c) and d ;
equivalent to
y = (ab + c)d
Correct
y <= (a and b) or (c and d) ;
Prof Amit Degada
10
SIGNAL
SIGNAL
SIGNAL
SIGNAL
Splitting buses
a
4
10
5
b
c
SIGNAL
SIGNAL
SIGNAL
SIGNAL
Sequential Hardware
You have to distinguish between
combinational, latches and synchronized
Flip-Flops
Lack of understanding is a common source
of errors.
We will first cover latches,
Next we will cover flip-flops
D latch
Graphical symbol
D
Truth table
Q(t+1)
Clock D
0
1
1
Clock
0
1
Q(t)
0
1
Timing diagram
Clock
t1
t2
t3
t4
D
Q
Time
D latch
library ieee;
use ieee.std_logic_1164.all;
entity dlatch_my is
port(D, Clock : in std_logic;
Q : out std_logic);
end dlatch_my;
architecture dlatch of dlatch_my is
begin
process(D,Clock)
begin
if (Clock = '1') then
Q <= D;
end if;
end process;
end architecture;
D
Clock
D flip-flop
Graphical symbol
D
Truth table
Clk D
Clock
Timing diagram
Clock
t1
t2
t3
0
1
0
1
Q(t+1)
0
1
Q(t)
Q(t)
t4
D
Q
Time
D flip-flop
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY flipflop IS
PORT ( D, Clock
: IN STD_LOGIC ;
Q
: OUT STD_LOGIC) ;
END flipflop ;
ARCHITECTURE behavioral OF flipflop IS
BEGIN
PROCESS ( Clock, D )
BEGIN
IF Clock'EVENT AND Clock = '1' THEN
Q <= D ;
END IF ;
END PROCESS ;
END behavioral ;
D
Clock
D flip-flop
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY flipflop IS
PORT (
D, Clock : IN STD_LOGIC ;
Q
: OUT STD_LOGIC) ;
END flipflop ;
ARCHITECTURE behavioral2 OF flipflop IS
BEGIN
PROCESS ( Clock )
BEGIN
IF rising_edge(Clock) THEN
Q <= D ;
END IF ;
END PROCESS ;
END behavioral2;
Clock
D flip-flop
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY flipflop IS
PORT ( D, Clock
: IN STD_LOGIC ;
Q
: OUT STD_LOGIC) ;
END flipflop ;
ARCHITECTURE behavioral3 OF flipflop IS
BEGIN
PROCESS
BEGIN
WAIT UNTIL rising_edge(Clock) ;
Q <= D ;
END PROCESS ;
END behavioral3 ;
Clock
STD_LOGIC ;
STD_LOGIC) ;
Q
D
Clock
Resetn
D
Clock
Resetn
BEGIN
IF Resetn = '0' THEN
Q <= "00000000" ;
ELSIF rising_edge(Clock) THEN
Q <= D ;
END IF ;
END PROCESS ;
END behavioral ;
Clock
reg8
Resetn N
D
Q
Clock
regn
Words on
generics
Use of OTHERS
OTHERS stand for any index
value that has
not been previously mentioned.
Q <= 00000001
can be written as
Q <= 10000001
can be written as
Q <= 00011110
can be written as
PROCESS (Clock)
BEGIN
N
IF (rising_edge(Clock)) THEN
IF (Enable = '1) THEN
Q <= D ;
END IF ;
END IF;
END PROCESS ;
END behavioral ;
Enable
Q
D
Clock
regn
--
ENTITY upcount IS
PORT ( Clear, Clock: IN
Q
: OUT
END upcount;
STD_LOGIC;
STD_LOGIC_VECTOR(1 DOWNTO 0));
Clear
upcount
Clock
Non-synthesizable VHDL
Delays
Delays are not synthesizable
Statements, such as
wait for 5 ns
a <= b after 10 ns
will not produce the required delay, and
should not be used in the code intended
for synthesis.
Initializations
Declarations of signals (and variables)
with initialized values, such as
SIGNAL a : STD_LOGIC := 0;
cannot be synthesized, and thus should
be avoided.
If present, they will be ignored by the
synthesis tools.
Use set and reset signals instead.
PROCESS (clk)
BEGIN
counter <= counter + 1;
END PROCESS;
Sin
Clock
Enable
Q(1)
Q(2)
Q(3)
Q(0)
D(1)
D(2)
Sin
D
D(0)
Clock
Enable
Q(3)
Q(2)
Q(1)
Q(0)
Enable
D
Q
Load
Sin
--Program 5.11
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
ENTITY shift4 IS
PORT (
Enable
Load
Sin
Clock
Q
END shift4 ;
D
:
:
:
:
:
IN
IN
IN
IN
OUT
shift4
Clock
: IN
STD_LOGIC_VECTOR(3 DOWNTO 0) ;
STD_LOGIC ;
STD_LOGIC ;
STD_LOGIC ;
STD_LOGIC ;
STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
Enable
D
Q
Load
Sin
shift4
Clock
ARCHITECTURE behavioral OF shift4 IS
SIGNAL Qt : STD_LOGIC_VECTOR(3 DOWNTO 0);
BEGIN
PROCESS (Clock)
BEGIN
IF rising_edge(Clock) THEN
IF Enable = 1 THEN
IF Load = '1' THEN
Qt <= D ;
ELSE
Qt <= Sin & Qt(3 downto 1);
END IF ;
END PROCESS ;
Q <= Qt;
END behavioral ;
Enable
D
Q
Load
Sin
Clock
shiftn
Enable
D
Q
2-115
2-116
2-117
VHDL
Assert
- Loop
Agenda
Assert statement
Examples
--indefinite Loop
--Conditioned Loop
--Counted Loop
Syntax:
[label]: while condition loop
statements;
end loop [label];
Statements are executed continuously as long
as condition is TRUE
The statements within the body of the loop are
executed sequentially
Condition is evaluated BEFORE execution.
Write a description to generate a pulse train whenever stop = 0. The
frequency of the pulse train should be half the clock frequency.
. . .
end process;
process
variable count : natural := 0;
begin
wait until clkevent and clk = 1;
count := 0;
RxLoop: while count < 255 loop
exit RxLoop when (rx = 0);
if (inbyte /= FILLER) then
data(count) <= inbyte;
count := count + 1;
end if;
wait until clkevent and clk = 1;
end loop RxLoop;
end process;
VHDL
Generate
- Subprograms
Array
Agenda
Generate statement
if
For
Subprograms
Procedure
function
Array
concurrent_statement
END GENERATE generate_label ;
FOR generate_parameter_specification
IF condition
--Label is
Conditional generation
if condition generate
-- concurrent statement
end generate;
Note that for generate and if generate both are concurrent
statements. So any combination is allowed.
This is usually used within afor ..generatestatement, to account for
irregularity.
Conditional generation
U0
Sin
D
clk
U1
D
clk
U2
D
clk
Un
Reset
Sout
clk
Clock
Conditional generation
for i in 0 to N generate
if (i = 0) generate
U: dff port map (sin , clk,
reset ,tmp(i+1));
end generate;
if ((i > 0 ) and (i < N)) generate
U: dff port map (tmp(i), clk,
reset,tmp(i+1));
end generate;
if (i = N) generate
U: dff port map (tmp(i), clk,
reset, sout);
end generate;
end generate;
Subprograms
Subprograms consist of procedures and functions
A function can return only one argument; a procedure
can return more than one arguments.
In a function all parameters are input parameters. In a
procedure parameters can be input, output or inout.
Subprograms can be concurrent or sequential.
Subprograms can have only sequential statements.
Subprograms can have any sequential statement,
including the wait statement.
The procedure exists as a separate statement in the
architecture or process, while the function is a part of
an expression.
Subprograms
Subprograms can be defined either in a
package, architecture or process.
Avoid subprogram side-effects.
Signal type of attributes cannot be used within
a subprogram.
A return statement in a function has a return
expression whereas the procedure return
statement does not have an expression.
Syntax
procedure <procedure_name> ( parameter list ) is
declarations;
begin
statements;
end [ procedure ] [ name] ;
function <function_name> ( parameter list )
return <return_type> is
declarations;
begin
statements;
return parameter;
end [ function ] [ function_name ];
Parameter list
Parameter list specification consists of:
Class definition (signal, variable, constant).
Name of the parameter.
Mode of the parameter (in, out, inout).
Subtype indication.
Optional initial value.
Class constant is assumed if an interface class is
not specified
For procedures always specify the mode of the
parameters (in, out, inout). For functions all
parameters are of mode in and hence need not be
specified.
Parameter list
Parameters passing
Signals can only be associated with signals
Variables can only be associated with variables.
Constants can be associated with either signal,
variable or constant
A parameter cannot have an initialization value if it
is a signal or if it has a mode other than IN.
The actual value of the parameter passed overrides
the default value.
The actual signal associated with a signal
parameter must be static.
Example
procedure avg_samples(signal samples: in my_list;
signal average: out real) is
variable total: real := 0.0;
begin
for index in 0 to 255 loop
total := total + samples(index);
end loop;
average <= total/256.0;
end procedure avg_samples;
signal data_in_list : my_list;
signal average_value : real;
begin
. . .
avg_samples(data_in_list, average_value);
Side effects
A sub program is said to have side effects if it
changes something not declared in its parameter
list.
Procedures and impure functions (VHDL93)
defined in the architecture have visibility of the
ports and the signals declared in the
architecture.
They have visibility of the variables and loop
parameters in the calling process.
They also have visibility to the global signals.
Avoid side effects on procedures. If it is
unavoidable then comment it properly.
ROM
0);
END instruction_rom;
Thanks