Professional Documents
Culture Documents
The User Constraint File contains information regarding the physical aspect of the design as
it resides in the FPGA. Pin locations, timing constraints, and placement information is kept in
this file.
Specifications:
The following specifications are based on the high-level description presented
above. Each major specification is indicated with an integer and details
supporting that specification are provided as decimals under that integer.
During the processes of coding and writing test-benches, these numbers will be
referred to so that we know that all testable aspects of the design are covered. If
our specifications are well written and thorough, this will virtually guarantee that
our design will run as expected the first time we download it into the FPGA.
Although specifications are not the most exciting read, please pay close attention to
the use of shall which indicates that the design must absolutely and in all
circumstances (unless otherwise indicated) perform this behavior, while may
indicates that the design is allowed to perform this behavior, but is not required to.
1. The design shall communicate with a host device using an RS-232 serial
communication link.
1.1.The supported baud rate shall be 19,200 baud.
1.2.Eight (8) data bits shall be supported.
1.3.One (1) stop bit shall be supported.
1.4.No parity shall be supported.
1.5.The RS-232 serial communication link may be replicated via USB 2.
2. The design shall drive two LEDs as status monitors
2.1.The lower order LED shall illuminate for 2 seconds when either an alpha
character or symbol is received via the RS-232 communications channel.
2.2.The higher order LED shall illuminate for 2 seconds when either a numeric
character or symbol is received via the RS-232 communications channel.
2.3.When no information has been received for at least 1 second both LEDs shall
beunlit.
3. The design shall monitor four DIP switches.
3.1.Each switch shall be debounced3 for at least 50 ms.
USB Universal Serial Bus. Traditional RS-232 D type connectors are quite bulky and
require voltages typically no longer found on many demo boards. The Avnet LX-9 board
converts the RS-232 protocol into USB for higher speeds and smaller connectors.
3
When a mechanical switch is thrown, two pieces of conductor must either separate or
come together. This contact or breaking of contact often results in some vibration or
mechanical imperfections which cause the signal to ring or oscillate for some period of
time usually on the order of 100 us to 10 or more milliseconds depending on the quality of
the switch. A debouncing mechanism eliminates this ringing (which is seen by digital
circuitry as a stream of alternating 1s and 0s until the bouncing ends and a clear 1 or 0
emerges). An RC (resistor-capacitor) filter can be used as a first order low-pass filter which
provides a gradual rise or fall in voltage until the capacitor is full charged or discharged. This
technique relies on the input circuitry to threshold the voltage into the proper digital state.
While adequate for many needs, the presence of additional components on a board is
typically not welcome and the charging constants can only be changed with new
components and a soldering iron. Digital debouncing removes the need for external
components and costs only a little bit of logic inside the FPGA.
A
A
A
A
UART module for managing serial communications via the RS-232 port
mechanism that recognizes received values from the UART and drives LEDs
debouncer for each DIP switch.
means of coding the DIP switch to:
a. Recognize that the DIP switch has changed
b. Collect the 4 DIP switch values and convert to an ASCII pattern for
transmission
5) Finally, a module that ties all of these together.
Now that we have a basic idea of what we need, well need to see how its all strung
together
As we saw in the book (see Table 3.13 and corresponding section), we can start the
coding process by defining the interfaces for each module beginning at the top
level. Remember that the top level of the design becomes the pins on the FPGA.
While explicitly declaring buffers with specific capabilities is possible, for simplicitys
sake we will use the intrinsic ability of the Xilinx Synthesis Tools (XST) to
automatically insert the right type of buffer.
Everything that pierces the dotted line represents the outside world (i.e. not in the
FPGA) . Input and Output in the table below are from the FPGAs perspective
(that is, an input is a signal coming from off-chip into the FPGA). From this we
derive the following table
Signal
Name
Type
reset
clk
std_logic (input)
std_logic (input)
serialDataIn
std_logic (input)
serialDataO
ut
LED_hi
LED_lo
DIP
std_logic (output)
std_logic (output)
std_logic (output)
std_logic_vector(3
downto 0) (output)
Significance
Reset signal from on-board button
40 MHz signal from one of the on-board
sources
Data arriving via the RS-232/USB
interface
Data being sent to the RS-232/USB
interface
High order LED
Low order LED
4 lines coming from the DIP switch
The next module is that of the UART. Since weve covered the details in the book,
well just copy the interface information here with no further explanation regarding
either the UART or the subordinate modules it contains.
Since this component is completely contained within the top module, inputs and
outputs are all contained within the FPGA. Even though some of the signals pierce
the FPGA-outside world boundary, they are buffered through the top module.
Signal
Name
Type
reset
clk
serialDataIn
std_logic (input)
std_logic (input)
std_logic (input)
parallelData
Out
dataValid
std_logic_vector (7
downto 0) (output)
std_logic (output)
parallelDataI
n
transmitRequ
est
std_logic _vector(7
downto 0) (input)
std_logic (input)
ready
std_logic (output)
Significance
Reset signal from on-board button
40 MHz signal
Data arriving via the RS-232/USB
interface
De-serialized data which arrived via the
RS-232/USB interface
Indicates when parallelDataOut becomes
valid
Data to serialize for transmission via the
RS-232/USB interface to the user
Single pulse to begin transmitting the
data on parallelDataIn. Note: ready must
be de-asserted when transmitRequest is
asserted or the data will not be sent.
Indicates that the transmitter module
within the UART is not busy (i.e. ready to
begin a new transmission).
serialDataOu
t
std_logic (output)
The Character Decoder module is responsible for receiving data from the UART
receiver and deciding what to do with it. At this point in the development the how is
going to be deferred and we will focus only on the signal interface. From Figure 1 we
have
Signal Name
Type
clk
charFromUART_v
alid
charFromUART
std_logic (input)
std_logic (input)
LED_hi
std_logic _vector(7
downto 0) (input)
std_logic (output)
LED_lo
std_logic (output)
send_character
character_to_sen
d5
std_logic (output)
std_logic _vector(7
downto 0) (output)
Significance
40 MHz signal
Indicates when parallelDataOut
becomes valid
Data to serialize for transmission via
the RS-232/USB interface to the user
Asserts when received character is a
numeric character or symbol
Asserts when received character is an
alpha character or symbol
Asserts when character_to_send is valid
Character to echo to the user
Generic
Name
CLOCK_FREQUE
NCY
Type
integer
Significance
Frequency of the clock in Hertz.
Signal
Name
clk
send_characte
r
character_to_s
4
5
Type
Significance
std_logic (input)
std_logic (input)
40 MHz signal
Asserts when character_to_send is valid
std_logic _vector(7
end
tx_ready
downto 0) (input)
std_logic (input)
parallelDataIn
std_logic _vector(7
downto 0) (output)
std_logic (output)
transmitReque
st
DIP_dbncd
std_logic _vector(3
downto 0) (input)
Finally, the interface table for a single debouncer module. This module will be
replicated four times, one for each switch.
Signal
Name
Type
clk
signal_in
signal_out
std_logic (input)
std_logic (input)
std_logic (output)
Significance
40 MHz signal
Asserts when character_to_send is valid
Character to echo to the user
The debouncer can use one additional piece of information how long to debounce?
This information can be passed to the debouncer as a generic. In order for the delay
value to be interpreted correctly, the frequency of the clock must also be passed to
this component.
Generic
Name
Type
DELAY_VALUE
integer
CLOCK_FREQUE
NCY
integer
Significance
Indicates the number of clocks that an
incoming signal must be stable before
the output changes.
Frequency of the clock in Hertz.
At this point in the design process, all of the module ports have been defined. These
sources can be found in the following files: top_level_ports_only.vhd,
uart_ports_only.vhd, character_decode_ports_only.vhd,
character_encode_ports_only.vhd, and debouncer_ports_only.vhd.
From here filling in the detailed behavior of each module should be performed.
Following the same order of description from above, we have
Lab Design Top
The lab_design_top module shall be a structurally coded module which connects the
UART, character_decoder, character_encoder, and debouncers together and
connects them to the physical pins of the FPGA.
The ability to insert the proper buffers on the ports by the Xilinx Synthesis Tool
(XST) shall be leveraged; therefore, no explicit buffer definitions are required.
The modules shall be connected according to the Design Block Diagram (Figure 1)
above.
UART
The UART module and subordinate modules are thoroughly described in the book
VHDL 101 and are not repeated here.
Character decoder
The character decoder module is responsible for receiving an 8 bit ASCII encoded
character from the UARTs receiver module. This data is valid when the signal
dataValid is asserted (high). Upon receipt of a valid character the character_decoder
module must categorize the data into one of three groups: alpha character, numeric
character, or symbol character. If the character is an alpha character then LED_lo
shall be illuminated for 10 seconds. If the character is a numeric character, then
LED_hi shall be illuminated for 10 seconds. If the character is a symbolic character
then both LED_hi and LED_lo shall be illuminated for 10 seconds.
The time specification implies a timer based on the incoming clock.
Based on the description above, the character decoder module shall be constructed
as follows:
The decoding_table process shall be written as a process which takes the character
(when charFromUART_valid is asserted) and makes the request to the LED control
process as to which LEDs should be illuminated. When the character is decoded, the
timer shall be reset regardless of if a previous character was received within 10
second ago. The LED control module shall illuminate the requested LEDs then
discontinue after 10 seconds.
Now that the processes and connecting signals have been defined, this module can
be coded along with its test bench. See character_decoder.vhd and
character_decoder_tb.vhd.
Character Encoder
The main responsibility of the character encoder is to first monitor the state of the
DIP switches. If a change is seen then it must generate an ASCII hexadecimal
character and transmit it. It must also transmit any characters indicated by the
character decoder module. This leads the module to appear as:
Since there are two requesters and only one transmitter, there is a possibility of a
data collision; therefore, some type of collision avoidance or collision recovery
scheme is necessary. Since a human is controlling the DIP switches, it is a fair
assumption that this will occur very infrequently, certainly less than once per
character transmitted therefore, adding a single buffer to capture the new DIP
data is probably sufficient6. This buffer will hold the new value from the DIP switch
until the transmitter becomes ready.
Similarly, a buffer can be placed on the character_decoder side as well to provide a
single character hold. There is a bit more of a concern here as serial data can
(although it is unlikely) be streamed requiring the transmitter to transmit every
character as it arrives just to keep up with the incoming serial data. If the DIP switch
is changed during this time, then the new DIP switch value will be queued in its
buffer, but never have a chance to transmit until the serial stream abates.
This is an unlikely situation so we can assume 7 that this condition wont occur and
single buffer each incoming port.
The selector module must immediately buffer any characters being echoed (i.e.
coming from the character decoder module) and any character arriving from the DIP
encoder. A priority scheme can be developed so that echoed character have the
right of first refusal to be transmitted. That is, if there are both pending requests
from the character decoder and the DIP encoder, then the character decoder will
take precedence as serial data is anticipated to arrive more quickly than DIP
switches changing.
The selector module shall monitor the ready signal from the transmitter and
transmit any characters from the character decoder. If there is no character present,
then the selector module will pass a character from the DIP encoder. If there is no
character present, then the selector module waits for the next character to arrive
from either source. If both sources present on the same clock cycle, then the
character decoder shall take precedence. (Thus meeting Specification 5 and 5.1)
Debouncer
The debouncer is an adjustable mechanism which removes ringing from
mechanical switches and buttons. The basic operation is that each time a change is
seen on the input to the debouncer, a counter is restarted. The duration of that
6
The specification could be improved to cover this case which would describe how many DIP
switch changes must be buffered.
7
Assumptions are usually deadly as they are typically not documented! This assumption is
DOCUMENTED so that anyone reading this design description will understand that this was
a considered situation and should not occur in this way.
counter is programmable and is set to 100 ms. The general practice for selecting
the timing constant is to connect the switch to a digital sampling oscilloscope and to
trigger on movement in voltage. The trace will clearly see the ringing and measure
the time. Often several buttons or switches of the same type are tested and the
worst case values are selected.
The debouncer will ensure that the incoming signal is stable (either high or low)
before the output of the debouncer changes.
Lab for Using the Xilinx Tools:
1. Acquiring, Installing, and Launching the Xilinx Project Navigator Tool (webpack
version)
1.1.Open a browser and navigate to http://www.xilinx.com/tools/webpack.htm
1.1.1. Click download
1.1.2. Select ISE Design Suite 13.1 Full Product Installation > All Platforms
Note: you may download either the Windows or Linux version, or the combined
version.
1.1.3. Once downloaded, launch the installer. Accept the default choices.
1.2.Please unzip the source files to an easily accessible location. These source
files will be imported into PlanAhead so that simulation and
implementation can be run. Remember this location!
2. Creating a Project in PlanAhead. Begin by launching PlanAhead by doubleclicking on the desktop icon, or Start > All Programs > Xilinx Design Suite
13.1 > PlanAhead > PlanAhead
A. Create a new PlanAhead project by first selecting Create New Project at the
welcome screen. This will walk you through the process of creating a new
project including the selection of the device, adding sources, etc.
a) Select Create New Project
Figure 6 - Selecting "Create New Project" from the PlanAhead Welcome Screen
b) The initial dialog box is a welcome screen which begins the Create New
Project wizard. Click Next >.
c) The first dialog screen of the actual wizard asks you to select a project
name and location for this project. Please name this project VHDL101_lab.
You are free to place the project wherever you wish. If you choose to use
names and locations other than what is shown in the next screen shot,
please take note of them for later use.
Enter a project name and location, then press Next
d) The next dialog which appears asks which type of project you will be
creating. Since the VHDL sources are presented to you choose Specify
RTL Sources.
e) Next you will be able to select the sources to use for this project. Click
Add Files
f) Navigate to where you unzipped the source files. Select all source files
and click OK. When complete, the Add Sources dialog box will open.
Change the HDL Sources for to Simulation Only for all sources ending
in _tb (which refers to all the testbench files). Click Next when done.
g) The next dialog box invites you to add any IP (black box modules) to the
project. Since this project does not require any, click Next >.
h) The following dialog box invites you to add any User Constraint Files to the
project. The UCF contains timing and pin location information which is
necessary for the successful implementation of the design. A suitable UCF
for the Avnet LX-9 board has been provided for you. Select this file and
click Next.
i) Next you will select which part will be targeted. The Avnet LX-9 board
which uses a XC6LX9CSG324-1. Using the pull-down menus select General
Purpose > Spartan6 > Spartan6LX > CSG324 > -1. The following screen
shots will walk you through this process. Alternately you can type
XC6SLX9CSG324-2 into the search box and click Next to continue to the
summary screen, then Finish to complete the project creation.
3. Simulation
A number of the sources imported in the previous step are not synthesizable they
are intended for simulation only. There are a number of test-benches included for
this as well as modules which support simulation. All of these files must be marked
as simulation files which was done during the importing step. If you missed any, the
source can be marked for simulation by selecting the file name, right-clicking, and
selecting move to simulation source from the pop-up menu.
There are a number of simulation files these were used to validate various
modules during development and are provided here for your reference. We will
concern ourselves here with only the top level testbench.
a) Begin simulation by selecting Behavioral Simulation from the Project
Manager tab on the far left selection menu.
b) Once selected, the Launch Behavioral Simulation dialog box will open.
c) Click Launch to run the simulation with the selected options. The simulation
may take a few minutes depending on the type of computer you are running.
d) Expand the Board Signals group by clicking on the hierarchy arrow next to the
Board Signals name. This will show all the signals in this group.
e) Zoom out to show the entire 2.5 second simulation by either clicking the
icon or selecting View > Zoom > Zoom to full View.
Heres an explanation of what you are seeing:
View 1 Full Zoom Out
Notes the initial portion of the simulation (times 0 to 50 ms) exercise the serial
communication requirements and LED responses. Beginning at or near 400 ms the
DIP switches are exercised until about 2,200 us.
When you zoom to the range 1ms to about 45ms you can see the sequence of serial
character sent into the FPGA and the sequence of serial characters leaving the
FPGA. Note that other groups have been expanded to see key signals.
Zooming in even further you can see the individual serial bits being converted into
character bytes.
Finally, after the last character received, the LED Timer begins its final countdown
which completes at about 1300ms which causes the LEDs to turn off.
As an aside play with the ISim simulation tool it has many, many powerful
features including the relaunch feature which allows you to recompile and re-run
the simulation when you make changes to the source while in the ISim tool. Any
source can easily be reached by expanding lab_design_top_tb in the Instances
and Processes panel on the far left.
4. Implementation
Implementation is the process of converting the source code to a bitstream
which can be downloaded (Step 5) to the board. Two things to keep in mind
during the implementation phase make certain your User Constraint File(s)
(UCFs) are present (and correct) and that there are no timing errors.
The UCF(s) contain physical information regarding your design how fast it
should run, which signals attach to which pins, and if necessary, where certain
items are located inside the FPGA (floorplanning).
Timing Errors occur when there is not enough time for a signal to get from one
portion of the design to another. The tools report this in several places; the
easiest location to view this information is in the project summary.
The process of both writing good UCFs and achieving timing closure (making
certain that there are no timing errors) is a non-trivial matter and is handled
excellently in Xilinxs 2-day instructor led training Designing for Performance.
e) This opens the Generate Bitstream Options Dialog Box. You may choose to
leave the options in their default settings, or you may add a User ID code as
shown in the screenshot below. The User ID is often used to stamp a
bitstream to confirm that the desired bitstream was downloaded to the part.
Note that the 8 hex digit User Code below shows the date that the bitstream
was created (6 hex digits) plus a count code which can be used to indicate
a sequential number to distinguish one bitstream from another when created
on the same day.
Click OK to begin the bitstrem generation process.
f) When the bitstream generation process is complete, a dialog box will appear
to let you know that the process has completed. Click OK.
The USB-JTAG connection is found on the tapering end of the board. This
slides into any available USB slot on your computer. You may wish to put this
on a USB extension cable or hub so that you have easy access to the LEDs
and DIP switches.
The USB-RS-232 connection is made using a USB A/micro-B cable to the
micro-B USB connector located next to the large RJ-45 Ethernet connector.
The A side of the cable goes to your computer.
Power for the LX-9 board is provided through either of these cables.
Tool Connection
The tool connection consists of two aspects. First, additional software must be
installed on your machine to support the programming interface. Software
download and instructions can be found here:
http://www.digilentinc.com/Products/Detail.cfm?
NavPath=2,66,768&Prod=DIGILENT-PLUGIN
a) Once the programming software for this board is installed, you can launch
Xilinxs programming tool: iMPACT by expanding the Program and Debug
entry on the left side of the display and double-clicking iMPACT.
An error in connecting the cable dialog box will likely appear. Click OK to
acknowledge the problem. This will be fixed in the next step.
b) Since the LX-9 uses the Digilent programming hook, you will need to
designate a different cable then the default. This is initiated by selecting
Output > Cable Setup from the iMPACT menu line.
c) The Cable Setup dialog box invites you to choose how the download cable is
connected to the PC. Check the Cable Plug-In check box and either type or
select from the pull-down menu digilent_plugin. This will select the Digilent
Inc. communications software.
d) Click OK. iMPACT will now find the cable and connect to it.
e) Discover what is connected via the JTAG chain by clicking File > Initialize
Chain. All JTAG devices will appear in the work area. Click OK to confirm.
f) Right-click on the only FPGA in the chain xc6slx9 and select Assign New
Configuration File
Last notes:
A number of improvements can be made to this design.
The first is to reduce the clock frequency. The advantage to this is that slower
designs consume less power. Additional power and space is saved in the debouncer
in that a smaller counter can be built to cover the same amount of time. Alternately,
the DSP48 hard silicon device can be used as a counter which frees up FPGA fabric
and also reduces power.
Most FPGAs contain some form of clock management. Xilinxs Spartan-6 contains
both a Digital Clock Manager (DCM) and analog Phase Lock Loop (PLL). Both of
these devices have the ability to divide the incoming clock from 40 MHz down to
something more desirable. They also provide a signal which indicates that the clock
is stable. The inverse of the clock stable signal should then be routed to all the
modules which use reset. The reset signal from the button is then used to reset the
DCM or PLL.