E21 Lecture #22

VHDL: VHSIC Hardware Description Language

Time to dive into data types and syntax

Data types, variables, & signals

  1. Scalar types
  2. Enumeration: a set of user defined literals
  3. Ordering in an enumeration type is important
  4. A variable is, by default, initialized to the leftmost element of an enumeration type
  5. You can use the same literals in multiple enumeration types (overloading)
  6. Predefined enumeration types: character (191 characters), bit (`0', `1'), boolean (FALSE, TRUE), severity_level, file_open_kind, and file_open_status.
  7. Enumeration types in std_logic_1164: std_ulogic (`U', `X', `0', `1', `Z', `W', `L', `H', `-' ) (definitions on pp. 43 of Bhasker)
  8. Integer: a type whose values are integers that fall within a specified range
  9. integer is the only predefined integer type
  10. Natural (0 to integer'high) and positive (1 to integer'high) are predefined subtypes
  11. You can define other integer types: type INDEX is range 0 to 15;
  12. Physical: numbers connected with units
  13. Physical literals are an integer or floating point value followed by a unit specification
  14. Example: 100 ns (space is important)
  15. The only predefined physical type is time
  16. Floating point: numbers containing decimal values with a specified range
  17. The only predefined floating point type is REAL
  18. You can define other floating point types: type ANALOG is range 0.0 to 5.0
  19. A floating point literal must have a decimal point (you can write it in scientific notation)
  20. Subtypes: variables of a specific type that have a range less than or equal to their type
  21. Composite types (arrays and records)
  22. Array types: vectors of the basic scalar types
  23. You can define an array as counting up or down
  24. You can define multi-dimensional arrays
  25. You can define arrays of arrays
  26. type BigEndian is array (7 downto 0) of std_ulogic;
  27. type LittleEndian is array (0 to 7) of std_ulogic;
  28. type ROM is array (0 to 127) of BigEndian;
  29. type ROM2 is array (0 to 127, 7 downto 0) of std_ulogic;
  30. You access ROM by AROM(5)(5);
  31. You access ROM2 by (AROM2(5, 5);
  32. You can define array types that do not have a predefined number of elements (defined at declaration time or by the passing variable if passed to a subroutine
  33. type STACKTYPE is array (integer range <>) of ProgramWord;
  34. variable STACK: STACKTYPE (0 to 8);
  35. String and Bit_Vector are predefined array types
  36. std_ulogic_vector and std_logic_vector are predefined in std_logic_1164
  37. string literals "stuff in quotes" can be assigned to an array; type is based on context
  38. B"0100010" means a bit string
  39. X"04FA" means a hex number
  40. You can define record types in VHDL
  41. Might use a record type to define external ports, buses with dedicated lines, etc..
  42. Access types (pointers)
  43. You can define pointers in VHDL
  44. Access types must be variables (local to the process, subprogram, or function)
  45. Access types cannot be signals
  46. Filte types (files)
  47. For reading and writing data to and from the host environment
  48. Might use for debugging, tracing the progress of a function, or simulating ROM contents

Operators & relational operators

  1. Logical operators
  2. and, or, nand, nor, xor, xnor, not
  3. Make sure you follow associativity rules and use parentheses, (nand and nor are not associative)
  4. Relational operators
  5. =, /=, <, <=, >, >=
  6. You can compare discrete arrays, which are compared element by element left to right
  7. Shift operators
  8. sll, srl, sla, sra, rol, ror
  9. Logical moves 0's into the position
  10. arithmetic duplicates whatever was in the leftmost/rightmost position
  11. rotate just rotates the bits around
  12. Adding operators
  13. +, -, & (concatenate)
  14. Multiplying operators
  15. *, /, mod, rem (remainder)
  16. Miscellaneous operators
  17. abs, ** (exponentiation, only integer exponents allowed)

Statements (processes, wait statements, if, loops, conditional assignments)

Main behavioral statement is a process. A process can contain any of a number of statements

  1. Variable assignments
  2. Variables are local to the process
  3. Variables are assigned their value instantaneously
  4. Variables maintain their value throughout the simulation run (processes are never exited)
  5. Variables get their value from the variable assignment operator :=
  6. Signal assignments
  7. Signals can be passed into the process
  8. Signal assignments within a process are considered sequential signal assignments
  9. Signal values are not updated instantaneously, but only after a specified time or a delta delay
  10. Delta delays: A delta delay is a mechanism for scheduling events and assignments in a digital simulation. The delta delay does not take any real time, but is a way of specifying the order in which things happen. When a signal gets assigned a value, that value gets put on the signal driver along with a simulation time at which the signal is to be updated. Then other statements are executed (at the current simulation time). Then simulation time is updated by delta, and any signal assigments or events at that simulation time are executed.

  11. Example: Z <= A; B <= Z;
  12. Since there is a delta delay before Z is assigned A, B is scheduled to get the old value of Z, event though the B <= Z statement came after the signal assignment Z <= A.
  13. Signals get their assignment from the signal assignment operator <=
  14. wait statements
  15. wait statements suspend a process until a set of conditions is true
  16. wait on sensititvity-list;
  17. wait until boolean-expression;
  18. wait for time-expression;
  19. wait on sensitivity-list until boolean-expression for time-expression;
  20. The last statement means to wait until all of the conditions are true.
  21. You can use wait statements to create waveforms
  22. You can use wait statements to allow processes to talk to one another
  23. if statements
  24. if X then statements elsif Y then statements else statements end if;
  25. case statements
  26. case expression is when choices => statements;
  27. loop statements
  28. for, while, loop expressions
  29. loops can have labels (a good thing)
  30. loop1: for index in 1 to N loop statements end loop loop1;
  31. loop2: while N < 20 loop statements end loop loop2;
  32. loop3: loop statements exit when N > 20; end loop loop3;
  33. null statements
  34. Useful in case or if statements where you don't want to do anything
  35. exit statements
  36. Can exit loops
  37. exit with no identifier leaves the innermost loop
  38. exit with an identifier leaves the identified loop
  39. next statements
  40. Like the continue statement in C, goes back to the top of the loop
  41. assertion statements
  42. Used for debugging purposes
  43. report statements
  44. Can be used to display a message
  45. procedure calls
  46. return statements

Concurrent v. Sequential Statements and how VHDL models digital systems

We've covered the basic syntax for sequential statements, now we need to turn to a more detailed analysis of how VHDL models digital systems. In particular, how does it deal with signals, which form the basis for the transfer of information and the dataflow level of modeling.

Signal drivers

Creating signal waveforms

  • Signal assignments can contain multiple values with the "after" keyword
  • CLOCK <= `0', `1' after 8 ns, `0' after 12 ns, `1' after 20 ns, `0' after 24 ns;
  • This assignment schedules 5 events for the CLOCK signal driver
  • If another sequential statement does something like:
  • CLOCK <= `1' after 15 ns;
then all of the events in the signal driver on or after 15 ns are removed from the queue.

Sequential v. Concurrent signal assignments

A concurrent signal assignment (not in a process) is executed whenever there is an event on one of the signals on the right hand side of the assignments.

Example: propagating signals

  • Architecture using a process to pass a value from A to B to C
  • Architecture using concurrent statements to pass a value from A to B to C

Concurrent statements still use delta delays to pass events around at a given simulation time (unless specific event times are given in the assignment statement(s)).

Example: flip-flop

pp. 109 of Bhasker

Concurrent signal drivers

Each concurrent signal assignment statement creates a driver for that signal.

What happens if more than one statement assigns a value to a single signal (multiple drivers)?

  • You create a resolution function: it decides what value the signal should have given the list of proposed values from all of the signal drivers
  • You can implement a wired-or or a wired-and function using a resolution function
  • The type std_logic is a resolved type (std_ulogic is not)