LANGUAGE VHDL FUNDAMENTALS

Similar documents
Digital Design Using VHDL Using Xilinx s Tool for Synthesis and ModelSim for Verification Part II

Contents. Appendix D VHDL Summary Page 1 of 23

Inthis lecture we will cover the following material:

Digitaalsüsteemide disain

Lecture 1: VHDL Quick Start. Digital Systems Design. Fall 10, Dec 17 Lecture 1 1

Introduction to VHDL. Main language concepts

BASIC VHDL LANGUAGE ELEMENTS AND SEMANTICS. Lecture 7 & 8 Dr. Tayab Din Memon

Basic Language Constructs of VHDL

What Is VHDL? VHSIC (Very High Speed Integrated Circuit) Hardware Description Language IEEE 1076 standard (1987, 1993)

Digital Systems Design

Advanced Training Course on FPGA Design and VHDL for Hardware Simulation and Synthesis. 26 October - 20 November, 2009

310/ ICTP-INFN Advanced Tranining Course on FPGA and VHDL for Hardware Simulation and Synthesis 27 November - 22 December 2006

EEL 4783: Hardware/Software Co-design with FPGAs

ENGIN 241 Digital Systems with Lab

Hardware Description Language VHDL (1) Introduction

Data types defined in the standard package

Introduction to the VHDL language. VLSI Digital Design

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

Design units can NOT be split across different files

DESCRIPTION OF DIGITAL CIRCUITS USING VHDL

Digital Systems Design

Review of Digital Design with VHDL

Introduction to VHDL #1

CSCI Lab 3. VHDL Syntax. Due: Tuesday, week6 Submit to: \\fs2\csci250\lab-3\

C-Based Hardware Design

Lecture 3 Introduction to VHDL

Introduction to VHDL

Synthesis from VHDL. Krzysztof Kuchcinski Department of Computer Science Lund Institute of Technology Sweden

Concurrent Signal Assignment Statements (CSAs)

Very High Speed Integrated Circuit Har dware Description Language

Outline CPE 626. Advanced VLSI Design. Lecture 4: VHDL Recapitulation (Part 2) Signals. Variables. Constants. Variables vs.

Logic and Computer Design Fundamentals VHDL. Part 1 Chapter 4 Basics and Constructs

VHDL. ELEC 418 Advanced Digital Systems Dr. Ron Hayne. Images Courtesy of Cengage Learning

Lecture 4. VHDL Fundamentals. George Mason University

ECE 545 Lecture 4. Simple Testbenches. George Mason University

DOD, VHSIC ~1986, IEEE stnd 1987 Widely used (competition Verilog) Commercial VHDL Simulators, Synthesizers, Analyzers,etc Student texts with CDROMs

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

Hardware Description Languages. Modeling Complex Systems

!"#$%&&"'(')"*+"%,%-".#"'/"'.001$$"

Modeling Complex Behavior

Lecture 4. VHDL Fundamentals. Required reading. Example: NAND Gate. Design Entity. Example VHDL Code. Design Entity

5. 0 VHDL OPERATORS. The above classes are arranged in increasing priority when parentheses are not used.

CDA 4253 FPGA System Design VHDL Testbench Development. Hao Zheng Comp. Sci & Eng USF

Digital Systems Design

Chapter 6 Combinational-Circuit Building Blocks

ECE U530 Digital Hardware Synthesis. Course Accounts and Tools

COE 405 Design Methodology Based on VHDL

VHDL BASIC ELEMENTS INTRODUCTION

