VHDL Scalar Data Types and Testbench Implementation

VHDL Scalar Data Types

Scalar data types are data types that contain a single value at a time. The values in scalar types are arranged in a sequential order. Scalar data types are used to represent numbers, logic values, characters, physical quantities, and more. These include Enumeration Types, Integer Types, Floating Point (Real) Types, and Physical Types.

Enumeration Types

An enumeration type contains a list of identifiers or character literals. The syntax is: TYPE type_name IS (value1, value2, value3);

The predefined enumeration types in VHDL are:

  • BIT Type: The BIT type has only two values: TYPE BIT IS ('0', '1');. It is used to represent binary logic values.
  • BOOLEAN Type: The BOOLEAN type has two values: BOOLEAN IS (FALSE, TRUE);. It is used in logical and conditional operations.
  • CHARACTER Type: The CHARACTER type represents ASCII characters. Example: (‘A’ to ‘Z’).
  • STD_LOGIC Type: Defined in the IEEE library:
    LIBRARY ieee; USE ieee.std_logic_1164.all;

STD_LOGIC contains nine logic values:

  • U: Uninitialized
  • X: Unknown
  • 0: Logic 0
  • 1: Logic 1
  • Z: High impedance
  • W: Weak unknown
  • L: Weak low
  • H: Weak high
  • : Don’t care

STD_LOGIC is the most commonly used data type in VHDL.

Integer Types and Subtypes

The Integer Type represents whole numbers. The syntax is: TYPE INTEGER IS RANGE low TO high;. For example: TYPE COUNT IS RANGE 0 TO 255;. The predefined INTEGER range is -2,147,483,647 to +2,147,483,647.

Integer Subtypes

  • NATURAL: Stores non-negative integers. SUBTYPE NATURAL IS INTEGER RANGE 0 TO INTEGER'HIGH;
  • POSITIVE: Stores positive non-zero integers. SUBTYPE POSITIVE IS INTEGER RANGE 1 TO INTEGER'HIGH;

Floating Point (REAL) Type

The Floating Point (REAL) Type represents floating point numbers. The syntax is: TYPE REAL IS RANGE low TO high;. For example: VARIABLE X : REAL := 10.5;. The range of the REAL type is -1.0E+38 to +1.0E+38. It is mainly used in mathematical calculations and simulations.

Physical Types and Units

Physical Types represent physical quantities such as time, current, voltage, and resistance. The predefined physical type in VHDL is TIME.

TIME Units: fs, ps, ns, us, ms, sec, min, hr. Example: SIGNAL delay : TIME := 10 ns;

User-Defined Physical Type:
TYPE CURRENT IS RANGE 0 TO 1000 UNITS: nA; uA = 1000 nA; mA = 1000 uA; A = 1000 mA; END UNITS;

Advantages of Scalar Data Types

  • Simple representation of single values
  • Easy hardware modeling
  • Efficient simulation and synthesis
  • Used in arithmetic and logical operations
  • Supports sequential ordering of values

Full Adder Testbench Code Example

Testbench code (full adder):

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY tb_fulladder IS
END tb_fulladder;

ARCHITECTURE behavior OF tb_fulladder IS
    COMPONENT fulladder
        PORT(
            a, b, cin : IN STD_LOGIC;
            sum, carry : OUT STD_LOGIC
        );
    END COMPONENT;

    SIGNAL a, b, cin, sum, carry : STD_LOGIC;

BEGIN
    UUT : fulladder
    PORT MAP(a, b, cin, sum, carry);

    stim_proc : PROCESS
    BEGIN
        a <= '0'; b <= '0'; cin <= '0';
        WAIT FOR 10 ns;
        a <= '0'; b <= '0'; cin <= '1';
        WAIT FOR 10 ns;
        a <= '0'; b <= '1'; cin <= '0';
        WAIT FOR 10 ns;
        a <= '0'; b <= '1'; cin <= '1';
        WAIT FOR 10 ns;
        a <= '1'; b <= '0'; cin <= '0';
        WAIT FOR 10 ns;
        a <= '1'; b <= '0'; cin <= '1';
        WAIT FOR 10 ns;
        a <= '1'; b <= '1'; cin <= '0';
        WAIT FOR 10 ns;
        a <= '1'; b <= '1'; cin <= '1';
        WAIT FOR 10 ns;
        WAIT;
    END PROCESS;
END behavior;