Escolar Documentos
Profissional Documentos
Cultura Documentos
11 BLOQUES ARITMTICOS
Elena Valderrama
Universidad Autnoma de Barcelona
4 .1
Losbloquesaritmticosconstituyenunaparteimportanteencasocualquiercircuito
digital.
Estudiaremoscircuitoscapacesdeimplementarlas4operacionesbsicas:
1.SUMA
2 RESTA
2.RESTA
3.MULTIPLICACIN
4.DIVISIN
4 .1
1.Sumabinaria
Sumadorparalelo:Verlecciones2.2y2.3delasemana2.
xi
yi
n
n
acarreo0
Sumadorn+1
n bits
Sumador
1bit
acarreoOUT
acarreoIN
Full_Adder (FA)
zi
xn-1
acarreoOUT
yn-1
Sumador
1bit
zn-1
xn-2
Sumador
1bit
zn-2
x1
yn-2
y1
Sumador
1bit
z1
x0
y0
Sumador
1bit
acarreoIN
z0
3
4 .1
2.Restabinaria
Unrestadorbinariorealizaelclculo:
n
n
donde:
acarreo0:1bit
(habitualmente igual a 0)
(habitualmenteiguala0)
acarreo0
n+1
Restador
Restador
n bits
Cmorepresentamosunnmeronegativo?
, serepresentaporunnmeroden+1
p
p
SiD<0,D
bitsllamadoelcomplementoa2deD:
4 .1
2.Restabinaria
Algoritmomanual:
1 1 0 0
1 0 0 1
1 0 0 1
1 1 0 0
n pasos,encadapasocalculamos:
Elbitresta:
Elacarreohacialaetapa
siguiente:
g
4 .1
2.Restabinaria
Algoritmo1delaresta
acarreo(0)<=acarreo_inicial; (habitualmente 0)
for i in0ton1loop
in 0 to n 1 loop
d(i)<=(x(i)+y(i)+acarreo(i))mod2;
acarreo(i+1)<=sign(x(i) y(i) acarreo(i));
p;
end loop;
s(n)<=acarreo(n);
Algoritmo2delaresta
acarreo(0)<=acarreo_inical;; (habitualmente 0)
fori in0ton1loop
d(i)<=x(i)xor y(i)xor acarreo(i);
acarreo(i+1)<=
(not(x(i)) and y(i)) or (not(x(i)) and acarreo(i))
(not(x(i))andy(i))or(not(x(i))andacarreo(i))
or (y(i)and acarreo(i));
endloop;
s(n)<=acarreo(n);
4 .1
2.Restabinaria
Restador n+1
n bits
xi
acarreoOUT
yi
acarreo0
Restador
1bit
acarreoIN
Full_Substractor
((FS))
di
xn-1
dn=acarreoOUT
yn-1
xn-2
FS
FS
dn-1
dn-2
x1
yn-2
y1
x0
y0
FS
FS
d1
d0
acarreoIN
4 .1
(Ejercicio)
ConstruiruncircuitoquecalculeD =x y (x,y den bits)ydevuelvaelvalordeD enla
representacin clsica de signo
representacinclsicade
signoymagnitud
y magnitud,,esdecir,comoD
es decir, como D =((1)
1)sign|D
|D|
Sugerencia:Calculaenparalelox y andy x yseleccionael|D|dependiendodelsignodex y.
4 .1
(Solucin del ejercicio)
(Solucindelejercicio)
ConstruiruncircuitoquecalculeD =x y (x,y den bits)ydevuelvaelvalordeD enla
p
g y
g
,
,
=(1)
( )sign|D|
| |
representacinclsicadesignoymagnitud,esdecir,comoD
Sugerencia:CalculaenparaleloX Y andY X yseleccionael|D|dependiendodelsignodeX Y.
x
subtract.
Restador
subtract.
Restador
d
d
d
d
0
sign
d
9
4 .1
3.Multiplicadorbinario
Unmultiplicadorrealizaelclculo:
donde:
Algoritmo1:
MayorvalordeP:
p0 =Xy
X 0;
p1 =Xy12;
p2 =Xy222;
pm1 =Xym12m1;
P =p0 +p1 +p2 ++pm1 .
P esunnmeroden+m bits
10
3.Multiplicadorbinario
4 .1
Algoritmo1:
p0 =Xy0;
p1 =Xy12;
p2 =Xy222;
pm1 =Xym12m11;
P =p0 +p1 +p2 ++pm1 .
Ej
Ejemplo:
l
101101
x1011
101101 p0
101101 p1
000000
000000
p2
101101 p3
111101111 P
11
3.Multiplicadorbinario
4 .1
p0 =Xy0;
p1 =Xy12;
p2 =Xy222;
pm1 =Xym12m1;
P =p0 +p1 +p2 ++pm1 .
Algoritmo2:Righttoleft algorithm
acc <=0;
fori in0tom1loop
acc <=acc +X*(2**i)*y(i);
endloop;
P<
P<=acc;
12
4.Divisorbinario
4 .1
13
4 .1
4.Divisorbinario
Algoritmodedivisinbinaria
r(0)<=x;
for i in1toploop
in 1 to p loop
d<=2*r(i1) y;
ifd<0thenq(i)<=0;r(i)<=2*r(i1);
else q(i) <=1;r(i)<
elseq(i)<
1; r(i) <=d;
d;
end if;
end loop;
Resultado:
Q =(q1 q2 qp1 qp)2p,
R =r
= rp2pp.
Ejemplo:X=21,Y =35,p =6
iteracin
0
1
2
3
4
5
6
r
21
7
14
28
21
7
14
1
0
0
1
1
0
7
21
7
7
21
7
<0
comentarios
D=4235=7
D=1435=21
D=2835=7
D=5635=21
D=4235=7
D=2835< 0
14
4.Divisorbinario
4 .1
Algoritmodedivisinbinaria
r(0)<=x;
for i in1toploop
in 1 to p loop
d<=2*r(i1) y;
ifd<0thenq(i)<=0;r(i)<=2*r(i1);
else q(i) <=1;r(i)<
elseq(i)<
1; r(i) <=d;
d;
end if;
end loop;
15
4 .1
RESUMEN
Hemosvistounconjuntodecircuitoscapacesdeejecutarlasoperacionesaritmticas
bsicasdesuma,resta,multiplicacinydivisin.
Hemosintroducido,aunquemuybrevemente,larepresentacindenmerosnegativos
medianteelcomplementoa2.
16
CONTENTS
1.
1
2.
3.
4
4.
5.
6.
7
7.
4 .2
Maingoals&Expectedlearning
M
i
l &E
t dl
i
BasicsonVHDLlexical&syntax
VHDLDesignUnits
VHDL Sequential Sentences (selection)
VHDLSequentialSentences(selection)
VHDLConcurrentSentences(selection)
VHDLusageformodelling,simulationandsynthesis
Summary
18
4 .2
M i
Maingoals
l
VHDLsyntax,mainunitsandstructure
Fundamentalsonsequentialandconcurrentstatements
Processes
Componentinstances
Signalassignments
VHDLusage:modelling,simulationandsynthesis
Expectedlearning
BasicknowledgeaboutVHDLlanguageanditsusage(basedonexamplesalreadyseeninthiscourse)
BeabletoreadandunderstandsimpleVHDLcode
BeabletowritespecificportionsofVHDLcode
Understandtheroleofhardwarelanguagesindigitalsystemsdesign
19
4 .2
access
assert
case
file
in
next
or
after
attribute
component
for
inout
nor
others
alias
begin
else
function
is
not
out
all
block
elsif
generate
label
null
process
and
body
end
generic
library
of
procedure
architecture
buffer
entity
guarded
nand
on
...
Symbols
Literales
- 1 or 2 characters
Base
- operators, punctuation, comments, part of sent. 2#110_1010#
16#CA#
+ - * / ( ) . , : & < >
= 16#f.ff#e+2
| # ; -- => ** := /= >= <= <> Decimal
12 0 1E6
Character
a A @
String
Tiempo
110101
Physical
10 ns
2.2 V
50 pF
Bit String
XF0f B111_100
4 .2
constant
constant
constant
constant
t t
VHDLobjectisanylanguageelementabletocontainavalue
TypesofVHDLobjects:
Constant
Variable
Object definition:
<Object type> <identifier> : <data
Signal
File
PI : real := 3.1415927;
WordBits : natural := 8;
NumWords : natural := 1024;
T tBit : natural
TotBits
t
l := WordBits
W dBit * NumWords;
N W d
Signal declaration
& initialization
Variables
declaration
Increment
I
t := 2;
2
Counter := Counter + Increment;
Variables
V
i bl
assignment
Si
Signal
l assignment
i
t
file Estimuli : FileTypeName1 open read_mode is data.in;
file Dataout : FileTypeName2 open write_mode is data.out; 21
4 .2
VHDLDataTypes
TheVHDLisastronglytypedlanguage
Adatatypedefinesasetoffixedandstaticvalues
Anylanguageobjectbelongstoaspecificdatatype
Objectvaluesshallbelongtorelateddatatype
STANDARD package:
is (false, true);
boolean
Newdatatypescouldbeuserdefined
Predefined Types of VHDL
type
type bit is (0, 1);
type severity_level is (note, warning, error, failure);
type character is (NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS,
HT, LF, VT, FF, CR, SO, SI, DEL, DC1, DC2, DC3, DC4, DC5, NAK,
SYN, ETB, CAN, EM, SUB, ESC, FSP, GSP, RSP, USP, , !, ,
#, $, %, &, , (, ), *, +, ,. -, ., /,
0,
0 , 1,
, 2,
, 3,
3 , 4,
, 5,
5 , 6,
6 , 7,
, 8,
8 , 9,
9 , :,
: , ;,
; , <,
,
=, >, ?, @, A, B, C, D, E, F, G, H, I,
J, K, L, M, N, O, P, Q, R, S, T, U, V,
W, X, Y, Z, [, \, ], ^, _, `, a, b, c,
d, e, f, g, h, i, j, k, l, m, n, o, p,
q, r, s, t, u, v, w, x, y, z, {, ...);
type integer is range -2.147.483.647 to 2.147.483.647;
type real is range -1.0e38 to 1.0e38;
/
22
4 .2
VHDLDataTypes
yp
TheVHDLisastronglytypedlanguage
Adatatypedefinesasetoffixedandstaticvalues
Any language object belongs to a specific data type
Anylanguageobjectbelongstoaspecificdatatype
Objectvaluesshallbelongtorelateddatatype
Newdatatypescouldbeuserdefined
4 .2
Operatorsaresymbolsidentifyingspecificoperations
Types:arithmetic,logic,relationalandconcatenation
Operands:
Expressions:
Relational
Logic
Arithmetic
=
/=
<
<=
>
>=
and
or
nand
nor
xor
not
+
*
/
**
mod
rem
abs
Concatenation
&
Arithmetic
(-b + sqrt(b**2 - 4.0*a*c))/(2.0*a)
Relational
delay >= 20 ns
name < Smith
Logic
(a xor b) and not c;
Concatenation
BitSign & VectorValue
Expressionscouldbeassignedto:
p
g
Constants(const := expression;)
Variables(var := expression;) 24
Signals(sig <= expression;)
4 .2
Entity
Architecture
Package(declaration&body)
Configuration
Architecture
1
Architecture
n
Package
Declaration
Package
g
Body
Secund
dary
Architecture
2
Configuration
D l
Declaration
i
Prim
mary
Entity
Declaration
25
4 .2
Likeablackboxjustdescribingexternalinterfaceforamodulewhile
hidingitsinternalarchitecture
Syntax:
Entity name (module name)
entity <id> is
[<generics>];
[<ports>];
p
[<declarations>];
[begin <sentences>];
end [entity] [<id>];
Generic parameters
Input/Output ports (electrical interface)
Global declarations (common to any potential architecture of this entity)
Passive sentences (common to any potential architecture of this entity)
entity MUX21 is
port( A
:
B
:
Ct l :
Ctrl
Z
:
end MUX21;
in
in
i
in
out
bit;
bit;
bit
bit;
bit;
A
B
Ctrl
MUX21
Z
26
4 .2
Likeablackboxjustdescribingexternalinterfaceforamodulewhile
hidingitsinternalbehaviourandarchitecture
Syntax:
Entity name (module name)
entity <id> is
[<generics>];
[<ports>];
p
[<declarations>];
[begin <sentences>];
end [entity] [<id>];
Generic parameters
Input/Output ports (electrical interface)
Global declarations (common to any potential architecture of this entity)
Passive sentences (common to any potential architecture of this entity)
entity MUX21n
generic( n
port( A
B
Ctrl
Z
end MUX21;
is
: integer := 2);
: in bit_vector(n-1 downto 0);
: in bit_vector(n
bit vector(n-1
1 downto 0);
: in bit;
: out bit_vector(n-1 downto 0));
A
B
Ctrl
n
n
MUX21
Z
27
4 .2
DetailswhatisbehindanEntitywhiledescribingitsbehaviouratfunctional,
dataflow,structuralormixedlevels
MultipleArchitecturesfo asingleEntityarepossible
Syntax:
Architecture name
architectura <id> of <id_entity> is
[<declarations>];
begin
<concurrent sentences>;
end [architecture] [<id>];
E tit name
Entity
Signals, variables, components
Concurrent sentences:
Concurrent assignments
Instances to components
Processes
Blocks
28
4 .2
A
B
Ctrl
MUX21
Z
entity MUX21n is
generic ( n: natural);
port( A
: in bit_vector(n-1 downto 0);
B
: in bit_vector(n-1 downto 0);
Ctrl : in bit;
Z
: out bit_vector(n-1 downto 0));
end MUX21;
architecture Functional of MUX21n is
begin
process(A, B, Ctrl)
begin
if Ctrl = 0 then
Z <= A;
;
else
Z <= B;
n
end if;
end process; A
n
end
d Functional;
F
ti
l B
MUX21n
Ctrl
29
in
i
in
in
out
bit;
i
bit;
bit;
bit;
4 .2
architecture structural of MUX21 is
signal Ctrl_n, N1, N2 : bit;
component INV
port( Y : in bit;
Z : out bit);
end component;
component AND2
port(
p
( X,
, Y : in bit;
;
Z
: out bit);
end component;
component OR2
port( X, Y : in bit;
Z
: out bit);
end component;
begin
U0: INV port map (Ctrl, Ctr_n);
U1: AND2 port map (Ctrl_n, A, N1);
U2: AND2 port map (Ctrl, B, N2);
U3: OR2 port map (N1, N2, Z);
end structural;
30
4 .2
Usefulforcodereuseasitcouldcontaindefinitionsofdatatypes,functionsand
languageobjects(constants,variables,signalsorfiles)foritsuseondifferentcodes
Twounits:
P k
Package
name
Packagedeclaration package <identifier>
[<declarations>];
end [package] [<identifier>]
Declarations of:
Data types
Constants
Functions & procedures
Package name
Packagebody
g
y
Packageusage
g
g
use <library>.<package name>.[<identifier> | all];
4 .2
Constant Id.
Id
Constant
data type
Comment
32
4 .2
package
body VSuP_Pack is
PACKAGE
-- Processor basic dimensions
constant ProcWordBits : integer := 16; -- Processor word lenght (bits)
constant MemAdrBits : integer := 16; -- Memory address lenght (bits)
constant CtrlBusNumBits : integer := 25; -- Number of bits for control bus
constant StatusBusNumBits : integer := 5; -- Number of bits for status and flags bus
constant ALUopNumBits : integer := 4; -- Number of bits to especify the ALU operation code
constant OpCodeNumBits : integer := 5; -- Number of bits to especify the instruction OpCode
constant Bus2zeros : std_ulogic_vector (ProcWordBits-1 downto 0):= (others =>0);
constant Bus2ones : std_ulogic_vector (ProcWordBits-1 downto 0):= (others =>1);
g _vector (
(ProcWordBits-1 downto 0)
) := conv_std_logic
g _vector (
(1,
,
constant One : std_ulogic
ProcWordBits);
-- Mnemonics for ALU operations
-- No operation cycle
constant NoOp : std_ulogic_vector (ALUopNumBits-1 downto 0) := "0000";
-- Addition: Out <- A + B;[C
B;[C,N,Z]
N Z]
constant Add : std_ulogic_vector (ALUopNumBits-1 downto 0) := "0001";
-- Subtraction: Out <- A - B;[C,N,Z]
constant Sub : std_ulogic_vector (ALUopNumBits-1 downto 0) := "0010";
/
-- Put all
ll output bi
bits at '1':
1
Out <- "1...1";[N]
1
1 [ ]
constant Out1 : std_ulogic_vector (ALUopNumBits-1 downto 0) := "1111";
end package body VSuP_Pack;
33
4 .2
Sessionsummary
BasicsonVHDLlexicalandsyntax
Languagelexicalelements
Objects(constant,variable,signalandfiles)
Objects (constant variable signal and files)
Datatypes,Operatorsandexpressions
VHDLdesignunits
EntityandArchitecture
Configuration
Package(declaration&body)
Package (declaration & body)
SimplifiedformalVHDLdesignunitsdescriptionsbutexamplebasedlearning
34
(cont.)
4 .3
Sequentialvs.ConcurrentSentences
Sequential
AlgorithmicsentenceslikeforSWlanguages(if, case, loop, exit, return, )
Interpretedsequentially Orderofsentencesisimportantfortheresults
Onlyusedinfunctions,proceduresandProcesses
Concurrent
Devotedtoexpresshardwarestructure(Hw componentsandblocksaredoingconcurrently)
andprocessesworkingsimultaneously
d
ki
i l
l
Somesequentialsentenceshaveitsequivalentconcurrentones
Selectedsentences:Process,Signalassignments,Componentsinstantiation
MainlyusedinArchitectures
Mainly used in Architectures
ConcurrenttoSequentialforsimulation
EachconcurrentstatementcouldbetranslatedtoitsequivalentProcess basedonsequential
statements.
Forsimulationpurposesalltheconcurrentstatementsaretranslatedtorelatedprocesses.
VHDLeventdrivensimulationwillmanagejustalotofprocesses.
36
4 .3
SequentialSentences
Wherearepossible?
process
begin
-- sequential
-- sentences
end process;
procedure P() is
begin
-- sequential
-- sentences
end P;
Whicharetheselectedsentences?
Variable&Signalassignments
Wait
Ifthenelseendif
Case
Loop,ExitandNext
Functions & Procedures
Functions&Procedures
Assertreportseverity
37
4 .3
SequentialSentences:VariableAssignment
Immediate replacementofvariablevalue.
Syntax:
[label:] <variable name> := <expression>;
Examples:
Var := 0;
Vector := 00011100;
string := Message is: ;
A := B;
B := my_function(3,databus)
C := my_function(4,adrbus)
my function(4 adrbus) + A;
38
4 .3
Projectsanewevent(value,time)onthesignaldriver.
Syntax:
t0
t1
ti
v0
v1
vi
Nextsentencesequenceswillexchangethevalues
betweensignalAandB:
Delaytypes:inertialortransport
Examples:
p
A <= B;
B <= A;
B <= A;
A <= B;
B1
B2
B3
A
0
10
20
30
40
50
60
70
((ns))
10
15
20
28
40
50
4 .3
Indicatesthepointwhereaprocessexecutionshallbesuspended,aswellasthe
Indicates
the point where a process execution shall be suspended as well as the
conditionsforitsreactivation.Morethanonewaitsentenceperprocessispossible.
Syntax:
[label:] wait [on <signal> {, ...}]
[until <boolean_expresion>]
[for <time_expresion>];
B i
Basicexamples:
l
process
begin
<sequential sentences>
wait;
end process;
Withoutreactivationcondition
process
begin
c <= a and b;
wait on a, b;
end process;
Sensibletoeventsonsignalsab
process
begin
Clock <= not Clock;
wait for 10 ns;
end process;
Sensibletoeventsonsignals&condition=True
4 .3
SelectsthegroupofsentencestoexecutedependingonaBooleancondition.
Syntax:
[label:] if <condicion> then
<sentencias secuenciales>
{elsif <condicion> then
<sentencias secuenciales}
[else
<sentencias secuenciales>]
end if [
[label];
]
Examples:
Latch: process begin
if load =1 then
Q <= D;
end if;
wait on load, D;
end process;
Latch
Process (A,
(A B
B, Ctrl)
Begin
if Ctrl = 0 then
Q <= A;
else
Q <= B;
end if;
end process;
Mux
Buffer Triestate
process
begin
if Enable =1 then
S lid <= Entrada;
Salida
d
else
Salida <= Z;
end if;
wait on Enable, Entrada;
end process;
41
4 .3
SequentialSentences:Case
Selectsthegroupofsentencestoexecute
dependingonaexpressionvalue.
Syntax:
Orofvalues:when00|01
Valuesrange:when5to12(integers)
Lastoption:whenothers
type weekdays
t
kd
: (Monday,
(M d
T
Tuesday,
d
W d
Wednesday,
d
Th
Thursday,
d
F id
Friday,
S t d
Saturday,
S d )
Sunday);
type typeofday : (Workingday, Holiday);
Signal Day : Weekdays;
process
process
Signal Daytype : typeofday;
begin
begin
case ValEnt
V lE t is
i
case Day
D
i
is
when 0
=> Res := 5;
when Monday to Friday =>
when 1 | 2 | 8 => Res := ValEnt;
Daytype <= Workingday;
when 3 to 7
=> Res := ValEnt + 5;
when Saturday | Saunday =>
when others
=> Res := 0;
Daytype <= Holiday;
end case;
end case;
wait on ValEnt;
wait on Day;
end process;
end process;
42
Examples:
PreviousexamplewithtwoProcess:
Mux
Latch
LatMux
A
B
C
D
4 .3
entity LatMux is
port(
Load
: in bit;
A B
A,
B, C
C, D : in bit;
Ctrl
: in bit_vector(0 to 1);
Y
: out bit);
end LatMux;
architecture TwoProc of LatMux is
Signal X : bit;
Concurrent Statements
begin
Mux: process (Ctrl, A, B, C, D);
begin
case Ctrl is
when 00 => X <= A;
when 01 => X <= B;
when 10 => X <= C;
when 11 => X <= D;
end case;
;
end process;
Sequential Statements
Ctrl
Load
43
4 .3
SequentialSentences:Loop
Sequentialsentencesintheloopregionarerepeatedforanumberoftimes.
Typesofloops:while,forandwithoutiterationscontrol(infiniteloop).
Syntax: [[label:]
abe :] [
[while
e <boolean
boo ea _co
condition>
d t o
| for
o <repetition
epet t o _co
control>]
t o ]
loop
<sequential sentences>}
end loop [label];
achitecture Functional of ParallelAdder is
begin
process (X, Y, Cin);
Examples:Fulladder
variable C : std_logic_vector(n downto 0);
variable tmp : std_logic;
variable I : integer;
entity ParallelAdder is
begin
g
generic (n : natural :=4 );
C(0) := Cin;
port ( X, Y : in
for I in 0 to n-1 loop
std_logic_vector(n-1 downto 0);
tmp
:= X(I) xor Y(I);
Cin : in std_logic;
Z(I)
<= tmp xor C(I);
Z : out std_logic_vector(n-1 downto 0);
C(I+1) := (tmp and C(I)) or (X(I) and Y(I));
Cout : out std_logic);
end loop;
End ParallelAdder ;
Cout <= C(n);
end process;
44
end Functional;
4 .3
SequentialSentences:Exit(insidealoop)
Endstheloopexecutionwhenboolean_conditionistrueandgoestonextsentence
aftertheloop.
Syntax: [label:] exit [loop_label] [when <boolean_condition>];
Needed
N
d d for
f neested
t d loops
l
t id tif which
toidentify
hi h is
i the
th
loop tobeexitedor nexted
SequentialSentences:Next(insidealoop)
Stopscurrentloopiterationwhenboolean_conditionistrueandgoesforthenextiteration
St
tl
it ti
h b l
diti i t d
f th
t it ti
(skipscurrentiterationafterthissentence).
Syntax: [label:] next [loop_label] [when <boolean_condition>];
45
4 .3
SequentialSentences:Functions(sameassoftwarelanguages)
Apieceofcodedevotedtospecificcomputationofinputparameterstoreturnavalue.
Syntaxforfunctiondeclaration: function <name> [(<parameters list>)] return <data_type>;
Syntaxforfunctiondefinition:
function <name> [(<parameters list>)] return <data_type> is
{<declarative part>}
begin
{<sequential sentences>}
[label:] return [expresion];
end [function] [<name>];
Example:
p
function bv2int (bs: bit_vector(7 downto 0)) return integer;
Var :
:= base + bv2int(adrBus(15 downto 8));
Functionusage
Sig <= base + bv2int(adrBus(7 downto 0));
orreference
46
4 .3
SequentialSentences:Procedures(sameassoftwarelanguages)
Apieceofcodedevotedtospecificcomputationofinputparameterstoreturnavalue.
Syntaxforproceduredeclaration: procedure <name> [(<parameters list>)];
Syntaxforproceduredefinition:
procedure <name> [(<parameters list>)] is
{<declarative part>}
begin
{<sequential sentences>}
end [function] [<name>];
Example:
p
procedure bv2int (bs: bit_vector(7 downto 0); x: out integer );
Procedureusage
orreference
4 .3
Akindofvalidationsentence:when<boolean expression>isFALSEthe<stringofcharacters>
isprintedoutandactionsrelatedtospecifiedseveritylevelaredone.
[label:] assert <boolean expression>
p
Syntax:
y
[report <string of characters>]
[severity (note | warning | error |failure);
Examples:
p
assert not(addr < X"00001000" or addr > X"0000FFFF)
report Address in range" severity note;
assert (J /= C) report "J = C" severity note;
SequentialSentences:Report
Syntax:
Example:
4 .3
Sequentialvs.ConcurrentworldsinVHDL
VHDLsequentialsentences(insideaprocess,functionorprocedure)
Selectedsentences:
Selected sentences:
Variable&signalassignments
Wait
Ifthenelseendif
Case
Loop,ExitandNext
Assert,Functions&Procedures
ExamplesbasedVHDLlearning
49
50
(cont.)
4 .4
Previous comment
GeneralstructureofaVHDLmodel
entity X is
begin
end X;
architecture Y of X is
begin
onlyconcurrentsentences
onlysequentialsentences
end process;
end Y;
P2: p
process
52
CONTENTS
1.
1
2.
3.
4
4.
5.
6.
7
7.
4 .4
Maingoals&Expectedlearning
M
i
l &E
t dl
i
BasicsonVHDLlexical&syntax
VHDLDesignUnits
VHDL Sequential Sentences (selection)
VHDLSequentialSentences(selection)
VHDLConcurrentSentences(selection)
VHDLusageformodelling,simulationandsynthesis
Summary
53
4 .4
Alltheconcurrentsentencesarebeingevaluatedsimultaneously
Wherearepossible?
Entity(passivesentences)
Block(collectsconcurrentsentences)
Architecture
Whicharetheselectedsentences?
Process
Signal assignments
Signalassignments
DirectAssignment
ConditionalAssignment
SelectedAssignment
entity X is
begin
Concurrent sentences
end X;
architecture Y of X is
begin
B : block
begin
end block;
end Y;
Components
Generate
Eachconcurrentsentencewillbetranslatedtoitsequivalentprocessbeforeitssimulation
54
4 .4
Containssequentialsentencestodefineitsownbehaviour
Communicateswithotherprocessesandconcurrentsentencesbymeansofsignals
Theprocessisaninfiniteexecutionloopabletocontainstop/waitconditions(atleastONE!!)
Eachprocessissensibletoeventsonspecificsignalsorconditionstolaunchagainitsexecution
Syntax:
[<label>:] process [(<signal> ,{<signal>,
{<signal> ...})]
})] [is]
<local declarations>
begin
<sequential sentences>
end process [<label>];
process
begin
<sequential
i l sentences>
wait on <sensitivity signals list>;
end process;
55
4 .4
Syntax:
[label:] <signal> <= [delay_type] <expresion | waveform> {after <delay_time>};
Examples:
Tmp <= A xor B after 10 ns;
Z
<= Tmp xor Cin after 10 ns;
Cout <= (A and B) or (Tmp and Cin) after 15 ns;
Fullll
F
Adder
Cout
Waveform
W
W
driver
Cin
10
15
20
28
40
50
(ns)
0
10
20
30
40
50
60
70
56
4 .4
Syntax:
[<label>:] <signal> <= [delay_type]
{<expression|waveform> when <boolean expression> else}
< expression|waveform> [when <boolean expression>];
Example
S <= A when Sel = 0 else B;
process (Sel, A, B)
begin
if Sel = 0 then
S <= A;
else
S <= B;
end
d if;
if
end process;
4 .4
Syntax:
[<label>] with <expression> select
<signal> <= [delay_type]
{<expression|waveform> when <value>,}
<
<expression|waveform>
i |
f
> when
h
< l >
<value>;
Example
with Operation select
Result <= Op1 + Op2
Op1 - Op2
O 1 and
Op1
d Op2
O 2
Op1 or Or2
when
when
when
h
when
add,
subs,
andL,
d
orL;
Equivalent
Process
Type opcode is (add, subs, andL, orL);
Signal operation : opcode;
58
4 .4
ConcurrentSentences:Components
Structuralandhierarchicaldescriptionsbyusingcomponentsdefinedsomewhereelse.
Syntaxforcomponentdeclaration: component <idname> [is]
[generic (<generic parameters list>);]
[port (<ports list>);]
end [component] [<idname>];
Syntaxforcomponentreferenceorinstantiation:
<label>: <idname>
[generic map (<parameters association list>);]
[port map (<ports association list>);]
Examples:
component example is
port(a,
t(
b c : in
b,
i bit;
bit
d : out bit);
end component example;
4 .4
U1
X
Y
Half
Adder
U3
A
B
Half
Adder
OrG
COut
Sum
U2
I1
0
0
1
1
I2
0
1
0
1
Sum Cout
0
0
1
0
1
0
0
1
Nominalassociationlist
60
4 .4
ConcurrentSentences:Generate
Generallyusedtocreatearraysofcomponentinstances,butitcouldincludeanyother
concurrentsentence. <label>: {[for <range specification> | if <condition> ]}
generate
Syntax:
{<concurrent sentences>}
end generate;
Example:
E(N-1)
E(N-2)
DFF
DFF
Clk
S(N-1)
E(0)
DFF
S(N-2)
S(0)
entity Register is
Parallelin/out
generic (N: positive);
NbitsRegister
port( Clk : in std_logic;
E
: in std_logic_vector(N-1 downto 0);
S
out std_logic_vector(N
std logic vector(N-1
1 downto 0));
end Register;
architecture structural of Register is
component DFF
port (Clk : in std_logic;
E
: in
i std_logic;
td l i
S
: out std_logic);
end component;
variable I : integer;
begin
GenReg: for I in N-1 downto 0 generate
Reg: DFF port map(Clk, E(I), S(I));
end generate;
61
end structural;
4 .4
ConcurrentSentences:Assert,Procedurecalland Functioncall
Sameusageandbehaviourastheequivalentsequentialones,butintheconcurrentworld.
[label:] assert <boolean expression>
[report <string of characters>]
[severity (note | warning | error |failure);
ConcurrentProcedurecallisjustlikeaprocesswithprocedureparametersinthesensitivity
list
list.
[label:] <Procedure name> [(<parameters>)];
Check_Timing(min_time, max_time, clk, sig_to_test, testOK);
F ti
Functioncallcouldbeembeddedinanyexpressioninsideaconcurrentstatement.
ll
ld b
b dd d i
i i id
t t t
t
function Check_Timing(min_time, max_time, clk, sig_to_test) returns boolean;
62
4 .4
4 .4
4 .4
entity ParallelAdder is
generic (n : natural := 4);
g
port ( X, Y : in std_logic_vector(n-1 downto 0);
Cin : in std_logic;
Z : out std_logic_vector(n-1 downto 0);
Cout : out std_logic);
End ParallelAdder ;
achitecture Functional of ParallelAdder is
Begin
process (X, Y, Cin);
variable
i bl C : std_logic_vector(n
d l i
( downto
d
t 0);
0)
variable tmp : std_logic;
variable I : integer;
begin
C(0) := Cin;
for I in 0 to n-1 loop
tmp
:= X(I) xor Y(I);
Z(I)
<= tmp xor C(I);
C(I+1) := (tmp and C(I)) or (X(I) and Y(I));
end loop;
Cout <= C(n);
end process;
end Functional;
65
4 .4
entity ParallelAdder is
generic (n : natural := 4);
g
port ( X, Y : in std_logic_vector(n-1 downto 0);
Cin : in std_logic;
Z : out std_logic_vector(n-1 downto 0);
Cout : out std_logic);
End ParallelAdder ;
Logic Simulation
4 .4
VHDLconcurrentsentences(insideanarchitecture,blockorentity)
Selectedsentences:
Process
signalassignments(uncond &cond.)
Components
Generate
Assert
Functions&Procedures
VHDLmodelling,simulation&synthesis:basicconceptsandflows
VHDL E
VHDLExamplesbasedlearning
l b dl
i
ThisendsourshortintroductiontoVHDLlanguageforitsusageinthecurrent
g g
g
DigitalSystemsCourse
67
68
4 .2
VHDLDataTypes
TheVHDLisastronglytypedlanguage
Adatatypedefinesasetoffixedandstaticvalues
Anylanguageobjectbelongstoaspecificdatatype
Objectvaluesshallbelongtorelateddatatype
Newdatatypescouldbeuserdefined
Result
is real;
type
type mark is range 10.0 downto 0.0;
...
type Price is integer;
type Month is range 1 to 12;
...
type Cardinal is (North, South, East, West);
t
type
C dK
CardKeys
i (N,
is
(N S,
S E,
E W)
W);
type Mixed is (N, South, East, W);
...
variable Direction : Cardinal := West;
variable Var : Mixed;
Signal Key : CardKeys := N;
...
Var := N; -- Var & Key cannot be assigned to each other as
Key <= E; -- they doesnt belongs to the same data type
69
4 .2
Foreachcomponentinaspecificarchitectureselectsthemodule(entity+
architecturetobemappedonit
Example:
TTL
CMOS
4 .3
Immediate replacementofvariablevalue.
Syntax:
[label:] <variable name> := <expression>;
Nonequivalentsequences:
Examples:
A := B;
B := A;
B := A;
A := B;
Var := 0;
V t
Vector
:= 00011100
00011100;
string := Message is: ;
A := B;
B := my_function(3,databus)
C := my_function(4,adrbus) + A;
71
4 .3
Indicatesthepointwhereaprocessexecutionshallbesuspended,aswellasthe
Indicates
the point where a process execution shall be suspended as well as the
conditionsforitsreactivation.Morethanonewaitsentenceperprocessispossible.
Syntax:
Basicexamples:
process
begin
<sequential sentences>
wait;
end process;
Withoutreactivationcondition
process
begin
c <= a and b;
wait on a, b;
end process;
Sensibletoeventsonsignalsab
process
b i
begin
Clock <= not Clock;
wait for 10 ns;
end process;
Suspendsandfixesatimeforreactivation10ns
process
begin
q <= d;
wait until Clock = 1;
end process;
Sensibletoeventsonsignals&condition=True
Otherpossibilities
wait on a,b until c=1;
72
4 .3
SelectsthegroupofsentencestoexecutedependingonaBooleancondition.
Syntax:
[label:] if <condicion> then
<sentencias secuenciales>
{elsif <condicion> then
<sentencias secuenciales}
[else
<sentencias secuenciales>]
end if [
[label];
]
Examples:
Latch: process begin
if load =1 then
Q <= D;
end if;
wait on load, D;
end process;
Latch
Buffer Triestate
process
begin
if Enable =1 then
Salida <= Entrada;
else
Salida <= Z;
end if;
wait on Enable, Entrada;
end process;
if Ctrl = 0 then
Q <= A;
else
e
se
Q <= B;
end if;
Mux
73
4 .3
AnotherexampletocombineIf&Case
sentencesinasingleProcess.
LatMux
A
B
C
D
Ctrl
Load
entity LatMux is
port(
Load
: in
A, B, C, D : in
Ctrl
: in
Y
end LatMux;
bit;
bit;
bit_vector(0 to 1);
: out bit);
74
4 .3
Sequentialsentencesintheloopregionarerepeatedforanumberoftimes.
Typesofloops:while,forandwithoutiterationscontrol(infiniteloop).
Syntax: [[label:]
abe :] [
[while
e <boolean
boo ea _co
condition>
d t o
| for
o <repetition
epet t o _co
control>]
t o ]
loop
<sequential sentences>}
end loop [label];
Examples:countermod16
process
begin
Cont <= 0;
loop
wait until Clock=1;
Cont <= (Cont + 1) mod 16;
end loop;
end process;
Withoutiterationscontrol(infiniteloop)
Process
var I : integer;
begin
Cont <= 0;
for I in 0 to 15 loop
wait until Clock=1;
Cont <= Cont + 1;
end loop;
wait until Clock=1;
end process;
Forcontrolledloop
process
begin
Cont <= 0;
wait until Clock=1;
while Cont < 15 loop
Cont <= Cont + 1;
wait until Clock=1
end loop;
end process;
Whilecontrolledloop
75
4 .3
Countermodule16with
asynchronousreset
Countermodule16
entity Counter16 is
whichavoidsvalue8
port(
Clock, Rst : in bit;
Count
Cou
t : out natural);
atu a );
end Counter16;
architecture functional of Counter16 is
variable C : natural;
variable I : integer;
begin
process
begin
C := 0;
for I in 0 to 15 loop
next when I=8;
C := I;
wait until Clock=1;
end loop;
p;
end process;
Count <= C;
end functional;
76
4 .4
ConcurrentSentences:Generate
Example:
entity ShiftReg is
NbitsShift register
generic (N: positive);
port( Clk, SIn : in bit ;
SOut
: out bit);
end ShiftReg;
X(0)
X(N 2)
X(N-2)
SIn
SOut
architecture structural of ShiftReg is
component DFF
DFF
DFF
DFF
port (Clk, E : in bit;
S
: out bit);
end component;
Clk
signal X : bit_vector(0 to N-2);
variable I : integer;
begin
GenShReg:
g for I in 0 to N-1 g
generate
G1 : if (I=0) generate
CIzq: DFF port map(Clk, SIn, X(I)); end generate;
G2 : if (I>0) and (I<N-1) generate
CCen: DFF port map(Clk, X(I-1), X(I)); end generate;
G3 : if (I=N-1)
(I=N 1) generate
CDer: DFF port map(Clk, X(I-1), SOut); end generate;
end generate;
77
end structural;
Example:
4 .4
entity
y ParallelAdder is
N bits Parallel Adder
NbitsParallelAdder
generic (n : natural),
port ( X, Y : in bit_vector(n-1 downto 0);
Cin : in bit;
Z
: out bit_vector(n-1 downto 0);
Cout : out bit);
End ParallelAdder;
architecture structural of parallelAdder is
component FA
Xn-1 Yn-1
Xn-2 Yn-2
X0 Y0
port ( A, B, Ci : in bit;
Cout=Cn
C0=Ci
Ci
Cn-1
C1
S C
S,
Co
: out
t bit);
bit)
n
end component;
FA
FA
FA
signal C : bit_vector(n downto 0);
variable I : integer;
begin
Zn-1
Zn-2
Z0
GenShReg: for I in 0 to N-1 generate
G1 : if (I=0) generate
LSB: FA port map(X(I), Y(I), Cin, Z(I), C(I+1)); end generate;
G2 : if (I>0) and (I<N-1) generate
OtherB: FA port map(X(I), Y(I), C(I), Z(I), C(I+1)); end generate;
G3 : if (I=N-1) generate
MSB: FA port map(X(I), Y(I), C(I), Z(I), Cout); end generate;
end generate;
78
end structural;
Example:
entity ParallelAdder is
generic (n : natural),
port ( X, Y : in bit_vector(n-1 downto 0);
Cin : in bit;
Z
: out bit_vector(n
bit vector(n-1
1 downto 0);
Cout : out bit);
End ParallelAdder;
4 .4
NbitsParallelAdder
X0 Y0
C0=Cin
C1
FA
Z0
79
4 .4
VHDL
Source code
VHDL Analyser
Sea of processes
VHDL
Simulator
4 .4
VHDL Simulation
VHDLEventDrivenSimulationCycle
y
Updating
Signals & Time
Processes
Execution
Which processes
shall be resumed?
?
y/n
...
Initialize
Signals
Drivers
Signals
Initialization
d
delay
STOP
y/n
Process-n
Process-1
y/n
Process-2
y/n
Update signals
drivers
5 Time
81
4 .4
VHDLconcurrentsentences(insideanarchitecture,blockorentity)
Selectedsentences:
signalassignments
Conditionedsignalassignments
Process
Components
Generate
Assert,Functions&Procedures
VHDLmodelling,simulation&synthesis:basicconceptsandflows
VHDL
VHDLeventdrivensimulationofprocessesoceans
td i
i l ti
f
Simulationcycle
delayversussimulationtime
VHDLExamplesbasedlearning
ThisendsourshortintroductiontoVHDLlanguageforitsusageinthecurrent
DigitalSystemsCourse
82