Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Data Types and Signals

std_logic and Other Basic Types

Learn VHDL's basic types: bit, boolean, integer, time, and the nine-valued std_logic with 0, 1, Z, X, U, L, H, W and dash, plus resolution and type conversion rules.

VHDL is strongly typed: every signal, constant and variable has exactly one type, and the compiler refuses to mix types silently. This feels strict at first, but it catches many errors, such as adding a bit to an integer or assigning a 4-bit bus to an 8-bit bus, before a single simulation runs.

Predefined types (package standard)

Type Values Typical use
bit '0', '1' Two-valued logic (rarely used for real designs)
boolean false, true Conditions, flags in generics
integer at least -2^31+1 to 2^31-1 Counters in testbenches, indexes, generics
natural, positive subtypes of integer (โ‰ฅ 0, โ‰ฅ 1) Sizes, widths
real floating point Simulation only, not synthesizable
character, string text Reports and messages
time 10 ns, 1 us ... Delays and waits in simulation

bit has only two values, which is too few for real hardware. Wires can be undriven, driven by two devices, or have an unknown value. For this reason, nearly all hardware ports use std_logic.

std_logic: nine values

std_logic is defined in ieee.std_logic_1164. Its nine values are:

Value Meaning
'U' Uninitialized: nothing has been assigned yet (simulation start)
'X' Forcing unknown: conflict between two strong drivers
'0' Forcing 0
'1' Forcing 1
'Z' High impedance: nobody drives the wire
'W' Weak unknown
'L' Weak 0 (like a pull-down)
'H' Weak 1 (like a pull-up)
'-' Don't care

For synthesis you use '0', '1', 'Z' (at tri-state pins) and sometimes '-'. The others, 'U', 'X', 'W', 'L', 'H', matter in simulation: seeing 'U' in a waveform tells you a signal was never assigned (often a missing reset), and 'X' tells you a conflict or a bad operation happened.

std_logic values to remember

'0' and '1' Normal driven values
'U' Never assigned
'X' Conflict or unknown
'Z' Released, tri-state

Read 'U' and 'X' as bug reports from the simulator.

1 / 2

std_logic is a resolved type

Several drivers may connect to one std_logic signal. A resolution function combines them. Rules in short: 'Z' loses to anything, equal strong values give that value, and two different strong values give 'X'. This is what Entity Declarations previewed with the shared bus.

The type std_ulogic is the same nine values without resolution: two drivers become a compile-time error. Some teams use it on purpose so accidental multiple drivers are caught early. In VHDL-2008, std_logic is simply a resolved subtype of std_ulogic.

Logic operators and tables

The operators and, or, not, xor are defined on std_logic through tables. For example, '0' and 'X' is '0' (a zero forces the AND), but '1' and 'X' is 'X'. This stand-in reproduces a reduced version of the table (values 0, 1, X, U) so you can see how unknowns spread:

C Stand-in (C): and / or with unknown values

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Integer ranges and subtypes

integer is a 32-bit type in practice. A subtype restricts a type's range:

VHDL
subtype byte_range is integer range 0 to 255;
signal  counter : integer range 0 to 9;     -- an anonymous subtype

The simulator checks the range at run time and stops with an error if you exceed it; the synthesizer sizes the hardware (4 bits for 0 to 9). Integers are ideal for counters inside testbenches and for generics. For signals that appear on pins, prefer std_logic_vector, signed or unsigned, which have fixed, explicit bit widths.

Type conversion

VHDL does not convert types implicitly. You use conversion functions or type casts. Closely related array types can be cast:

VHDL
signal u : unsigned(7 downto 0);
signal v : std_logic_vector(7 downto 0);

v <= std_logic_vector(u);      -- closely related types: a cast is allowed
u <= unsigned(v);
n <= to_integer(u);            -- unsigned -> integer (function)
u <= to_unsigned(n, 8);        -- integer -> unsigned of 8 bits

Unrelated types need functions: to_integer and to_unsigned live in numeric_std (Numeric Arithmetic). A bit-to-std_logic conversion is to_stdulogic(b).

Seeing "no function declarations for operator" or "type mismatch" errors is normal at first. Read the types on both sides of the operator; the fix is almost always a missing conversion or a missing use ieee.numeric_std.all;.

Range checking and wrap-around

Integers in simulation stop with an error when out of range, but bit vectors silently wrap around, just like hardware. The second stand-in shows the difference: a 4-bit counter (hardware) rolls over, whereas a checked integer subtype 0 to 9 would raise an error.

C Stand-in (C): vector wrap vs range error

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a 'U' in a std_logic waveform tell you?

    'U' means uninitialized; often the cause is a missing reset or an unconnected input.
  2. 2. Two strong drivers, one driving '0' and the other '1', share a std_logic signal. What is its value?

    The resolution function returns 'X' for conflicting strong drivers.
  3. 3. Which type is NOT synthesizable for hardware signals in general?

    Real numbers are used in simulation and constants; most synthesizers do not implement floating-point signals.
  4. 4. How do you convert an unsigned signal u to an integer?

    numeric_std provides to_integer for unsigned and signed values.

Summary

  • VHDL is strongly typed; conversions must be explicit.
  • Use std_logic (nine values) for signals; 'U' and 'X' expose bugs in simulation.
  • std_logic is resolved, so multiple drivers combine; std_ulogic is unresolved.
  • integer is for counters, indexes and generics; subtypes restrict ranges.
  • Casts work between closely related array types; to_integer and to_unsigned convert numbers.

Next: Signals and Variables