Overview of VHDL


Primitive Data Types: Their meaning and uses

Integer    to count in discrete steps
Bit    to represent the most commonly occurring model of discrete digital circuit value
Boolean    to represent decisions, outcomes of logical expression evaluation,
        especially used in procedural control flow
 Character  
         type character is the set of ASCII symbols
Reals    to represent analog, continuously variable, measurable values in design space.
Time
is a standard, pre-defined physical type.

Primitive Objects in VHDL

Signal    - analogous to wire or device output. Holds values which may change over time.
Variable  - often has no direct correspondence in hardware. Also holds values which may change over time.
Constant - has a single value for all time.
        constant  Reg_size:  integer := 16;
        constant  Tprop:  time  := 15 ns;
        signal  preset, clear:  bit;
        signal  CS1:  bit;
        variable  i_slice:  integer range 0 to Reg_size-1;
Comments

User Defined Types

User Defined Objects

Entities and Architectures

Packages

Example of a package implementing a standard

PACKAGE std_logic_INC IS
------------------------------------------------------------------    
-- logic state system  (unresolved)
    TYPE std_ulogic IS ( 'U',  -- Uninitialized
                         'X',  -- Forcing  Unknown
                         '0',  -- Forcing  0
                         '1',  -- Forcing  1
                         'Z',  -- High Impedance   
                         'W',  -- Weak     Unknown
                         'L',  -- Weak     0       
                         'H',  -- Weak     1       
                         '-'     -- Don't care   );
------------------------------------------------------------------    
-- unconstrained array of std_ulogic for use with resolution function
    TYPE std_ulogic_vector IS ARRAY ( NATURAL RANGE <> ) OF std_ulogic;
-------------------------------------------------------------------
-- common subtypes
    SUBTYPE X01     IS resolved std_ulogic RANGE 'X' TO '1'; 
    SUBTYPE X01Z    IS resolved std_ulogic RANGE 'X' TO 'Z'; 
    SUBTYPE UX01    IS resolved std_ulogic RANGE 'U' TO '1';
-------------------------------------------------------------------    
-- overloaded logical operators
    FUNCTION "and"  ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
    FUNCTION "nand" ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
    FUNCTION "or"   ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
    FUNCTION "nor"  ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
    FUNCTION "xor"  ( l : std_ulogic; r : std_ulogic ) RETURN UX01;
    FUNCTION "not"  ( l : std_ulogic                 ) RETURN UX01;
    
-------------------------------------------------------------------
-- vectorized overloaded logical operators
    FUNCTION "and"  ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
    FUNCTION "nand" ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
    FUNCTION "or"   ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
    FUNCTION "nor"  ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
    FUNCTION "xor"  ( l, r : std_ulogic_vector ) RETURN std_ulogic_vector;
    FUNCTION "not"  ( l : std_ulogic_vector ) RETURN std_ulogic_vector;
-------------------------------------------------------------------
-- conversion functions
    FUNCTION To_bit    ( s : std_ulogic; xmap : BIT := '0') RETURN BIT;
    FUNCTION To_bitvector ( s : std_ulogic_vector; xmap : BIT := '0') 
                                                           RETURN BIT_VECTOR;
    FUNCTION To_StdULogic       ( b : BIT ) RETURN std_ulogic;
    FUNCTION To_StdULogicVector ( b : BIT_VECTOR ) 
                                                        RETURN std_ulogic_vector;
-------------------------------------------------------------------
-- strength strippers and type convertors
    FUNCTION To_X01  ( s : std_ulogic_vector ) RETURN  std_ulogic_vector;
    FUNCTION To_X01  ( s : std_ulogic        ) RETURN  X01;
                        .
                        .
                        .
    FUNCTION To_UX01  ( b : BIT_VECTOR  ) RETURN  std_ulogic_vector;
    FUNCTION To_UX01  ( b : BIT ) RETURN  UX01;       
-------------------------------------------------------------------
-- edge detection
    FUNCTION rising_edge  (SIGNAL s : std_ulogic)  RETURN BOOLEAN;
    FUNCTION falling_edge (SIGNAL s : std_ulogic)  RETURN BOOLEAN;
-------------------------------------------------------------------
-- object contains an unknown
    FUNCTION Is_X ( s : std_ulogic_vector ) RETURN  BOOLEAN;
    FUNCTION Is_X ( s : std_ulogic        ) RETURN  BOOLEAN;

END std_logic_1164;

PACKAGE BODY std_logic_1164 IS
    -------------------------------------------------------------------
    -- local types
    -------------------------------------------------------------------
    TYPE stdlogic_1d IS ARRAY (std_ulogic) OF std_ulogic;
    TYPE stdlogic_table IS ARRAY(std_ulogic, std_ulogic) OF std_ulogic;

    -------------------------------------------------------------------
    -- resolution function
    -------------------------------------------------------------------
    CONSTANT resolution_table : stdlogic_table := (
    -----------------------------------------------------------
    --      |  U    X    0    1    Z    W    L    H    -        |   |
    -----------------------------------------------------------
            ( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ), -- | U |
            ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ), -- | X |
            ( 'U', 'X', '0', 'X', '0', '0', '0', '0', 'X' ), -- | 0 |
            ( 'U', 'X', 'X', '1', '1', '1', '1', '1', 'X' ), -- | 1 |
            ( 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', 'X' ), -- | Z |
            ( 'U', 'X', '0', '1', 'W', 'W', 'W', 'W', 'X' ), -- | W |
            ( 'U', 'X', '0', '1', 'L', 'W', 'L', 'W', 'X' ), -- | L |
            ( 'U', 'X', '0', '1', 'H', 'W', 'W', 'H', 'X' ), -- | H |
            ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' )  -- | - |
        );
        
    FUNCTION resolved ( s : std_ulogic_vector ) RETURN std_ulogic IS
        VARIABLE result : std_ulogic := 'Z';  -- weakest state default
    BEGIN
        -- the test for a single driver is essential otherwise the
        -- loop would return 'X' for a single driver of '-' and that
        -- would conflict with the value of a single driver unresolved
        -- signal.
        IF    (s'LENGTH = 1) THEN    RETURN s(s'LOW);
        ELSE
            FOR i IN s'RANGE LOOP
                result := resolution_table(result, s(i));
            END LOOP;
        END IF;
        RETURN result;
    END resolved;

    -------------------------------------------------------------------
    -- tables for logical operations
    -------------------------------------------------------------------

    -- truth table for "and" function
    CONSTANT and_table : stdlogic_table := (
    ------------------------------------------------------
    --      |  U    X    0    1    Z    W    L    H    -         |   |
    ------------------------------------------------------
            ( 'U', 'U', '0', 'U', 'U', 'U', '0', 'U', 'U' ),  -- | U |
            ( 'U', 'X', '0', 'X', 'X', 'X', '0', 'X', 'X' ),  -- | X |
            ( '0', '0', '0', '0', '0', '0', '0', '0', '0' ),  -- | 0 |
            ( 'U', 'X', '0', '1', 'X', 'X', '0', '1', 'X' ),  -- | 1 |
ETC. for about thirty more pages.

LIBRARY and USE Statements

There are two special libraries explicitly prescribed by VHDL:

LIBRARY Statements

USE Statements


Copyright 1998, Ben M. Huey
Copying this document without the permission of the author is prohibited and a violation of international copyright laws.

Rev. 1/29/98 B. Huey