What is the Difference Between Signal and Variable in VHDL

The main difference between signal and variable in VHDL is that a signal is an object with a past history of values, while a variable is an object with a single current value.

The VHDL is a popular HDL, which stands for High-Level Description Language. Generally, a digital circuit operates within two discrete levels – true and false. Here, the HDL helps to perform these operations. Furthermore, these languages have programming structures such as control structures, expressions, and statements. Moreover, the base languages for VHDL are Ada and Pascal.

Key Areas Covered

1. What is Signal in VHDL
     – Definition, Functionality
2. What is Variable in VHDL
     – Definition, Functionality
3. Difference Between Signal and Variable in VHDL
    – Comparison of Key Differences

Key Terms

HDL, Signal, Variable, VHDL

Difference Between Signal and Variable in VHDL - Comparison Summary

What is Signal in VHDL

Signals are equivalent to wires that denote the communication channels between concurrent statements of the system’s specification. Also, signals help to model inherent hardware features such as concurrency and buses with multiple driving sources. Furthermore, every signal has a history of values. It is also possible to have multiple drivers with the current value and protected future values. Moreover, the signal attributes help to access signals.

Difference Between Signal and Variable in VHDL

Programmers can declare the signals in the declarative part. Thus, the signals declared in a package are visible to all design entities using the package. Furthermore, some signals are only visible inside the architecture. Therefore, the signals declared in blocks are only to that specific block. Furthermore, if a signal is in a subprogram, those signals are visible only in that subprogram.

Below is a section of code with signal declaration. 

library IEEE;
use IEEE.Std_Logic_1164.all;
entity DataTransm is
  port (Data: Std_Logic_Vector(15 downto 0));
end entity DataTransm;
architecture ExDecl of DataTransm is
signal Temp: Std_Logic;
signal FlagC, FlagZ: Bit;
begin

Moreover, the signal declaration consists of single or multiple identifiers. And, each signal name is an identifier and creates an individual signal. Also, there can be a subtype indicator. Additionally, it is possible to assign an initial value in its declaration.

What is Variable in VHDL

Variable are objects which store information local to processes and subprograms in which they are defined. These values can be modified during simulation via variable assignment statements. Moreover, a variable declaration can include single or multiple identifiers, a subtype indication and an optional globally static expression. For an example, a code with variable declaration is as follows.

type Mem is array (Natural range <>, Natural range <>) of Std_Logic;
variable Delay1, Delay2: Time;
variable RAM1: Mem (0 to 1023, 0 to 8);

The default values of the variables are used to initialize that variable declared in the processes. In the beginning, they can be given either explicitly or implicitly. Each time a subprogram is called, the variables are declared in subprograms. However, the scope of variables is only limited to the defined process or subprogram. Nevertheless, this changes when there are multiple processes with a shared variable. But, it is important to avoid this kind of situation as it can provide unpredictable results.

Difference Between Signal and Variable in VHDL

Definition

A signal is a primary object describing a hardware system and is equivalent to “wires”. On the other hand, a variable is an object that stores the information that is local to the processes and subprograms (procedures and functions) in which they are defined. 

Basis

Thus, the main difference between signal and variable in VHDL is that a signal is an object with a past history of values, while a variable is an object with a single current value.

Syntax

variable variable_name : type; and variable variable_name : type := initial_value; are the syntaxes of signal in VHDL. On the other hand, signal signal_name: type; AND signal signal_name: type: = initial_value; are the syntaxes of variable in VHDL. Hence, this is another difference between Signal and Variable in VHDL.

Conclusion

In conclusion, electronic engineers and programmers use VHDL to design digital systems. Signal and variable are two objects in VHDL programming. However, the main difference between signal and variable in VHDL is that a signal is an object with a past history of values, while a variable is an object with a single current value.

References:

1.“Signal Declaration.” VHDL, Available here.
2.“Variable Declaration.” VHDL, Available here.

Image Courtesy:

1.”VHDL source for a signed adder” By Vhdl_signed_adder.png: RevRagnarokderivative work: Bernard Ladenthin – Own work, This file was derived from: Vhdl signed adder.png: (CC BY-SA 3.0) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply