Professional Documents
Culture Documents
Introduction
Very High Speed Integrated Circuit Hardware Description Language (VHDL)
Project in Mid 1908s by US Dept of defence & IEEE To develop platform for design and development of high speed and complex (large no. of gates) Ics Other competitors Verilog (also popular) and ABEL (no so popular) HDL are meant to emulate behavior of digital circuit real time Allows both (concurrent and sequential execution of statements) along with timing specifications (gate delays)
2 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Abstraction is hiding of details: Differentiation between essential and nonessential information Creation of abstraction levels: On every abstraction level only the essential information is considered, nonessential information is left out
VHDL allows one to describe a digital system at the structural or the behavioral level
Behavior model : functional description of the module is outlined at the behavioral level RTL: design is divided into combinational logic and storage elements with storage elements controlled by a system clock Logic - design is represented as a netlist with logic gates (AND, OR, NOT,) and storage elements Layout - different cells of target technology are placed on the chip and the connections are routed
Structural or Gate level- list of the gates (components) that are used in the design
Behavioral description
Behavioral is highest level of abstraction Describes a system in terms of what it does or how it behaves Specifies relation between input and output signals Behavioral description is abstract
Behavioral descriptions can be Data flow and Algorithmic Dataflow representation describes how data moves through the system Eg data flow between registers (Register Transfer level or RTL) Data flow model uses concurrent statements executed in parallel as soon as data arrives at the input
eg XOR gate : S = AB Eg Car passenger Buzzer: Warning = Ignition_on AND ( Door_open OR Seatbelt_off)
10
Structural
Describes system as collection of gates and components interconnected to perform a function Similar to schematic of interconnected logic gates
Structural representation of a buzzer circuit
11
12
13
Entity declaration
Entity declaration defines the NAME of the entity and lists the input and output ports
entity NAME_OF_ENTITY is [ generic generic declarations);] port (signal_names: mode type; signal_names: mode type; : Signal type signal_names: mode type); end [NAME_OF_ENTITY] ; -- comments: example of the buzzer circuit entity BUZZER is port (DOOR, IGNITION, SBELT: in std_logic; WARNING: out std_logic); end BUZZER;
14
Entity description
The NAME_OF_ENTITY is a user-selected identifier signal names consists of a comma separated list of one or more user-selected identifiers that specify external interface signals. mode: is one of the reserved words to indicate the signal direction: 1. in indicates that the signal is an input 2. out indicates that the signal is an output of the entity whose value can only be read by other entities that use it. 3. buffer indicates that the signal is an output of the entity whose value can be read inside the entitys architecture 4. inout the signal can be an input or an output.
type: a built-in or user-defined signal type. The type defines the set of values an object can have. Examples of types are bit, bit_vector, Boolean, character, std_logic, and std_ulogic. 1. bit can have the value 0 and 1 2. bit_vector is a vector of bit values (e.g. bit_vector (0 to 7) 3. std_logic, std_ulogic, std_logic_vector, std_ulogic_vector: can have 9 values to indicate the value and strength of a signal. Std_ulogic and std_logic are preferred over the bit or bit_vector types. 4. boolean can have the value TRUE and FALSE 5. integer can have a range of integer values 6. real can have a range of real values 7. character any printing character 8. time to indicate time
EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
15
16
The type defines the set of values an object can have std_logic type is defined in the std_logic_1164 package of the IEEE library
EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Architecture body
Specifies how the circuit operates and how it is implemented Entity or circuit can be specified in a variety of ways, such as behavioral, structural (interconnected components), or a combination of the above Architecture body
architecture architecture_name of NAME_OF_ENTITY is -- Declarations -- components declarations -- signal declarations -- constant declarations -- function declarations -- procedure declarations -- type declarations
: begin -- Statements : end architecture_name;
EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
17
Behavioral model
Behavioral model of Buzzer circuit
architecture behavioral_Buzz of BUZZER is main body of the architecture starts begin WARNING <= (not DOOR and IGNITION) or (not SBELT and IGNITION); end behavioral;
Boolean expression of the function <= assignment operator, assign value of expression on the right to signal on left Architecture behavioral is associated with entity, BUZZER
-- An example of a two-input XNOR gate (entity + architecture) entity XNOR2 is port (A, B: in std_logic; Z: out std_logic); end XNOR2; architecture behavioral_xnor of XNOR2 is -- signal declaration (of internal signals X, Y) Signal assignment statements in architecture body uses signal X, Y: std_logic; operators (eg and, or, not, <= etc..) and are concurrent begin Concurrent statements: Eg if A changes, signals X and Y X <= A and B; Y <= (not A) and (not B); change values that in turn causes the last statement to update Z <= X or Y; the output Z End behavioral_xnor;
18
Digital systems are data-driven (data flow) and an event/change which occurs on one signal will lead to an event on another signal Order in which these statements are given does not matter Contrast this to conventional, software programs that execute EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkeeflow statements in a sequential
Structural description
Describes the system as set of gates appropriately interconnected
architecture structural of BUZZER is Buzzer entity declaration same earlier -- Declarations component AND2 declarative part that gives port (in1, in2: in std_logic; the components (gates) out1: out std_logic); that are going to be used end component; component OR2 port (in1, in2: in std_logic; Schematic out1: out std_logic); end component; component NOT1 port (in1: in std_logic; out1: out std_logic); end component; -- declaration of signals used to interconnect gates Concurrent statements signal DOOR_NOT, SBELT_NOT, B1, B2: std_logic; An alternative way to define net list using explicit association between the ports begin executed in parallel and -- Component instantiations statements and how they are connected order does not hence U0: NOT1 port map (DOOR, DOOR_NOT); label: component-name port map (port1=>signal1, port2=> signal2, port3=>signaln); matter Key word port map defines how the U1: NOT1 port map (SBELT, SBELT_NOT); components are connected U2: AND2 port map (IGNITION, DOOR_NOT, B1); U0: NOT1 port map (in1 => DOOR, out1 => DOOR_NOT); U3: AND2 port map (IGNITION, SBELT_NOT, B2); U1: NOT1port map (B1, B2, WARNING); out1 => SBELT_NOT); U4: OR2 port map (in1 => SBELT,
U2: AND2 port map (in1 => IGNITION, in2 => DOOR_NOT, out1 => B1); U3:end structural; (in1 => IGNITION, in2 => SBELT_NOT, B2); AND2 port map U4: OR2 port map (in1 => B1, in2 => B2, out1 => WARNING);
19 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Library and use clause defined a component for the full adder
20
21
signal c: std_logic_vector (4 downto 0); component FULLADDER port(a, b, c: in std_logic; sum, carry: out std_logic); end component; begin FA0: FULLADDER port map (a(0), b(0), Cin, sum(0), c(1)); FA1: FULLADDER port map (a(1), b(1), C(1), sum(1), c(2)); FA2: FULLADDER port map (a(2), b(2), C(2), sum(2), c(3)); FA3: FULLADDER port map (a(3), b(3), C(3), sum(3), c(4)); V <= c(3) xor c(4); Cout <= c(4); end fouradder_structure; EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Library and use clause defined a component for the full adder Four instantiations of the full adder to build the structure of the 4bit adder
Lexical Elements
Identifiers - are user-defined words used to name objects in VHDL models
May contain only alpha-numeric characters (A to Z, a to z, 0-9) and the underscore (_) character The first character must be a letter and the last one cannot be an underscore. An identifier cannot include two consecutive underscores. An identifier is case insensitive (ex. And2 and AND2 or and2 refer to the same object) An identifier can be of any length. Valid identifer: X10, x_10, My_gate1 Some invalid identifiers are: _X10, my_gate@input, gate-input.
o113
22 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
A value of a given type and cannot be changed during the simulation constant list_of_name_of_constant: type [ := initial value] ; constant RISE_FALL_TME: time := 2 ns;
Variable: single value which can be updated by assignment statement in architecture or process variable list_of_variable_names: type [ := initial value] ; variable VAR1: boolean :=FALSE; variable STS_BIT: bit_vector (7 downto 0); variable SUM: integer range 0 to 256 :=16; updated using a variable assignment statement : Variable_name := expression;
signal list_of_signal_names: type [ := initial value] ; signal SUM, CARRY: std_logic; signal DATA_BUS: bit_vector (0 to 7); Updated when their signal assignment statement : SUM <= (A xor B) after 2 ns; multiple values : wavefrm <= 0, 1 after 5ns, 0 after 10ns, 1 after 20 ns;
Signal change a delay when assignment expression is evaluated, if no delay is specified, the
signal will change after a delta (a unit delay time) delay
23
Data types
Each data object has type associated with it VHDL strongly typed - requires each object to be of a certain type Four classes of data types: scalar, composite, access and file types Scalar type includes integer, real, and enumerated types of Boolean and Character
24
25
26
Record Type A record consists of multiple elements that may be of different types. Syntax type name is record identifier :subtype_indication; : identifier :subtype_indication; end record;
Eg type MY_MODULE is record RISE_TIME :time; FALL_TIME : time; SIZE : integer range 0 to 200; DATA : bit_vector (15 downto 0); end record; signal A, B: MY_MODULE A.RISE_TIME <= 5ns; A.SIZE <= 120; 27 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Type conversion
Since VHDL is strongly typed language - To allow assigning data between objects of different types, one needs to convert one type to the other
Syntax type_name (expression); entity QUAD_NAND2 is port (A, B: in bit_vector(3 downto 0); out4: out std_logic_vector (3 downto 0)); end QUAD_NAND2; architecture behavioral_2 of QUAD_NAND2 is begin out4 <= to_StdLogicVector(A and B); end behavioral_2;
Conversions supported by std_logic_1164 package Conversion Function std_ulogic to bit to_bit(expression) std_logic_vector to bit_vector to_bitvector(expression) std_ulogic_vector to bit_vector to_bitvector(expression) bit to std_ulogic To_StdULogic(expression) bit_vector to std_logic_vector To_StdLogicVector(expression) bit_vector to std_ulogic_vector To_StdUlogicVector(expression) std_ulogic to std_logic_vector To_StdLogicVector(expression) std_logic to std_ulogic_vector To_StdUlogicVector(expression) 28 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Attributes
Used to return various types of information about signal, variable or type Consist of quote mark () followed by attribute name
Signal attributes
Attribute signal_nameevent signal_nameactive Function returns the Boolean value True if an event on the signal occurred, otherwise gives a False returns the Boolean value True there has been a transaction (assignment) on the signal, otherwise gives a False returns a signal of the type bit that toggles (0 to 1 or 1 to 0) every time there is a transaction on the signal. returns the time interval since the last event on the signal returns the time interval since the last transaction on the signal gives the value of the signal before the last event occurred on the signal gives a signal that is the delayed version (by time T) of the original one. [T is optional, default T=0] returns a Boolean value, True, if no event has occurred on the signal during the interval T, otherwise returns a False. [T is optional, default T=0] returns a Boolean value, True, if no transaction has occurred on the signal during the interval T, otherwise returns a False. [T is optional, default T=0]
Example signal attribute if (CLOCKevent and CLOCK=1) then Others: Scalar attributes Array attributes
signal_nametransaction
signal_namelast_event
signal_namelast_active
signal_namelast_value signal_namedelayed(T) signal_namestable(T)
signal_namequiet(T)
29
Operators
VHDL supported operators that operate on signals, variables and constants
Class
1. Logical operators and or /= srl = / abs mod not rem nand < sla & nor <= sra xor > rol xnor >= ror
2. Relational operators = 3. Shift operators 4.Addition operators 5. Unary operators 6. Multiplying op. 7. Miscellaneous op. sll + + * **
30
Logic operators
Operate on bit, boolean, std_logic and std_ulogic types and their vectors Define Boolean logic expression or to perform bit-bybit operations on arrays of bits nand and nor operators are not associative X nand Y nand Z will give a syntax error and should be written as (X nand Y) nand Z.
31
Shift operators
Perform a bit-wise shift or rotate operation on a one-dimensional array of elements of the type bit (or std_logic) or Boolean Result Type
Same as left type
variable A: bit_vector :=101001; A sll 2 A srl 2 A sla 2 A sra 2 A rol 2 A ror 2 results in results in results in results in results in results in 100100 001010 100111 111010 100110 011010
srl
Shift right logical (fill left vacated bits with 0) Shift left arithmetic (fill right vacated bits with rightmost bit) Shift right arithmetic (fill left vacated bits with leftmost bit)
sla
same as above
sra
same as above
rol
ror
same as above
same as above
32
Addition operators
Perform arithmetic operation (addition and subtraction) on operands of any numeric type To use these operators specify the ieee.std_logic_unsigned.all or std_logic_arith package package in addition to the ieee.std_logic_1164 package in VHDL code Description
Addition Subtraction Concatenation
Operator
+ &
Result Type
Same type Same type Same array type
Numeric type Same as left operand Numeric type Same as left operand Array or element type Same as left operand
33
Unary operators
+ and - are used to specify the sign of a numeric type
Operator + -
Operand Type Result Type Any numeric type Same type Any numeric type Same type
34
Multiplying operators
perform mathematical functions on integer or floating point Operator Descriptio Left Operand n Type
* Multiplicatio n Any integer or floating point Any physical type Any integer or real type / Division Any integer or floating point Any physical type Any physical type mod rem Modulus Remainder Any integer type Any integer type
11 rem 4 (-11) rem 4 9 mod 4 7 mod (-4)
Result Type
Same type Same as left Same as right Same type Same as left Integer Same type Same type
A rem B = A (A/B)*B (in which A/B in an integer) A mod B = A B * N (in which N is an integer)
35
Miscellaneous operators
Absolute value and exponentation operators that can be applied to numeric types Description Left Operand Type
Integer type
Operator
**
Exponentiation
abs
not
Absolute value
Logical negation
Same type
Same type
36
Relational operators
Test the relative values of two scalar types and give as result a Boolean output of TRUE or FALSE.
Operator
= /= < <= > >=
Description
Equality Inequality Smaller than Smaller than or equal Greater than Greater than or equal
Operand Types
Result Type
any type Boolean any type Boolean scalar or discrete array types Boolean scalar or discrete array types Boolean scalar or discrete array types Boolean scalar or discrete array types Boolean
variable STS : Boolean; constant A : integer :=24; constant B_COUNT : integer :=32; constant C : integer :=14; STS <= (A < B_COUNT) ; -- will assign the value TRUE to STS STS <= ((A >= B_COUNT) or (A > C)); -- will result in TRUE STS <= (std_logic (1, 0, 1) < std_logic(0, 1,1));--makes STS FALSE
37 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
Process reads and writes signals and values of input and output ports (CLK, CLEAR, D) to communicate with the rest of the architecture
39
Half adder S_ha = (AB) and C_ha = AB For the Full Adder Sum = (AB)Cin = S_ha Cin Cout = (AB)Cin + AB = S_ha.Cin + C_ha
41
if statement
Executes a sequence of statements whose sequence depends on one or more conditions
Example 4x1 Multiplexer entity MUX_4_1a is port (S1, S0, A, B, C, D: in std_logic; Z: out std_logic); end MUX_4_1a; architecture behav_MUX41a of MUX_4_1a is begin P1: process (S1, S0, A, B, C, D) if S1=0 and S0=0 then Z <= A; elsif S1=0 and S0=1 then Z <= B; elsif S1=1 and S0=0 then Z <= C; elsif S1=1 and S0=1 then Z <= D; end if;
if condition then sequential statements [elsif condition then sequential statements ] [else sequential statements ] end if;
42
case statement
Depending on value of a single expression case statement executes one of several sequences of statements
Example 4x1 MUX case expression is when choices => entity MUX_4_1 is sequential statements port ( SEL: in std_logic_vector(2 downto 1); when choices => A, B, C, D: in std_logic; sequential statements Z: out std_logic); -- branches are allowed end MUX_4_1; [when others => sequential statements] architecture behav_MUX41 of MUX_4_1 is end case;
Expression must evaluate to an integer, an enumerated type of a one-dimensional array, such as a bit_vector No two choices can overlap if the when others" choice is not present, all possible values of the expression must be covered by the set of choices.
begin PR_MUX: process (SEL, begin case SEL is when 00 => Z when 01 => Z when 10 => Z when 11 => Z when others => end case; end process PR_MUX; end behav_MUX41;
A, B, C, D)
43
loop statements
Repeatedly execute a sequence of sequential statements Three types of loops
basic loop while loop for loop
[loop_label :]iteration_scheme loop sequential statements [next [label] [when condition]; [exit [label] [when condition]; end loop [loop_label];
44
entity COUNT31 is port ( CLK: in std_logic; COUNT: out integer); end COUNT31; architecture behav_COUNT of COUNT31 is begin P_COUNT: process variable intern_value: integer :=0; begin COUNT <= intern_value; loop wait until CLK=1; intern_value:=(intern_value + 1) mod 32; COUNT <= intern_value; end loop; end process P_COUNT; end behav_COUNT;
For loop uses an integer iteration scheme that determines the number of iterations
[ loop_label :] for identifier in range loop sequential statements [next [label] [when condition]; [exit [label] [when condition]; end loop[ loop_label ]; Where range in one of the following forms: integer_expression to integer_expression integer_expression downto integer_expression
45
CLK=1; wait statement can not have a CLK=0; sensitivity list CLKevent and CLK=1; not CLKstable and CLK=1;
Null statement - no action will occur Useful in a case statement where all choices must be covered
P_WAIT: process (CNTL) begin Z <=A; case CNTL is when 3 | 15 => Z <= A xor B; when others => null; end case; end process P_WAIT;
46
47
48
entity MUX_4_1_funcTab is port (A, B, C, D: in std_logic; SEL: in std_logic_vector (1 downto 0); Z: out std_logic); end MUX_4_1_ funcTab; architecture concurr_MUX41 of MUX_4_1_ funcTab is begin Z <= A when SEL = 00 else B when SEL = 01 else C when SEL = 10 else D; end concurr_MUX41;
49
50
Structural Modeling
Describes a circuit in terms of components and their interconnection kind of schematic description A component is assumed to defined earlier (e.g. in package) and can be described as structural, a behavioral or dataflow model Lowest hierarchy in each component described as a behavioral model, using the basic logic operators defined in VHDL Structural modeling good to describe complex digital systems, through a set of components in a hierarchical fashion Structural description consists of
Declaring components and signals within architecture body Declaring a list of components being used Declaring signals which define the nets that interconnect components
Labeling multiple instances of the same component so that each instance is uniquely defined
51
Structure description
Component declaration has to be done either in the architecture body or in the package declaration General syntax
architecture architecture_name of NAME_OF_ENTITY is -- Declarations component declarations signal declarations begin -- Statements component instantiation and connections : end architecture_name; Component name refers to either name of entity defined in library or entity explicitly defined in the Component declaration VHDL file component component_name [is] Interface ports similar to entity declaration [port (port_signal_names: mode type; Use library and use clause for components port_signal_names: mode type; declared in package library : port_signal_names: mode type);] -- example fulladder end component [component_name]; component FULLADDER port(a, b, c: in std_logic; sum, carry: out std_logic); end component;
52 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee
53
sum
carry FULLA DDER c
Structural description of 4 bit adder as hierarchical model with FULLADDER component instantiations
Behavioral description of full adder in dataflow model (concurrent statements) Defined already
54
Further reading
http://esd.cs.ucr.edu/labs/tutorial/ http://www.vhdl-online.de/tutorial/ http://www.seas.upenn.edu/~ese171/vhdl/vhd l_primer.html A VHDL PRIMER By J BHASKAR, Pearson India www.xilinx.com Digital design by Wakerly 4th ed, Pearson India
55 EC242, Dr. SanjeeV Manhas, E&CE IIT Roorkee