Beruflich Dokumente
Kultur Dokumente
Verilog
Tutorial
Watch Design
R
R
The following table shows the revision history for this document.
Design Description
The design used in this tutorial is a hierarchical, HDL-based design. The top-level design file is an
HDL file that references several other lower-level macros. The lower-level macros are either HDL
modules or CORE Generator modules.
The tutorial begins with an unfinished design. You will complete the design by generating some of
the modules from scratch, and by completing other modules from existing files. When the design is
complete, it is simulated to verify functionality.
The Watch design is intended to perform like a track coach’s stopwatch. There are three external
inputs, and three external output buses in the completed design. The system clock is an externally
generated signal. The inputs, outputs, and functional blocks are listed below.
Inputs
• STRTSTOP — This is an active low signal that starts and stops the stopwatch.
• RESET—Resets the stopwatch to 00.0 after it has been stopped.
• CLK—Externally generated system clock.
Outputs
• TENSOUT[6:0]—7-bit bus that represents the tens digit of the stopwatch value. This bus is in
7-segment display format as viewable on the 7-segment LED display on the Xilinx
demonstration board.
• ONESOUT[6:0]—Similar to TENSOUT, but represents the ones digit of the stopwatch value.
• TENTHSOUT[9:0]—10-bit one-hot encoded bus that represents the tenths digit of the
stopwatch value.
Functional Blocks
• STATMACH
State Machine module.
• CNT60
HDL-based module that counts from 0 to 59 in decimal. This macro has two 4-bit outputs that
represent the ones and tens digits of the decimal values, respectively.
• TENTHS
CORE Generator 4-bit, binary encoded counter. This macro outputs a 4-bit code that is decoded
to represent the tenths digit of the stopwatch value as a 10-bit one-hot encoded value.
• HEX2LED
HDL-based macro. This macro decodes the ones and tens digit values from hexadecimal to 7-
segment display format.
• SMALLCNTR
A simple counter.
Tutorial Installation
The Watch tutorial file is available for download from the Xilinx Web site at
http://support.xilinx.com/support/techsup/tutorials.
Directory Description
mti_vlog/watch working directory
mti_vlog/watch_source Verilog source and script files
mti_vlog/watch_solution Verilog solution files
Script Files
The following script files are provided to automate the steps in this tutorial.
• rtl_sim.do
• stim.do
• time_sim.do
Verilog Libraries
To simulate the Watch design, you need the following simulation libraries.
UniSim Library
The UniSim library is used for functional simulation only. The models in this library contain only
unit delays. This library includes all Xilinx Unified Library primitives that are inferred by most
popular synthesis tools.
For Verilog, separate libraries are provided for common technologies that share the same
functionality. This combined library makes it easy to retarget designs to other technologies. It is not
necessary to change the library mapping statements when switching from Virtex™ to Virtex-E or
from Spartan™ to Virtex.
The Verilog UniSim Library source files are provided in $XILINX/verilog/src/unisims (Series 4KE,
4KX, 4KL, 4KXV, Spartan, Virtex).
SimPrim Library
The SimPrim library is used for post-NGDBuild (gate-level functional), post-Map (partial timing),
and post-PAR (full timing) simulations. This library is architecture independent.
The Verilog SimPrim Library source files are provided in $XILINX/verilog/src/simprims.
- Operation: Up
Defines how the counter will operate. This field is dependent on the type of module you
select.
- Count Restrictions: Restrict Count to A
This specifies the maximum count value.
- Output Options: Threshold 0 set to A
Signal goes high when the value specified has been reached.
- Output Options: Registered
8. Click on the Register Options button to open the Register Options dialog box. Enter the
following settings.
- Clock Enable: Selected
- Asynchronous Settings: Init with a value of 1
- Synchronous Settings: None
Click OK.
- coregen.prj
Stores the CORE Generator configuration for the project
RTL Simulation
RTL-level (behavioral) simulation allows you to verify or simulate a description at the system or
chip level. This first pass simulation is typically performed to verify code syntax, and to confirm that
the code is functioning as intended. At this step in the tutorial, no timing information is provided and
simulation is performed in a unit-delay mode to avoid the possibility of a race condition.
RTL simulation is not architecture-specific unless the design contains instantiated UniSim, CORE
Generator, or LogiBLOX components.
A general suggestion during the initial design creation is to keep the code behavioral. Avoid
instantiating specific components unless necessary. This allows for more readable code, faster and
simpler simulation, code portability (the ability to migrate to different device families) and code
reuse (the ability to use the same code in future designs). However, you may find it necessary to
instantiate components structurally in order to obtain the desired design structure or performance.
It is important to address the built-in reset circuitry behavior in a design starting with the first
simulation to ensure that subsequent simulations agree at different points.
Virtex devices have register (flip-flops and latches) set/reset circuitry that pulses at the end of the
configuration mode. This pulse is automatic and does not need to be programmed. All the flip-flops
and latches receive this pulse through a dedicated global set/reset (GSR). The registers either set or
reset, depending on how the registers are defined.
If the you do not simulate GSR behavior prior to synthesis and PAR, the RTL and possibly post-
synthesis simulations will not initialize to the same state as the post-route timing simulation. As a
result, various design descriptions are not functionally equivalent and simulation results will not
match.
Even if GSR behavior is not described, the actual chip initializes during configuration, and the post-
route netlist will have this net that must be driven during simulation.
In addition to the set/reset pulse, all output buffers are tristated during configuration mode with the
dedicated global output tristate enable (GTS) net.
Starting ModelSim
If you are using the PC, invoke the simulator by selecting the following from the Start menu.
Programs → Model Tech → ModelSim
For UNIX workstations, type the following at the prompt.
vsim -i &
Set the project directory using the File → Change Directory menu command and select watch/rtl.
• stopwatch_tb.v
• rtl_sim.do
• glbl.v
3. In the Structure window, notice that Verilog modules are indicated by circles. You can expand
and collapse regions of hierarchy by clicking on the (+) and (-) notations.
4. To run the simulation for a specified amount of time at the ModelSim prompt, type the
following.
run 100000 ns
The simulation output is displayed in the Wave window. You may have to zoom in or out to
view the waveforms.
5. In the Wave window, try adding or removing cursors with the Cursor → Add | Remove menu
command. When multiple cursors are drawn, ModelSim adds a delta measurement showing the
time difference between the cursors. The selected cursor is drawn as a solid line and the values
at the cursor location are shown to the right of the signal name. All other cursors are drawn as
dotted lines. If you cannot see the signal value next to the signal name, select the bar separating
the signal names from the waveforms and drag it to the right.
Note: The above commands have been combined into a macro file called stim.do that you can
run at the ModelSim prompt.
Before you implement the Watch design with the Xilinx Design Manager, you need to set the
Implementation Options Timing Template to ModelSim Verilog to produce the time_sim.v file, and
time_sim.sdf for timing simulation. To set these options, follow these steps.
1. In the Design Manger Implement window, select Design → Options to open the Options dialog
box.
2. In the Program Options section of the dialog box, set Simulation to ModelSim Verilog.
7. View and add the signals of the design to the waveform window.
8. At the ModelSim prompt, type.
run 100000 ns
9. To zoom in, right click in the waveform window, or press and hold the middle mouse button and
draw a square around the area you want to zoom in on. After simulating, you can zoom in and
view the delay from the clock edge to the TENSOUT, ONESOUT, and TENTHSOUT output
change.
Note: The above commands are included in the macro file, time_sim.do, and can be executed at
the ModelSim prompt.
The MTI ModelSim Vlog/Xilinx Tutorial is now completed!