Difference between revisions of "VHDL tutorial"

From UConn PAN
Jump to navigation Jump to search
 
(39 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{| align="right" border="1"
 +
|
 +
{| align="right" width="100px" style="text-align:center" cellspacing="0"
 +
! colspan="2" style="background:#ffff66" | VHDL Tutorial
 +
|-
 +
| colspan="2" style="background:#ffff99" | A brief guide to VHDL design with a design example; the introduction and core of the tutorial.
 +
|-
 +
| style="background:#ffff66" | < prev
 +
| style="background:#ffff66" | [[VHDL: Where to start|next >]]
 +
|}
 +
|}
 +
 
FPGA programming using a hardware description language is not a commonly taught skill in physics programs, but is a necessary skill for designing the electronics required for this project.  This tutorial aims to layout the design process and teach the basics of hardware description language; in particular [http://en.wikipedia.org/wiki/Vhdl VHDL].  The main competitor to VHDL is [http://en.wikipedia.org/wiki/Verilog Verilog]; tutorials and information regarding Verilog can be found through Google web searching.
 
FPGA programming using a hardware description language is not a commonly taught skill in physics programs, but is a necessary skill for designing the electronics required for this project.  This tutorial aims to layout the design process and teach the basics of hardware description language; in particular [http://en.wikipedia.org/wiki/Vhdl VHDL].  The main competitor to VHDL is [http://en.wikipedia.org/wiki/Verilog Verilog]; tutorials and information regarding Verilog can be found through Google web searching.
  
 
== Design example ==
 
== Design example ==
  
To illustrate the discussions in this tutorial, a design example is discussed along the way.  The design example is the [[http://zeus.phys.uconn.edu/wiki/index.php?title=Programming_the_FPGA#Emulator_.28D.29|emulator for the AD5535 DAC]].  As each step of the design process is discussed, the DAC emulator will be used for illustration.
+
To illustrate the discussions in this tutorial, a design example is discussed along the way.  The design example is the [[Programming_the_DAC#Emulator|emulator for the AD5535 DAC]].  As each step of the design process is discussed, the DAC emulator will be used for illustration.
  
== Where to start ==
+
== The tutorial ==
  
=== The black box ===
+
Due to the length of the tutorial, it had to be broken into several pages.  Here are the links to the various sections of the tutorial.  The first three sections discuss VHDL itself.  The final section is about using the development environment provided by Xilinx; you can read this section first or last as you see fit.
  
The first part of the design process is completely independent of any code.  The first step is to define the "black box" of your circuit; that is, draw a box and say what goes in and what comes out. VHDL allows three types of ''pins'' (connections to the outside world):
+
* [[VHDL: Where to start]] - Section one of the tutorial, focusing on preparing your design for coding.
* '''in''': An ''in'' pin can be read from but never written to.
+
* [[VHDL: Enter the code monkey]] - Section two of the tutorial, focusing on outlining the framework of your code.
* '''out''': An ''out'' pin can be written to but never read from.
+
:''See also: [http://en.wikipedia.org/wiki/Code_monkey code monkey]''
* '''inout''': An ''inout'' pin can be both read from and written to, providing the flexibility to allow bidirectional communication on a single line.  At first this seems the ideal choice and that you would always want inout pins; in actual fact you want to avoid inout pins unless you absolutely need them for bidirectional communication.
+
* [[VHDL: The real code]] - Section three of the tutorial, focusing on coding the body of your design.
 +
* [[VHDL: Xilinx ISE]] - Section four of the tutorial, focusing on using the development environment.
  
Some notes on nomenclature and notation:
+
== Extras ==
* The term '''signal''' is used to generically refer to a line, pin, or bus.
 
* Signals come in '''active-high''' and '''active-low''' varieties.  Active-high means that a logical 1 is "on" and a logical 0 is "off".  It is also known as "positive logic".  Active-low is the exact opposite; logical 0 is "on" and logical 1 is "off", and it is alternately known as "negative logic".
 
* Some signals serve double-duty.  As active-high logic they perform one operation, but as active-low logic they perform another operation.  This links these operations as complimentary pairs.  For example a shift register may shift its output or it may load a new value.  If it's not shifting then it's loading.  So the name would be something like "Shift/Load" to signify that shifting is active-high and loading is active-low.  Carrying over this notation, any signal that is written "/Name" is an active-low signal.  This notation is not always used, but it is quite common and I shall attempt to maintain this practice throughout the tutorial.  When writing on paper, an active-low signal is frequently denoted by an overbar instead of a leading slash.  Unless otherwise specified, a signal that is not marked as active-low is assumed to be active-high by default.  Some designs assume active-low as the default, but that will either be marked or implied by context (i.e. all active-high lines marked as such).
 
* A '''pin''' is an input, output, or inout.  A '''line''' is a single pin or a single bit of data flowing along a wire.  A '''bus''' is properly a multidrop line, but through common usage (due to the way circuits are commonly designed), in digital logic at this level the term has come to mean multiple lines bound together into a bundle.  On a diagram, a bus appears as a thick line with a slash through it.  Near the slash will be a number denoting how many lines are bundled into that bus.
 
  
=== Example: the block box ===
+
Here is some extra information regarding VHDL to be used as reference material.
  
For the DAC emulator, the inputs are clearly defined for us.  The AD5535 data sheet discusses the [[http://zeus.phys.uconn.edu/wiki/index.php?title=Programming_the_FPGA#Interface_.28D.29|serial interface protocol]] in detail.  We need four input lines:
+
=== VHDL Resolution Table ===
* ''/Reset'': an asynchronous, active-low reset line
 
* ''D_in'': serial data line
 
* ''/Sync'': an active-low flag to being transmission
 
* ''SClk'': a serial clock
 
 
 
Our outputs are not so clearly defined.  This emulates the circuit itself, so the output of the black box is purely for our benefit to aid in testing.  So I decided to define as outputs 32 channels, each 14-bits wide, which display the value being fed to each DAC at any given time.
 
 
 
=== The block diagram ===
 
 
 
Having defined your block box, you need to fill in your black box.
 
  
 +
VHDL STD_LOGIC and STD_LOGIC_VECTOR both operate on 9-value logic defined by IEEE.  The nine states are:
 +
* U: uninitialized
 +
* X: forcing unknown
 +
* 0: forcing 0
 +
* 1: forcing 1
 +
* Z: high impedance
 +
* W: weak unknown
 +
* L: weak 0
 +
* H: weak 1
 +
* &#8211;: don't care
  
 
+
If you have two or more drivers for the same line, then VHDL must somehow resolve the conflict.  The resolution table is given below.
== VHDL Resolution Table ==
 
  
 
{| style="text-align:center"
 
{| style="text-align:center"
|+VHDL Resolution Table
+
|+ '''VHDL Resolution Table'''
 
|-
 
|-
!  !! U !! X !! 0 !! 1 !! Z !! W !! L !! H !! -
+
!  !! U !! X !! 0 !! 1 !! Z !! W !! L !! H !! &#8211;
 
|-
 
|-
 
! U
 
! U
Line 67: Line 75:
 
| U || X || 0 || 1 || H || W || W || H || X
 
| U || X || 0 || 1 || H || W || W || H || X
 
|-
 
|-
! -
+
! &#8211;
 
| U || X || X || X || X || X || X || X || X
 
| U || X || X || X || X || X || X || X || X
 
|}
 
|}
  
VHDL Logic States
+
=== Links ===
* U: uninitialized
+
 
* X: forcing unknown
+
In case you can't follow the near-incoherent ramblings that constitute my tutorial, here are links to some others.  And always remember: Google is a programmer's best friend.
* 0: forcing 0
+
* http://esd.cs.ucr.edu/labs/tutorial/
* 1: forcing 1
+
* http://www.vhdl-online.de/tutorial/
* Z: high impedance
 
* W: weak unknown
 
* L: weak 0
 
* H: weak 1
 
* -: don't care
 

Latest revision as of 18:55, 17 July 2007

VHDL Tutorial
A brief guide to VHDL design with a design example; the introduction and core of the tutorial.
< prev next >

FPGA programming using a hardware description language is not a commonly taught skill in physics programs, but is a necessary skill for designing the electronics required for this project. This tutorial aims to layout the design process and teach the basics of hardware description language; in particular VHDL. The main competitor to VHDL is Verilog; tutorials and information regarding Verilog can be found through Google web searching.

Design example

To illustrate the discussions in this tutorial, a design example is discussed along the way. The design example is the emulator for the AD5535 DAC. As each step of the design process is discussed, the DAC emulator will be used for illustration.

The tutorial

Due to the length of the tutorial, it had to be broken into several pages. Here are the links to the various sections of the tutorial. The first three sections discuss VHDL itself. The final section is about using the development environment provided by Xilinx; you can read this section first or last as you see fit.

See also: code monkey
  • VHDL: The real code - Section three of the tutorial, focusing on coding the body of your design.
  • VHDL: Xilinx ISE - Section four of the tutorial, focusing on using the development environment.

Extras

Here is some extra information regarding VHDL to be used as reference material.

VHDL Resolution Table

VHDL STD_LOGIC and STD_LOGIC_VECTOR both operate on 9-value logic defined by IEEE. The nine states are:

  • 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

If you have two or more drivers for the same line, then VHDL must somehow resolve the conflict. The resolution table is given below.

VHDL Resolution Table
U X 0 1 Z W L H
U U U U U U U U U U
X U X X X X X X X X
0 U X 0 X 0 0 0 0 X
1 U X X 1 1 1 1 1 X
Z U X 0 1 Z W L H X
W U X 0 1 W W W W X
L U X 0 1 L W L W X
H U X 0 1 H W W H X
U X X X X X X X X

Links

In case you can't follow the near-incoherent ramblings that constitute my tutorial, here are links to some others. And always remember: Google is a programmer's best friend.