1 / 64

Data types

ECE 545 Lecture 9. Data types. Sources & Required Reading. Peter Ashenden, The Designer’s Guide to VHDL , Chapter 2 Scalar Data Types and Operations Chapter 4 Composite Data Types and Operations Sundar Rajan, Essential VHDL , Chapter 5

elgin
Télécharger la présentation

Data types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 545 Lecture 9 Data types ECE 545 – Introduction to VHDL

  2. Sources & Required Reading • Peter Ashenden, The Designer’s Guide to VHDL, • Chapter 2 • Scalar Data Types and OperationsChapter 4 • Composite Data Types and Operations • Sundar Rajan, Essential VHDL, • Chapter 5 • Counters and Simple Arithmetic Functions ECE 545 – Introduction to VHDL

  3. VHDL as a Strongly Typed Language ECE 545 – Introduction to VHDL

  4. Notion of type • Type defines a set of values and a set of applicable operations • Declaration of a type determines which values can be stored in an object (signal, variable, constant) of a given type • Every object can only assume values of its nominated type • Each operation (e.g., and, +, *) includes the types of values to which the operation may be applied, and the type of the result • The goal of strong typing is a detection of errors at an early stage of the design process ECE 545 – Introduction to VHDL

  5. Example of strong typing architecture incorrect of example1 is type apples is range 0 to 100; type oranges is range 0 to 100; signal apple1: apples; signal orange1: oranges; begin apple1 <= orange1; end incorrect; ECE 545 – Introduction to VHDL

  6. Type Classification ECE 545 – Introduction to VHDL

  7. Classification of data types ECE 545 – Introduction to VHDL

  8. Integer Types ECE 545 – Introduction to VHDL

  9. Integer type Name:integer Status: predefined Contents: all integer numbers representable on a particular host computer, but at least numbers in the range –(231-1) .. 231-1 ECE 545 – Introduction to VHDL

  10. User defined integer types - Examples type day_of_month is range 0 to 31; type year is range 0 to 2100; type set_index_range is range 999 downto 100; constant number_of_bits: integer :=32; type bit_index is range 0 to number_of_bits-1; Values of bounds can be expressions, but need to be known when the model is analyzed. ECE 545 – Introduction to VHDL

  11. Enumeration Types ECE 545 – Introduction to VHDL

  12. Predefined enumeration types (1) boolean (true, false) bit (‘0’, ‘1’) characterVHDL-87: 128 7-bit ASCII characters VHDL-93: 256 ISO 8859 Latin-1 8-bit characters ECE 545 – Introduction to VHDL

  13. Predefined enumeration types (2) severity_level (note, warning, error, failure) Predefined in VHDL-93 only: file_open_kind (read_mode, write_mode, append_mode) file_open_status (open_ok, status_error, name_error, mode_error) ECE 545 – Introduction to VHDL

  14. User-defined enumeration types - Examples type state is (S0, S1); type alu_function is (disable, pass, add, subtract, multiply, divide); type octal_digit is (‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’); type mixed is (lf, cr, ht, ‘-’, ‘/‘, ‘\’); Each value in an enumeration type must be either an identifier or a character literal ECE 545 – Introduction to VHDL

  15. Floating-Point Types ECE 545 – Introduction to VHDL

  16. Floating point types • Used to represent real numbers • Numbers are represented using a significand (mantissa) part and an exponent part • Conform to the IEEE standard 754 or 854 Minimum size of representation that must be supported by the implementation of the VHDL standard: VHDL-2001: 64-bit representation VHDL-87, VHDL-93: 32-bit representation ECE 545 – Introduction to VHDL

  17. Real literals - examples 23.1 23.1 46E5 46  105 1E+12 1  1012 1.234E09 1.234  109 34.0e-08 34.0  10-8 2#0.101#E5 0.1012  25 =(2-1+2-3)  25 8#0.4#E-6 0.48  8-6 = (4  8-1)  8-6 16#0.a5#E-8 0.a516  16-8 =(1016-1+516-2)  16-8 ECE 545 – Introduction to VHDL

  18. Floating-point number format ECE 545 – Introduction to VHDL

  19. The ANSI/IEEE standard floating-point number representation formats ECE 545 – Introduction to VHDL

  20. ECE 545 – Introduction to VHDL

  21. Features of the ANSI/IEEE standard floating-point number representation formats ECE 545 – Introduction to VHDL

  22. User-defined floating-point types - Examples type input_level is range -10.0 to +10.0 type probability is range 0.0 to 1.0; constant max_output: real := 1.0E6; constant min_output: real := 1.0E-6; type output_range is max_output downto min_output; ECE 545 – Introduction to VHDL

  23. Physical Types ECE 545 – Introduction to VHDL

  24. Physical data types Types representing physical quantities, such as time, voltage, capacitance, etc. are referred in VHDL as physical data types. TIME is the only predefined physical data type. Value of the physical data type is called a physical literal. ECE 545 – Introduction to VHDL

  25. Time values (physical literals) - Examples 7 ns 1 min min 10.65 us 10.65 fs Numeric value Space Unit of time (dimension) ECE 545 – Introduction to VHDL

  26. TIME values Numeric value can be an integer or a floating point number. Numeric value is optional. If not given, 1 is implied. Numeric value and dimension MUST be separated by a space. ECE 545 – Introduction to VHDL

  27. Units of time Unit Definition Base Unit fs femtoseconds (10-15 seconds) Derived Units ps picoseconds (10-12 seconds) ns nanoseconds (10-9 seconds) us microseconds (10-6 seconds) ms miliseconds (10-3 seconds) sec seconds min minutes (60 seconds) hr hours (3600 seconds) ECE 545 – Introduction to VHDL

  28. User-defined physical types (1) type resistance is range 0 to 1E9 units ohm; kohm = 1000 ohm; Mohm = 1000 kohm; end units resistance; name needs to be skipped in VHDL-87 ECE 545 – Introduction to VHDL

  29. User-defined physical types (2) type length is range 0 to 1E10 units um; -- primary unit: micron mm = 1000 um; -- secondary metric units m = 1000 mm; inch = 25400 um; -- secondary English units foot = 12 inch; end units length; ECE 545 – Introduction to VHDL

  30. Attributes of Scalar Types ECE 545 – Introduction to VHDL

  31. Attributes of all scalar types T’left first (leftmost) value in T T’right last (rightmost) value in T T’low least value in T T’high greatest value in T Not available in VHDL-87: T’ascending true if T is an ascending range, false otherwise T’image(x) a string representing the value of x T’value(s) the value in T that is represented by s ECE 545 – Introduction to VHDL

  32. Attributes of all scalar types - examples type index_range is range 21 downto 11; index_range’left = 21 index_range’right = 11 index_range’low = 11 index_range’high = 21 index_range’ascending = false index_range’image(14) = “14” index_range’value(“20”) = 20 ECE 545 – Introduction to VHDL

  33. Attributes of all scalar types - examples type resistance is range 0 to 1E9 units ohm; kohm = 1000 ohm; Mohm = 1000 kohm; end units resistance; resistance’left = 0 ohm resistance’right = 1E9 ohm resistance’low = 0 ohm resistance’high = 1E9 ohm resistance’ascending = true resistance’image(2 kohm) = “2000 ohm” resistance’value(“5 Mohm”) = 5_000_000 ohm ECE 545 – Introduction to VHDL

  34. Attributes of discrete and physical types T’pos(x) position number of x in T T’val(n) value in T at position n T’succ(x) value in T at position one greater than position of x T’pred(x) value in T at position one less than position of x T’leftof(x) value in T at position one to the left of x T’rightof(x) value in T at position one to the right of x ECE 545 – Introduction to VHDL

  35. Attributes of discrete types - examples type logic_level is (unknown, low, undriven, high); logic_level’pos(unknown) = 0 logic_level’val(3) = high logic_level’succ(unknown) = low logic_level’pred(undriven) = low logic_level’leftof(unknown) error logic_level’rightof(undriven) = high ECE 545 – Introduction to VHDL

  36. Subtypes ECE 545 – Introduction to VHDL

  37. Subtype • Defines a subset of a base type values • A condition that is used to determine which values are included in the subtype is called a constraint • All operations that are applicable to the base type also apply to any of its subtypes • Base type and subtype can be mixed in the operations, but the result must belong to the subtype, otherwise an error is generated. ECE 545 – Introduction to VHDL

  38. Predefined subtypes natural integers  0 positive integers > 0 Not predefined in VHDL-87: delay_length time  0 ECE 545 – Introduction to VHDL

  39. User-defined subtypes - Examples subtype bit_index is integer range 31 downto 0; subtype input_range is real range 1.0E-9 to 1.0E+12; ECE 545 – Introduction to VHDL

  40. Operators ECE 545 – Introduction to VHDL

  41. Operators (1) ECE 545 – Introduction to VHDL

  42. Operators (2) ECE 545 – Introduction to VHDL

  43. Operators (3) ECE 545 – Introduction to VHDL

  44. Operator Overloading ECE 545 – Introduction to VHDL

  45. Operator overloading • Operator overloading allows different argument types for a given operation (function) • The VHDL tools resolve which of these function to select based on the types of the inputs • This selection is transparent to the user as long as the function has been defined for the given argument types. ECE 545 – Introduction to VHDL

  46. Different declarations for the same operator - Example Declarations in the package ieee.std_logic_unsigned: function “+” ( L: std_logic_vector; R:std_logic_vector) return std_logic_vector; function “+” ( L: std_logic_vector; R: integer) return std_logic_vector; function “+” ( L: std_logic_vector; R:std_logic) return std_logic_vector; ECE 545 – Introduction to VHDL

  47. Different declarations for the same operator - Example signal count: std_logic_vector(7 downto 0); You can use: count <= count + “0000_0001”; or count <= count + 1; or count <= count + ‘1’; ECE 545 – Introduction to VHDL

  48. Constrained Array Types ECE 545 – Introduction to VHDL

  49. One-dimensional arrays – Examples (1) type word_asc isarray(0 to 31) of bit; type word_desc is array(31 downto 0) of bit; ….. signal buffer_register: word_desc; ….. buffer_register(6) <= ‘1’; ….. variable tmp : word_asc; ….. tmp(5):= ‘0’; ECE 545 – Introduction to VHDL

  50. One-dimensional arrays – Examples (2) type controller_state is (initial, idle, active, error); type state_counts_imp is array(idle to error) of natural; type state_counts_exp is array(controller_state range idle to error) of natural; type state_counts_full is array(controller_state) of natural; ….. variable counters: state_counts_exp; ….. counters(active) := 0; ….. counters(active) := counters(active) + 1; ECE 545 – Introduction to VHDL

More Related