1 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS Y TIPOS DE DATOS Elementos Tipos de datos Librerías Std_logic y Std_logic_vector
2 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS Elementos del VHDL: Comentarios Palabras reservadas. Identificadores Símbolos especiales Números Caracteres Cadenas y cadenas de bits.
3 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS: Comentarios y palabras reservadas Comentario: - Línea de comentario comienza con --. - Ejemplo: -- Esto es un comentario. Palabras reservadas: - Reservadas para uso específico del lenguaje. - No pueden ser usados para definir identificadores.
4 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS: Identificadores Identificadores: - Utilizados por usuario para nombrar objetos. - Se deben usar nombres que indiquen su propósito. - Pueden ser de cualquier longitud. - Reglas: 1. Deben empezar con una letra del alfabeto. 2. Pueden contener: - Letras del alfabeto ( A Z, a z ) - Números decimales ( 0 9 ). - Caracteres _. 3. No pueden terminar en _. 4. No pueden tener _ sucesivos.
5 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS: Símbolos especiales Símbolos especiales - Operadores: + - * / & ( ) = > < - Delimitan partes de las construcciones: # ` [ ] - Delimitadores léxicos:., ; : - Símbolos con dos caracteres: := => /= >= <= **
6 ELEMENTOS Y TIPOS DE DATOS Operadores Operadores lógicos and or nand nor xor not xnor Operadores relacionales = /= < <= > >= Precedencia de operadores Highest Lowest not = /= < <= > >= and or nand nor xor xnor
7 ELEMENTOS Y TIPOS DE DATOS Concatenación de vectores signal A: STD_LOGIC_VECTOR(3 downto 0); signal B: STD_LOGIC_VECTOR(3 downto 0); signal C, D, E: STD_LOGIC_VECTOR(7 downto 0); A <= 0000 ; B <= 1111 ; C <= A & B; -- C = 00001111 D <= 0 & 0001111 ; -- D <= 00001111 E <= 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 ; -- E <= 00001111
8 ELEMENTOS Y TIPOS DE DATOS Rotación de vectores.
9 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS: Números Números Dos tipos: Entero y real. Ambos tipos pueden ser representados en notación exponencial (46E5, 1.34E5).
10 ELEMENTOS Y TIPOS DE DATOS ELEMENTOS: Caracteres, cadenas y cadenas de bits Caracteres - Escritos entre comillas. Ejemplo: A, z. Cadenas: - Escritos entre doble comilla. Ejemplo: abcdefg, 123456. - Operación de concatenación con &. Ejemplo: abc & def => abcdef. Cadenas de bits: - Cadenas de números binarios, octales o hexadecimales. - Escritos entre doble comilla y precedidos de la base: B 10000, O 20, X 10.
11 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS. VHDL es un lenguaje basado en tipos de datos. Cada tipo determina las operaciones que pueden ser realizadas. Tipos pre-definidos: Integer Floating-point Physical Enumeration Array Record El usuario puede definir nuevos tipos.
12 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS. Types Access Composite Scalar Array Record Integer Real Enumerated Physical
13 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Integer Tipo predefinido para representar números enteros. Lenguaje estándar: Números en el rango: -2 31 1 2 31 1 El usario puede definir un sub-rango diferente:
14 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Integer Ejemplo: ARCHITECTURE test_int OF test IS BEGIN PROCESS (X) VARIABLE a: INTEGER; BEGIN a := 1; -- OK a := -1; -- OK a := 1.0; -- illegal END PROCESS; END test_int;
15 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Integer, operaciones Suma: + Resta o negación: - Multiplicación: * División: / Módulo: mod (-5) mod 3 = 1 Resto: rem (-5) rem 3 = -2 Valor absoluto: abs Exponenciación: ** Lógicos: =, /=, <, >, <=, >=
16 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Floating-Point Tipo predefinido para representar números en punto flotante. El usario puede definir un sub-rango diferente:
17 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Floating-Point Ejemplo: ARCHITECTURE test_real OF test IS BEGIN PROCESS (X) VARIABLE a: REAL; BEGIN a := 1.3; -- OK a := -7.5; -- OK a := 1; -- illegal a := 1.7E13; -- OK a := 5.3 ns; -- illegal END PROCESS; END test_real;
18 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Floating-Point, operaciones Suma: + Resta o negación: - Multiplicación: * División: / Valor absoluto: abs Exponenciación: ** Lógicos: =, /=, <, >, <=, >=
19 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Physical Usados para representar valores físicos (longitud, masa, tiempo y corriente). Definión similar al tipo de datos enteros, pero con definición adicional de unidad. Primary unit primer identificador después de la palabra units : es la unidad más pequeña.
20 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Physical Ejemplo: TYPE resistance IS RANGE 0 TO 10000000 UNITS ohm; -- ohm Kohm = 1000 ohm; -- i.e. 1 K Mohm = 1000 kohm; -- i.e. 1 M END UNITS;
21 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Physical, operaciones Suma: + Resta o negación: - Multiplicación por entero o real.: * División por entero o real: / Valor absoluto: abs Exponenciación: ** Lógicos: =, /=, <, >, <=, >=
22 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Physical, ejemplo. Time: Es un tipo predefinido, usado para medir tiempos en simulaciones y para generar relojes. Time: No es sintetizable
23 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Physical, ejemplo. Time: Simulación de un período de reloj (10ns).
24 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Enumerated Se pueden utilizar para dar valores o nombres a un objeto. Ejemplo: cuando se modela un procesador, para nombrar explícitamente las funciones que implementa (legibilidad del código).
25 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Enumerated Ejemplo: TYPE binary IS ( ON, OFF );... some statements... ARCHITECTURE test_enum OF test IS BEGIN PROCESS (X) VARIABLE a: binary; BEGIN a := ON; -- OK... more statements... a := OFF; -- OK... more statements... END PROCESS; END test_enum;
26 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Enumerated (Boolean) Es uno de los tipos enumerated predefinidos más útiles. Usado para representar valores de condición para control.
27 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Boolean, operaciones Muchas operaciones VHDL aplicadas a otros tipos de datos tienen como resultado un valor booleano: Relaciones: Igualdad ( = ) o desigualdad ( /= ) aplicado a datos del mismo tipo: Ejemplo: 32=32 (true), `VHDL /= `Verilog (true). Relaciones: Menor ( < ), menor-igual ( <= ), mayor ( > ), mayor-igual ( >= ). Aplicable a tipos con orden (enteros, caracteres), ambos operandos del mismo tipo. Ejemplo: 827 > 789 (true), `1 < `0 (false).
28 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Boolean, operaciones Operadores lógicos: and, or, nand, nor, xor, xnor, not. Todos los operandos booleanos. Resultado booleano. Ejemplo:
29 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Boolean, síntesis Síntesis del tipo booleano: true se sintetiza como el valor lógico 1 (vdd) false se sintetiza como el valor lógico 0 (gnd)
30 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Enumerated (Bit) Es uno de los tipos enumerated predefinidos. Es el tipo más frecuentemente utilizado. Diferencias: Valores Booleanos: Condiciones de control. Bits: representan niveles de voltaje.
31 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Bit, operaciones Operaciones: Lógicas: =, /=, <, >, <=, >= Booleanas: and, or, nand, nor, xor, xnor, not Shift: sll, srl, sla, sra, rol, ror Ejemplos:
32 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Enumerated (Characters) Es uno de los tipos enumerated predefinidos.
33 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Enumerated (Characters) Escritos entre comas sencillas. `A, `k Ejemplo: Cada carácter se representa con un número binario de 8 bits (formato ASCII).
34 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays array_type <= array ( discrete_range {, } ) of element_subtype_indication ; discrete_range <= discrete_subtype_indication expr ( to downto ) expr discrete_subtype_indication <= type_mark [ range expr ( to downto ) expr ]
35 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays type word1 is array (0 to 31) of bit; type word2 is array (31 downto 0) of bit; type state is (initial, idle, active, error); type state_counts1 is array (state) of natural; type state_counts2 is array (state range initial to active) of natural;
36 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays Ejemplo: TYPE data_bus IS ARRAY(0 TO 31) OF BIT; VARIABLE X : data_bus; VARIABLE Y : BIT; Y := X(12); -- Y gets value of element at index 12
37 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays Ejemplo: TYPE reg_type IS ARRAY(15 DOWNTO 0) OF BIT; VARIABLE X : reg_type; VARIABLE Y : BIT; Y := X(4); -- Y gets value of element at index 4
38 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays multidimensionales type symbol is ( a, t, d, h ); type state is range 0 to 6; type trans_matrix is array(state, symbol) of state; variable trans_table: trans_matrix; trans_table(0, a ) := 1;
39 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Unconstrained Arrays array_type <= array ( ( type_mark range <> ) {, } ) of element_subtype_indication ; type sample is array (natural range <>) variable short: sample (0 to 63); of integer;
40 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays (cadenas) string es un unconstrained array de tipo carácter. variable name: string (0 to 11) := (others => );
41 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays (vectores de bits) bit_vector es un unconstrained array de tipo bit. variable byte: bit_vector(0 to 7);
42 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays (vectores de bits) Operaciones sobre buses tipo bit.
43 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays, operaciones and, or, nand, nor, xor, xnor Pueden ser aplicados a arrays 2D del mismo tamaño y del mismo tipo (bit o booleano). sll, slr, sal, sar, rol, ror Pueden ser aplicados a un array 1D de tipo bit o booleano. sll or slr llenado con cero. sla or sra llenado con copias del elemento. rol and ror rotan. Operadores relacionales: <, >, <=, >=, =, /= Concatenación: &
44 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Arrays, secciones y conversión type array1 is array (1 to 100) of integer; variable a1,b1: array1; b1(1 to 50) := a1(51 to 100); -- array slices subtype big_type is bit_vector(0 to 15); subtype little_type is bit_vector(31 downto 16); variable big : big_type; variable little : little_type; big := little; -- array conversion
45 ELEMENTOS Y TIPOS DE DATOS TIPOS DE DATOS: Records Se utilizan para agrupar diferentes tipos en un único objeto. TYPE binary IS ( ON, OFF ); TYPE switch_info IS RECORD status : BINARY; IDnumber : INTEGER; END RECORD; VARIABLE switch : switch_info; switch.status := ON; -- status of the switch switch.idnumber := 30; -- e.g. number of the switch
46 ELEMENTOS Y TIPOS DE DATOS LIBRERÍAS Librería IEEE Cargando librería:
47 ELEMENTOS Y TIPOS DE DATOS LIBRERÍAS Paquetes estándar que definen operaciones y tipos de datos normalmente utilizados. Std_Logic_1164: Std_ulogic Std_ulogic_vector Std_logic Std_logic_vector Incluir en todos los diseños.
48 ELEMENTOS Y TIPOS DE DATOS DESVENTAJAS TIPO BIT Elementos únicos: `0 y `1 No suficiente para modelar el comportamiento de hardware real. No es posible indicar: Valores sin inicializar. Valores desconocidos (bus atacado simultáneamente por dos fuentes). Tri-state o alta impedancia.
49 ELEMENTOS Y TIPOS DE DATOS TIPOS Std_logic y Std_ulogic Parte de la librería IEEE (paquete std_logic_1164). Diseñado para modelar señales eléctricas.
50 ELEMENTOS Y TIPOS DE DATOS TIPOS Std_logic y Std_ulogic: Ejemplo Buffer Tri-state Errores en la señal de enable no afectan a data_out
51 ELEMENTOS Y TIPOS DE DATOS Std_logic vs. Std_ulogic Sistemas con 9 valores lógicos. Std_logic: resuelve de acuerdo a la tabla de resolución.
52 ELEMENTOS Y TIPOS DE DATOS Std_logic vs. Std_ulogic Std_ulogic: no puede estar atacado por más de un driver. En otro caso se producen errores. Bueno para diseños sin buses tri-state. Std_logic: permite múltiples drivers. Puede ser usado en diseños tri-state.
53 ELEMENTOS Y TIPOS DE DATOS Std_logic vs. Std_ulogic: Ejemplo Std_logic bus con múltiples drivers
54 ELEMENTOS Y TIPOS DE DATOS Std_ulogic_vector, Std_logic_vector Unconstrained arrays de valores std_ulogic y std_logic, respectivamente.
55 ELEMENTOS Y TIPOS DE DATOS Std_logic_vector
56 ELEMENTOS Y TIPOS DE DATOS Std_logic_vector signal A: STD_LOGIC; signal B: STD_LOGIC_VECTOR(3 downto 0); signal C: STD_LOGIC_VECTOR(3 downto 0); signal D: STD_LOGIC_VECTOR(7 downto 0); signal E: STD_LOGIC_VECTOR(15 downto 0); signal F: STD_LOGIC_VECTOR(8 downto 0);. A <= 1 ; B <= 0000 ; -- Binary base assumed by default C <= B 0000 ; -- Binary base explicitly specified D <= 0110_0111 ; -- You can use _ to increase readability E <= X AF67 ; -- Hexadecimal base F <= O 723 ; -- Octal base
57 ELEMENTOS Y TIPOS DE DATOS Funciones aritméticas Para usar funciones aritméticas con std_logic_vectors hay que incluir los siguientes paquetes: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;
58 ELEMENTOS Y TIPOS DE DATOS Funciones aritméticas