Difference between revisions of "VHDL"
Line 2: | Line 2: | ||
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. | VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. | ||
− | = Structure and Behaviour = | + | = Structure and Behaviour = |
+ | There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system. | ||
+ | |||
+ | == Structure == | ||
+ | <span class="mw-customtoggle-Structure" style="font-size:small; display:inline-block; "><span class="mw-customtoggletext" data-expandtext="Illuminate" data-collapsetext="Deluminate">[Show/hide]</span></span> | ||
+ | <div id="mw-customcollapsible-Structure" class="mw-collapsible mw-collapsed"> | ||
+ | The structure of a system describes that system in terms of "what is connected to what". The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports. | ||
+ | |||
+ | TODO: IMAGE | ||
+ | |||
+ | In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type. | ||
+ | </div> | ||
+ | |||
+ | == Behaviour == | ||
+ | <span class="mw-customtoggle-Behaviour" style="font-size:small; display:inline-block; "><span class="mw-customtoggletext" data-expandtext="Illuminate" data-collapsetext="Deluminate">[Show/hide]</span></span> | ||
+ | <div id="mw-customcollapsible-Behaviour" class="mw-collapsible mw-collapsed"> | ||
+ | You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak. | ||
+ | </div> | ||
+ | |||
+ | == Entities == | ||
+ | <span class="mw-customtoggle-Entities" style="font-size:small; display:inline-block; "><span class="mw-customtoggletext" data-expandtext="Illuminate" data-collapsetext="Deluminate">[Show/hide]</span></span> | ||
+ | <div id="mw-customcollapsible-Entities" class="mw-collapsible mw-collapsed"> | ||
+ | As we have mentioned an entity is a "box" with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this: | ||
+ | |||
+ | <pre> | ||
+ | entity hadder is | ||
+ | port | ||
+ | ( inA, inB: in std_logic; | ||
+ | sum,carry: out std_logic); --note the semicolon | ||
+ | end hadder; | ||
+ | </pre> | ||
+ | |||
+ | This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here: | ||
+ | |||
+ | TODO: IMAGE | ||
+ | </div> | ||
+ | |||
+ | == Architectures == | ||
+ | <span class="mw-customtoggle-Architectures" style="font-size:small; display:inline-block; "><span class="mw-customtoggletext" data-expandtext="Illuminate" data-collapsetext="Deluminate">[Show/hide]</span></span> | ||
+ | <div id="mw-customcollapsible-Architectures" class="mw-collapsible mw-collapsed"> | ||
+ | Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one. | ||
+ | |||
+ | Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows: | ||
+ | |||
+ | TODO: IMAGE | ||
+ | |||
+ | Here is an example of structural description: | ||
+ | <pre> | ||
+ | architecture structure of hadder is | ||
+ | --We now need to describe the interface to the components that we are | ||
+ | --using. These components are described in the ALTERA MAXPLUS2 library. | ||
+ | component a_7408 --AND gate | ||
+ | port (a_2: in STD_LOGIC; | ||
+ | a_3: in STD_LOGIC; | ||
+ | a_1: out STD_LOGIC); | ||
+ | end component; | ||
+ | component a_7486 --XOR gate | ||
+ | port (a_2: in STD_LOGIC; | ||
+ | a_3: in STD_LOGIC; | ||
+ | a_1: out STD_LOGIC); | ||
+ | end component; | ||
+ | --Signals are like wires used to connect components | ||
+ | signal inputA,inputB : std_logic; | ||
+ | begin | ||
+ | --see equivalent diagram in notes to understand this. | ||
+ | inputA<=inA; | ||
+ | inputB<=inB; | ||
+ | myAND: a_7408 port map (a_2=>inputA,a_3=>inputB,a_1=>carry); | ||
+ | myXOR: a_7486 port map (a_2=>inputA,a_3=>inputB,a_1=>sum); | ||
+ | end structure; | ||
+ | </pre> | ||
+ | |||
+ | The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal "wires" which connect components together. The signals are inputA and inputB. | ||
+ | |||
+ | After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram. | ||
+ | </div> | ||
+ | |||
= Processes = | = Processes = | ||
= Variables = | = Variables = |
Revision as of 09:53, 16 July 2020
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here.
Contents
Structure and Behaviour
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.
Structure
[Show/hide]
The structure of a system describes that system in terms of "what is connected to what". The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.
TODO: IMAGE
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.
Behaviour
[Show/hide]
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.
Entities
[Show/hide]
As we have mentioned an entity is a "box" with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:
entity hadder is port ( inA, inB: in std_logic; sum,carry: out std_logic); --note the semicolon end hadder;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:
TODO: IMAGE
Architectures
[Show/hide]
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:
TODO: IMAGE
Here is an example of structural description:
architecture structure of hadder is --We now need to describe the interface to the components that we are --using. These components are described in the ALTERA MAXPLUS2 library. component a_7408 --AND gate port (a_2: in STD_LOGIC; a_3: in STD_LOGIC; a_1: out STD_LOGIC); end component; component a_7486 --XOR gate port (a_2: in STD_LOGIC; a_3: in STD_LOGIC; a_1: out STD_LOGIC); end component; --Signals are like wires used to connect components signal inputA,inputB : std_logic; begin --see equivalent diagram in notes to understand this. inputA<=inA; inputB<=inB; myAND: a_7408 port map (a_2=>inputA,a_3=>inputB,a_1=>carry); myXOR: a_7486 port map (a_2=>inputA,a_3=>inputB,a_1=>sum); end structure;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal "wires" which connect components together. The signals are inputA and inputB.
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.