Review. LIBRARY list of library names; USE library.package.object; ENTITY entity_name IS generic declarations PORT ( signal_name(s): mode signal_type;

ECOM4311 Digital Systems Design

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

5. VHDL - Introduction - 5. VHDL - Design flow - 5. VHDL - Entities and Architectures (1) - 5. VHDL - Entities and Architectures (2) -

Combinational Logic COMB. LOGIC BLOCK. A Combinational Logic Block is one where the outputs depend only on the current inputs

Menu. Introduction to VHDL EEL3701 EEL3701. Intro to VHDL

Subprograms, Packages, and Libraries

Embedded Systems CS - ES

CDA 4253 FPGA System Design Introduction to VHDL. Hao Zheng Dept of Comp Sci & Eng USF

Basic Language Concepts

VHDL: skaitmeninių įtaisų projektavimo kalba. 2 paskaita Pradmenys

Outline. CPE/EE 422/522 Advanced Logic Design L07. Review: JK Flip-Flop Model. Review: VHDL Program Structure. Review: VHDL Models for a MUX

VHDL. Official Definition: VHSIC Hardware Description Language VHISC Very High Speed Integrated Circuit

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 4 Introduction to VHDL

VHDL for Complex Designs

VHDL Structural Modeling II

Multi-valued Logic. Standard Logic IEEE 1164 Type std_ulogic is ( U, uninitialized

[1] Douglas L. Perry, VHDL, third edition, ISBN , McRaw- Hill Series on Computer Engineering.

VHDL is a hardware description language. The code describes the behavior or structure of an electronic circuit.

VHDL Part 2. What is on the agenda? Basic VHDL Constructs. Examples. Data types Objects Packages and libraries Attributes Predefined operators

CPE/EE 422/522. Chapter 8 - Additional Topics in VHDL. Dr. Rhonda Kay Gaede UAH. 8.1 Attributes - Signal Attributes that return a value

CprE 583 Reconfigurable Computing

Lecture 4. VHDL Basics. Simple Testbenches

ECOM 4311 Digital System Design using VHDL. Chapter 7

VHDL And Synthesis Review

JUNE, JULY 2013 Fundamentals of HDL (10EC45) PART A

UNIT I Introduction to VHDL VHDL: - V -VHSIC, H - Hardware, D - Description, L Language Fundamental section of a basic VHDL code Library :

The University of Alabama in Huntsville ECE Department CPE Midterm Exam February 26, 2003

VHDL. Chapter 7. Behavioral Modeling. Outline. Behavioral Modeling. Process Statement

Lecture 38 VHDL Description: Addition of Two [5 5] Matrices

ECE 545 Lecture 5. Data Flow Modeling in VHDL. George Mason University

The process. Sensitivity lists

Review. VHDL in Action. This week. Lexical Elements. Literals. More Literals. Concurrent statements Conditional and selected signal assignments

Programmable Logic Design Grzegorz Budzyń Lecture. 4: Introduction to VHDL

Lecture 7. Standard ICs FPGA (Field Programmable Gate Array) VHDL (Very-high-speed integrated circuits. Hardware Description Language)

VHDL Instant. Table of contents. History

ECEU530. Homework 2. ECE U530 Digital Hardware Synthesis. Homework 2: Waveforms. Debugging VHDL

1. Using the for-generahon scheme, concurrent statements can be replicated a predetermined number of times.

Declarations of Components and Entities are similar Components are virtual design entities entity OR_3 is

VHDL: A Crash Course

Summary of basic structures

ECOM 4311 Digital Systems Design

Lecture 10 Subprograms & Overloading

Hardware Modeling. VHDL Syntax. Vienna University of Technology Department of Computer Engineering ECS Group

INTRODUCTION TO VHDL ADVANCED COMPUTER ARCHITECTURES. Slides by: Pedro Tomás. Additional reading: - ARQUITECTURAS AVANÇADAS DE COMPUTADORES (AAC)

Arithmetic Circuits. Nurul Hazlina Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit

2/14/2016. Hardware Synthesis. Midia Reshadi. CE Department. Entities, Architectures, and Coding.

A bird s eye view on VHDL!

ECE 545 Lecture 8. Data Flow Description of Combinational-Circuit Building Blocks. George Mason University

Declarations. Lexical elements. Type declaration Subtype declaration Constant declaration Signal declaration Variable declaration.

Outline CPE 626. Advanced VLSI Design. Lecture 3: VHDL Recapitulation. Intro to VHDL. Intro to VHDL. Entity-Architecture Pair

Transcription:

LANGUAGE VHDL FUNDAMENTALS Introduction Entities and architectures Sentences and processes Objects Data types and operands Authors: Luis Entrena Arrontes, Celia López, Mario García, Enrique San Millán, Marta Portela, Almudena Lindoso 1

History of VHDL 1980: The USA Department of Defense funded a project under the program VHSIC (Very High Speed Integrated Circuit) to create a standard hardware description language. 1983: The development of VHDL began. 1987: IEEE 1076-1987 standard 1994: The standard is revised: IEEE 1076-1993 1996: First automatic tools that support the new version of the standard We will focus on the 1987 version since it is the most widely accepted standard. 2002: New version with few modifications 2

VHDL language IEEE standard Widely used, mainly in Europe (Verilog in USA) Capabilities VHDL is a very powerfu language. It can be used to design digital circuits at different abstract levels, from logic level to system level. Model and simulate digital circuits at different abstract levels. Logic synthesis, Register Transfer (RT) (automatic tools) 3

General features Design hierarchy Allows the use of design libraries. Useful for managing large and multiple designs. Generic design. Execution in parallel (concurrence) Description style Structural Behavioral Simulation and synthesis VHDL for synthesing hardware is just a subset of the VHDL for simulation. 4

Notation used Capital letters for VHDL keywords (reserved words), although VHDL is case insensitive. Brackets [ ] point out optional clauses in VHDL constructs. Vertical bar point out alternative elements. Comments are pointed out with two dashes --, like in VHDL. VHDL code examples are in a rectangle 5

LANGUAGE VHDL FUNDAMENTALS Introduction Entities and architectures Sentences and processes Objects Data types and operands 6

Entities and architectures Top level entity Entity 1 Entity 2 Architecture 1 Architecture 2 Entity 3 7

Entities The entity is the basic design unit The entity declaration consists of Generic parameters declaration Interface declaration ENTITY not_cell IS GENERIC (delay_not: TIME := 5 NS); PORT (i1: IN BIT; o1: OUT BIT); END not_cell; 8

Architectures The architecture is a secondary desing unit and it provides the functional description of a design. One entity can be matched with multiple architerctures that describe different versions for the same design. A VHDL architecture can instantatiate lower-level entities in which case they are known as component. This feature provides a hierarchical structure. ARCHITECTURE example OF not_cell IS -- Declarations BEGIN -- Sentences o1 <= NOT i1 AFTER delay_not; END example; 9

Example: a half-adder a b HalfAdder s c Half-adder equations s = a xor b c = a and b 10

The half-adder in VHDL ENTITY HalfAdder IS PORT ( a: IN BIT; b: IN BIT; s: OUT BIT; c: OUT BIT); END HalfAdder; ARCHITECTURE simple OF HalfAdder IS BEGIN s <= a XOR b; c <= a AND b; END simple; 11

Full-adder x y cin FullAdder s cout x y cin a HalfAdder b s c s_partial a HalfAdder b s c c_partial2 s c_partial1 cout 12

Full-adder in VHDL ENTITY FullAdder IS PORT ( x: IN BIT; y: IN BIT; cin: IN BIT; s: OUT BIT; cout: OUT BIT); END FullAdder ; ARCHITECTURE structural OF FullAdder IS COMPONENT HalfAdder PORT ( a: IN BIT; b: IN BIT; s: OUT BIT; c: OUT BIT); END COMPONENT; SIGNAL s_partial: BIT; SIGNAL c_partial1, c_partial2: BIT; BEGIN SS0: HalfAdder PORT MAP (x, y, s_partial, c_partial1); SS1: HalfAdder PORT MAP (s_partial, cin, s, c_partial2); cout <= c_partial1 OR c_partial2; END structural; 13

Port connection Connecting ports by using positional assotiation COMPONENT HalfAdder PORT ( a: IN BIT; b: IN BIT; s: OUT BIT; c: OUT BIT); END COMPONENT;... SS0: HalfAdder PORT MAP (x, y, s_partial, c_partial1); 14

Port connection Connecting ports by using named association COMPONENT HalfAdder PORT ( a: IN BIT; b: IN BIT; s: OUT BIT; c: OUT BIT); END COMPONENT;... SS0: HalfAdder PORT MAP (a => x, b => y, s => s_partial, c =>c_partial1); 15

LANGUAGE VHDL FUNDAMENTALS Introduction Entities and architectures Sentences and processes Objects Data types and operands 16

Concurrent statements These statements are executed in parallel! They operate independently and then they can be written in any order. The simulation tools detect when there is an event in the object values and it set when objects must be updated. Every statement in an architecture is concurrent with respect to the others. ARCHITECTURE structural OF FullAdder IS... BEGIN SS0: HalfAdder PORT MAP (x, y, s_partial, c_partial1); SS1: HalfAdder PORT MAP (s_partial, cin, s, c_partial2); cout <= c_partial1 OR c_patcial2; END structural; 17

Concurrent statements Two equivalent examples ARCHITECTURE a OF circuit IS BEGIN g1 <= a OR b; s <= g1 AND c; END a; ARCHITECTURE a OF circuit IS BEGIN s <= g1 AND c; g1 <= a OR b; END a; a b c g1 s 18

Simulation of concurrent statements ARCHITECTURE a OF circuit IS BEGIN g1 <= a OR b; s <= g1 AND c; END a; Simulation: ARCHITECTURE a OF circuit IS BEGIN s <= g1 AND c; g1 <= a OR b; END a; If there is a change in a or b -> Calculating the new value of g1 If there is a change in g1 or c -> Calculation the new value of s Each statement is executed so many times as it is necessary The order in which concurrent statements are written is irrelevant! 19

Sequential statements Concurrency can be difficult to manage by designers: VHDL also allows the use of sequential statements to describe designs Sequential statements: They are executed following a procedural flow, like in software languages. Sequential statements are always included inside processes or procedures Between the execution of two different sequential statements time does not pass. 20

Processes Processes are used to describe hardware by means of sequential statements They consist of Declarations Sequential statements The process must have a sensitivity list or at least a WAIT clause. A process is activated when A change (event) occurs in one or more signals contained in the sensitivity list The condition in the WAIT statement becomes true Proceses are executed indefinitely over and over. 21

Example of process(i) ARCHITECTURE one OF example IS BEGIN Sensitivity list PROCESS ( i1 ) VARIABLE a: BIT; BEGIN a := NOT i1; -- Sequential statement o1 <= a; -- Sequential statement END PROCESS; END example; The process is activated when i1 changes the value The statements inside the process are executed sequentially 22

Example of process(ii) ARCHITECTURE two OF example IS BEGIN PROCESS VARIABLE a: BIT; BEGIN a := NOT i1; -- Sequential statement o1 <= a; -- Sequential statement WAIT ON i1; -- Sequential statement END PROCESS; END example; Process execution is stopped in the WAIT statement The execution is resumed when there is a change in the value of i1 When the end of the process is reached the execution starts again from the beginning. 23

Recommendations for synthesis Do not use AFTER clauses in descriptions for synthesis Synthesizer ignore the clause AFTER in the assignments, since the delay is a feature of the technology used to implement the circuit. This information is fixed at low abstraction levels (physical levels), while VHDL is used at high abstraction levels (mainly RT) Do use process with sensitivity list WAIT statement is just synthesizable in very few cases WAIT statement is not supported by many synthesizers 24

LANGUAGE VHDL FUNDAMENTALS Introduction Entities and architectures Sentences and processes Objects Data types and operands 25

VHDL Data Objects Constants Variables Signals Similar to constant and variables in software languages Represent hardware signals. Their values change along the execution 26

Data Objects: Constants Hold one specific value that can not change A constant can be declared in any part of a design CONSTANT name1, name2,..., namen: type [ := value ]; Examples CONSTANT gnd : BIT := 0 ; CONSTANT n, m : INTEGER := 3; CONSTANT delay: TIME := 10 NS; 27

Data objects: Variables They can change their value The update of the value is performed just after the assignment They have to be declared in sequential fields, like in processes or subprograms They are local data, that is, variables are only visible in the process or subprogram where they are declared. There are not global variables. VARIABLE name1, name2,..., namen: type [ := value ]; VARIABLE one_variable : BIT := 1 ; VARIABLE i, j, k: INTEGER; 28

Data objects: Signals Their values have always associated a temporal factor Signal assignments do not cause a change in the signal value immediately, but after certain specified time. The pair (value, time) is called transaction Signals can only be declared in concurrent fields. However they are global objects and are also visible in sequential environments, like processes or subprograms SIGNAL name1, name2,..., namen: type [ := value ]; SIGNAL one_signal : BIT := 1 ; SIGNAL i, j, k: INTEGER; 29

Signal simulation: Drivers Each process that contains a signal assignment contains a driver for that signal The driver for a given signal stores a list of transactions to represent the current and future signal values The first transaction in a driver is the current value of that driver The simulator is in charge of updating the values in every signal along the execution time: when the time in a transaction is equal to the current instant the signal is updated with the driver s value. 30

Signal assignments If a process contain several assignments for the same signal, there is only one driver and then the final value for the signal will be the last one assigned PROCESS (a) BEGIN z <= a; z <= 1 ; END PROCESS; z always is 1 31

Signal assignments If the same signal is assigned in different concurrent statements there is a driver for each process (multiple drivers for the same signal). Therefore, the final value must be resolved The value of the signal is obtained by means of a resolution function PROCESS (a) BEGIN z <= a; END PROCESS; z? Resolution function PROCESS (b) BEGIN z <= b; END PROCESS; Current value of the signal (resolved) 32

Using signals and variables Variables: They are locals within the processes and subprograms. They are used for storing local values or temporary values They require less memory space and their use provides more efficiency at simulation, since they are updated immediately. Signals They are necessary for implementing concurrency. Using signals is the only way to communicate two different processes. Asignments For variables := For signals <= 33

LANGUAGE VHDL FUNDAMENTALS Introduction Entities and architectures Sentences and processes Objects Data types and operands 34

Outline Data types Operators and conversion functions Attributes Data types in synthesis 35

Data types VHDL is a language with a wide set of data types Every data type limits the number of possible values that an object associated with that type can take. Types Scalars: - Enumerated - Integer - Real - Physical Composite - Vector/Matrix - Record File 36

Scalars types Enumerated Values are identifiers or a character literal Enumerated data types can be defined by the language of user defined Integer Real Physical A numerical value and a physical unit The predefined type TIME is the only physical type that we are going to use. 37

Enumerated data types defined by the user Type declaration Use TYPE set_of_letters IS ( A, B, C, D ); TYPE traffic_light IS (green, amber, red); TYPE states IS (s0, s1, s2, s3, s4, s5); CONSTANT first_letter: set_of_letters := A ; SIGNAL traffic_light1: traffic_lights ; SIGNAL current_state: states ;... current_state <= s0; Traffic_light1<= green; 38

Predefined enumerated types BIT BOOLEAN ('0', '1') (FALSE, TRUE) CHARACTER (NUL, SOH,..., 'A', 'B',...) STD_LOGIC (defined in the IEEE 1164 standard) ('U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') 39

Standard logic type This type is defined in the IEEE 1164 standard. It is use widely It is a enumerated typed for logic object. It provided multiple values U X 0 1 Z W L H - - uninitialized. This is the value of an object by default - Unknown (strong) - Logic Zero (strong). Gnd - Logic One (strong). Vdd - High impedance - Unknown (weak) - Logic Zero (weak). Pull-down resistors - Logic One (weak). Pull-up resistors - Don t-care. Used for synthesis 40

Standard logic type STD_LOGIC is a resolved tipo resuelto A STD_LOGIC object may have got multiple drivers The resolution function assign an X when there is a collision between multiple drivers In order to use standard logic types we have to added the following lines before the design entity declaration: LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY... 41

Integer type Declaration and use CONSTANT n: INTEGER := 8; SIGNAL i, j, k: INTEGER;... i <= 3; It is advisable to fix a range It limits the number of bits inferred in the synthesis Simulation sends an error messages when the object has a value out of range SIGNAL BCD_value: INTEGER RANGE 0 TO 9; 42

Real type Declaration and use SIGNAL d: REAL;... d <= 3.1416; d <= 10E5; d <= 2.01E-3; It is not synthesizable However, there are libraries for operations with real numbers (simulation) 43

Physical types Example of declaration and use TYPE weight IS RANGE 0 TO 100.000.000 UNITS gram; kilo = 1000 gram; ton = 1000 kilo; END UNITS; SIGNAL p: weight; The most important physical type predefined in the VHDL standard is the type TIME FS PS NS US MS SEC MIN HR femtosecond = 10-15 sec. picosecond = 10-12 sec. nanosecond = 10-9 sec. microsecond = 10-6 sec. millisecond = 10-3 sec. second minute = 60 sec. hour = 60 minutes SIGNAL t: TIME;... t <= 10 NS; 44

Composite types: ARRAY All the elements are of the same type. All the VHDL types can be used to form arrays TYPE byte IS ARRAY ( 7 DOWNTO 0 ) OF STD_LOGIC; SIGNAL s: byte; It is possible to access one element or a subset of them s <= 00000000 ; s(2) <= 1 ; s(4 downto 3) <= 00 ; The direction of the range can be ascending (to) or descending (downto): The accessed subset of elements must have the same order as in the original vector. 45

Composite types: ARRAY Unconstrained vectors. The size of the vector is specified in a later declaration TYPE bit_vector IS ARRAY (NATURAL RANGE <>) OF BIT; SIGNAL s: bit_vector (7 DOWNTO 0); Vectors of data of types BIT and STD_LOGIC are predefined SIGNAL s: BIT_VECTOR (7 DOWNTO 0); SIGNAL a: STD_LOGIC_VECTOR (7 DOWNTO 0); 46

Multidimensional arrays Multidimensional matrix and vector of vectors TYPE matrix IS ARRAY(0 TO 479, 0 TO 479) OF STD_LOGIC; SIGNAL image: matrix; TYPE memory1 IS ARRAY(0 TO 1023) OF STD_LOGIC_VECTOR(7 DOWNTO 0); SIGNAL ram1: memory1; TYPE memory2 IS ARRAY(0 TO 1023) OF INTEGER RANGE 0 TO 255; SIGNAL ram2: memory2; Use image(0,0) <= 1 ; ram1(0)(0) <= 1 ; ram1(0) <= 00000000 ; image(0, 0 TO 7) <= 00000000 ; -- ERROR 47

Composite types: RECORD Collection of elements possibly of different types TYPE type_opcode IS (sta, lda, add, sub, and, nop, jmp, jsr); TYPE type_operand IS BIT_VECTOR (15 DOWNTO 0); TYPE instruction_format IS RECORD opcode : type_opcode; operand: type_operand; END RECORD; SIGNAL ins1: instruction_format := (nop, 0000000000000000 ); ins1.opcode <= lda; ins1.operand <= 0011111100000000 ; 48

Literals Symbols used for representing constant values in VHDL Characters: always between single quotation marks '0' '1' 'Z' Array of characters (string literals) : between double quotation marks "Esto es un mensaje" "00110010" Bit string literals: A prefix points out the base required SIGNAL b: BIT_VECTOR (7 DOWNTO 0); b <= B"11111111"; -- Binary b <= X"FF"; -- Hexadecimal b <= O"377"; -- Octal 49

Aliases and subtypes Alias are used to reference an object by a new name SIGNAL status_register: BIT_VECTOR (7 DOWNTO 0); ALIAS carry_bit: BIT IS status_register(0); ALIAS zero_bit: BIT IS status_register(1); Subtypes define a subset of a type previously defined SUBTYPE ten_values IS INTEGER RANGE 0 TO 9; 50

Predefined operators Operation Operator Operand type Result type Logical NOT, AND, OR, NAND, NOR, XOR BOOLEAN, BIT, STD_LOGIC BOOLEAN, BIT, STD_LOGIC Relational =, /=, <, <=, >, >= Any type BOOLEAN Arithmetic +, -, *, /, **, MOD, REM, ABS INTEGER, REAL, physical, STD_LOGIC_VECTOR INTEGER, REAL, physical, STD_LOGIC_VECTOR Concatenation & ARRAY & ARRAY ARRAY & element ARRAY 51

MOD and REM Reminder of an integer division: Using REM, the sign of the result is equal to the first operand. Using MOD, the sign of the result is equal to the second operand. 5 rem 3 = 2 5 mod 3 = 2 ( 5) rem 3 = 2 ( 5) mod 3 = 1 ( 5) rem ( 3) = 2 ( 5) mod ( 3) = 2 5 rem ( 3) = 2 5 mod ( 3) = 1 52

Signed and unsigned operands The result of some arithmetic operations with bit vectors can differ depending on the considered binary representation: signed or unsigned "1111" > "0000" There are two possible solutions: Using two different set of operators: STD_LOGIC_UNSIGNED for operations without sign STD_LOGIC_SIGNED for operations without sign Using two different data types: UNSIGNED for operations without sign SIGNED for operations without sign TRUE without sign (15 > 0) FALSE with sign (-1 < 0) 53

Signed and unsigned operands Example of the first possible solution: USE IEEE.STD_LOGIC_UNSIGNED.ALL;... "1111" > "0000" -- without sign USE IEEE.STD_LOGIC_SIGNED.ALL;... "1111" > "0000" -- with sign The packages STD_LOGIC_UNSIGNED and STD_LOGIC_SIGNED define the same operations but taking into account different binary representation. Therefore, they cannot be used together in a same design unit. 54

Signed and unsigned operands Example of the second possible solution: Nowadays: USE IEEE.STD_LOGIC_ARITH.ALL; USE IEEE.NUMERIC_STD.ALL;... SIGNAL u1, u2: UNSIGNED(3 DOWNTO 0); SIGNAL s1, s2: SIGNED(3 DOWNTO 0); -- without sign u1 >u2 UNSIGNED("1111") > UNSIGNED("0000") -- with sign s1 > s2 SIGNED("1111") > SIGNED("0000") 55

Conversion functions Predefined function allows the conversion between data types CONV_INTEGER CONV_STD_LOGIC_VECTOR These functions are defined in the package STD_LOGIC_ARITH USE IEEE.STD_LOGIC_ARITH.ALL;... SIGNAL s : STD_LOGIC_VECTOR ( 7 DOWNTO 0 ); SIGNAL i : INTEGER RANGE 0 TO 255;... i <= CONV_INTEGER(s); s <= CONV_STD_LOGIC_VECTOR(i, 8) 56

Concatenation and aggregates Concatenation is used to form vectors SIGNAL s1, s2 : BIT_VECTOR ( 0 TO 3 ); SIGNAL x, z : BIT_VECTOR ( 0 TO 7 );... z <= s1 & s2; z <= x(0 TO 6) & '0'; Aggregates are used to join elemnts in order to form data of a composite type (ARRAY o RECORD) s1 <= ( 0, 1, 0, 0 ); -- Equivalent to s1 <= 0100 ; s1 <= ( 2 => 1, OTHERS => 0 ); -- Equivalent to s1 <= 0010 ; s1 <= ( 0 to 2 => 1, 3 => s2(0) ); 57

Attributes Pointing out values, functions, ranges or types associated with VHDL objects and types. They may be predefined or user-defined Predefined attributes Array related: Are used to determine the range, length or the limits of an array Type related: These attributes are used to access to the elements of a given type Signal related: These attributes ares used to model some signal properties 58

Array related attributes SIGNAL d: STD_LOGIC_VECTOR(15 DOWNTO 0) Attribute Description Example Result LEFT Left bound d LEFT 15 RIGHT Right bound d RIGHT 0 HIGH Upper bound d HIGH 15 LOW Lower bound d LOW 0 RANGE Range d RANGE 15 DOWNTO 0 REVERSE_RANGE Reverse range d REVERSE_RANGE 0 TO 15 LENGTH Length d LENGTH 16 59

Type related attributes TYPE qit IS ( 0, 1, Z, X ); SUBTYPE tit IS qit RANGE 0 TO Z ; Attribute Description Example Result BASE Base of the type tit BASE qit LEFT Left bound (subtype) tit LEFT 0 RIGHT Right bound (subtype) tit RIGHT Z HIGH Upper bound (subtype) tit HIGH Z LOW Lower bound (subtype) tit LOW 0 POS(v) Position of v (base type) tit POS( X ) 3 VAL(p) Value in the p index (base type) tit VAL(3) X SUCC(v) Next value to v (base type) tit SUCC( Z ) X PRED(v) Previous value to (base type) tit PRED( 1 ) 0 LEFTOF(v) Value on the left of v (base type) tit LEFTOF( 1 ) 0 RIGHTOF(v) Value on the right of v (base type) tit RIGHTOF( 1 ) Z 60

Signal related attributes Attributes Type Description DELAYED(t) Signal It generates the same signal but delayed STABLE(t) BOOLEAN Signal The result is TRUE when the signal has not change during time t EVENT BOOLEAN value The result is TRUE when the signal has changed LAST_EVENT TIME value Spent time since the last signal event LAST_VALUE Value The value of the signal before the last event QUIET(t) BOOLEAN Signal The result is TRUE when the signal has not received any transaction during time t ACTIVE BOOLEAN value The result is TRUE when the signal have had a transaction LAST_ACTIVE TIME value Spent time since the last transaction TRANSACTION BIT Signal It changes the value every time the signal receives a transaction 61

Signal related attributes 62

User-defined attributes Attributes of entities, architectures, types and objects can be defined Firstly, we must to declare the attribute type ATTRIBUTE <attribute_name> : <type>; Secondly, we must to specify its value ATTRIBUTE < attribute_name > OF <item> : <class> IS <value> ; Example ATTRIBUTE technology: STRING; ATTRIBUTE technology OF circuit: ENTITY IS CMOS ;...... circuit technology... Circuit is an entity 63

Interpretation of data types in synthesis INTEGER: It is synthesized as a number coded in natural binary If the range contains negative numbers, it is synthesized as a number coded in two s complement It is necessary to write the range in the declaration in order to make an effecient synthesis SIGNAL a: INTEGER; SIGNAL b: INTEGER RANGE 0 TO 7; -- 32 bits -- 3 bits Enumerated: They are synthesized as a number coded in natural binary. A binary code is assigned to every value in the appearence order 64

Interpretation of data types in synthesis The following types are not synthesizable REAL Physical Files Using attributes Array related attributes: They are useful and syntesizable Types related attributes: They may be synthesizable although they are not ussualy used Signal related attributes: EVENT is the most used. The rest of these kind of attributes are not synthesizable, except STABLE 65

Initial values Simulation: In order to simulate a signal, all the signal and variables must have an initial value. The initial value can be assigned in the object s declaration If the initial value is not specified, the VHDL language assigns a value by default. In enumerated types this value is the first one at the left TYPE state IS (S0, S1, S2, S3); SIGNAL s: state:= S3; SIGNAL s: state; SIGNAL a: BIT; SIGNAL b: STD_LOGIC; -- Initial value: S3 -- Initial value : S0 -- Initial value : '0' -- Initial value : 'U' 66

Initial values Synthesis Synthesizers have not taking into account initial values The inizialization has to be made in hardware SIGNAL b: STD_LOGIC;... PROCESS (reset,...) BEGIN IF reset = '1' THEN b <= '0';... 67