Seguindo o tutorial da ALTERA para o MODELSIM

De MediaWiki do Campus São José
Ir para: navegação, pesquisa

Este tutorial ensina como utilizar o Modelsim para realizar a simulação funcional e também temporal. É requisito para a realização do tutorial o acesso ao software Quartus II e Modelsim ou Modelsim-ALTERA.

PASSO 1

/opt/altera/13.0sp1/modelsim_ase/bin/vsim
  • Para abrir o ModelSim ae (Versão Altera Edition) na CLOUD-IFSC ou nos Labs do IFSC, abra um terminal e digite:
/opt/altera/13.0sp1/modelsim_ae/bin/vsim
  • Para abrir o ModelSim a partir do Quartus II, é necessário primeiro se certificar que o caminho correto do ModelSim está configurado (Tools > License Setup > EDA Tool Options), e no campo [Location of Executable] do ModelSim-Altera insira o caminho correspondente ao versão ae ou ase. Em seguida faça a (Processing > Start > Analysis & Synthesis) do projeto. Em seguida abra o ModelSim (Tools > Run Simulation Tools > RTL Simulation).

PASSO 2 - Functional Simulation with ModelSim

Creating a Project

  • To create a project in ModelSim, select [File > New > Project...]
project name = serial_adder,
project location <= <subdiretorio do usuário>/Using_ModelSim/functional
default library name <= tutorial
copy settings field.
click [OK]
  • Since the file for this tutorial exists, click Add Existing File and select serial.vhd file.
  • Once the file is added to the project, it will appear in the Project tab
  • click [Close]

Compiling a Project

Compilation in ModelSim checks if the project files are correct and creates intermediate data that will be used during simulation.

  • select [Compile > Compile All]. A green check mark will appear to the right of the serial.vhd file in the Project tab.

Preparing Simulation

  • Put Modelsim in simulation mode by selecting [Simulate > Start Simulation...]
  • The window to start simulation consists of many tabs. For the purposes of the functional simulation, we only need to look at the Design tab.
  • In the Design tab you will see a list of libraries and entities you can simulate. In this tutorial, simulate a entity called serial.
  • To select this entity, scroll down and locate the tutorial library and click on the plus (+) sign.
  • You will see three entities available for simulation: FSM, serial, and shift_reg. Select the serial entity (Design Unit(s) = tutorial.serial) and click [OK] to begin simulation.
See the equivalent tcl command in Transcript window:
vsim tutorial.serial
  • Using the sim tab and the Objects window we can select signals for simulation. To add a signal to simulation, rightclick (with shift key) on the signals names in the Objects window and [select Add > To Wave > Selected Signals]. Add signals A, B, resetn, start, clock, sumfrom serial entity,
add wave  \
sim:/serial/A \
sim:/serial/B \
sim:/serial/start \
sim:/serial/resetn \
sim:/serial/clock \
sim:/serial/sum
  • Add signal current_state and counter from my_control component.
add wave  \
sim:/serial/my_control/current_state \
sim:/serial/my_control/counter
  • There are two ways to run a simulation in ModelSim: manually or by using scripts. In this tutorial, we perform the simulation manually.

Manual Simulation

  • To set the clock period, right-click on the clock signal and select Clock... from the pop-up menu.
[clock period = 100 ps], [first edge = falling edge] and click [OK].
  • To reset the circuit, set the resetn signal low by right-clicking on it and selecting the Force... from the pop-up menu.
[Value = 0] and [OK].
  • Set the value of the start signal to 0.
[Value = 0] and [OK].
force -freeze sim:/serial/clock 0 0, 1 {50 ps} -r 100
force -freeze sim:/serial/resetn 0 0
force -freeze sim:/serial/start 0 0
  • To run a simulation for 100 ps, set the value in the text field to 100 ps (default) and press the [Run] button.
run 
  • To test the serial adder we will add numbers A=143 and B=57 => sum=200.
  • To specify a value for A (B) in decimal, right-click on it, and choose Force... from the pop-up menu.
A [Value = 10#143] and [OK].
B [Value = 10#57] and [OK].
  • Set resetn to 1 to stop the circuit from resetting. Then set start to 1 to begin serial addition,
force -freeze sim:/serial/A 10#143 0
force -freeze sim:/serial/B 10#57 0
force -freeze sim:/serial/start 1 0
force -freeze sim:/serial/resetn 1 0
  • Change the radix of A and B signal. Highlight them in the simulation window, click right, and select [Radix > Unsigned]. Change the radix of the sum and counter signal to unsigned as well.
  • To complete the operation, the circuit will require 10 clock cycles. run 1000 ps using the Transcript command.
run 1000 ps [enter] (or)
run 1000 [enter]

Simulation with do file

  • Create a do file with all the transcript commands. [File > New > Open > Do] and [File > Save As...] serial_adder.do
# Preparing Simulation
vsim tutorial.serial
# Adding signal to wave
add wave  \
sim:/serial/A \
sim:/serial/B \
sim:/serial/start \
sim:/serial/resetn \
sim:/serial/clock \
sim:/serial/sum
add wave  \
sim:/serial/my_control/current_state \
sim:/serial/my_control/counter
# Defining clock and inicial reset and start value
force -freeze sim:/serial/clock 0 0, 1 {50 ps} -r 100
force -freeze sim:/serial/resetn 0 0
force -freeze sim:/serial/start 0 0
# Simulation of 1 clock periods
run 100
# Defing A = 143 and B = 57
force -freeze sim:/serial/A 10#143 0
force -freeze sim:/serial/B 10#57 0
# Redefining reset and start value
force -freeze sim:/serial/start 1 0
force -freeze sim:/serial/resetn 1 0
# Simulation of 10 clock periods 
run 1000
  • If needed restart the simulation
restart -force
  • type in transcript command
do serial_adder.do
  • Change the radix of A, B, sum and counter signal to unsigned. There is no tcl command for this.

Saving wave format

  • When the wave window is showing the right signal, radix and zoom, save the wave format. Select the wave windows and [File > Save Format ...] as wave.do in the current directory
  • Create a new do simulation file serial_add_v2.do, replacing the add commands with the command do wave.do
# Preparing Simulation
vsim tutorial.serial
# Adding signal to wave
do wave.do
# Defining clock and inicial reset and start value
force -freeze sim:/serial/clock 0 0, 1 {50 ps} -r 100
force -freeze sim:/serial/resetn 0 0
force -freeze sim:/serial/start 0 0
# Simulation of 1 clock periods
run 100
# Defing A = 143 and B = 57
force -freeze sim:/serial/A 10#143 0
force -freeze sim:/serial/B 10#57 0
# Redefining reset and start value
force -freeze sim:/serial/start 1 0
force -freeze sim:/serial/resetn 1 0
# Simulation of 10 clock periods 
run 1000

PASSO 3 - Timing Simulation with ModelSim

For Altera FPGA-based designs the delay information is available after the design is synthesized, placed and routed, and is generated by Quartus II CAD software.

Timing simulation of an entire design can be slow and should be avoided

See the gate level simulation supported device: https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/hb/qts/qts_qii53025.pdf page 1-2

Gate-level timing simulation of an entire design can be slow and should be avoided. Use TimeQuest static timing analysis rather than gate-level timing simulation

Make sure you go to assignement -> Settings -> EDA Tools Simulation -> generate functional simulation netlist -> turn it to off.

Setting up a Quartus II Project for Timing Simulation with ModelSim

  • To set up EDA Tools for simulation, open the Quartus II project serial.qpf in example/timing subdirectory, and select [Assignment > Settings... > EDA Tool Settings ]. Select the Tool Type = Simulation, Tool Name = ModelSim-Altera, Format = VHDL. click [OK]
  • Compile the project in Quartus II [Processing > Start Compilation]. The compilation process synthesizes, places, and routes the design, and performs timing analysis.
  • Then it stores the compilation result (serial.vho, and serial_vhd.sdo) in the simulation directory for ModelSim to use.

Running a Manual Timing Simulation

  • To create a project in ModelSim, select [File > New > Project...]
project name = serial_adder_timing,
project location <= <subdiretorio do usuário>/Using_ModelSim/timing
default library name <= tutorial
copy settings field.
click [OK]
  • Since the file for this tutorial exists, click Add Existing File and select serial.vho file, click [OK].
  • Once the file is added to the project, it will appear in the Project tab, click [Close]
  • Select [Compile > Compile All]. A green check mark will appear to the right of the serial.vho file in the Project tab.
  • To include the Modelsim libraries in the project, [Simulate > Start Simulation...] and click the Libraries Tab, Add... and choose cycloneive_ver [OK] and Add... and choose altera_ver [OK].
  • Click the SDF Tab, and Add... SDF File = serial_vhd.sdo and Apply to Region = \ [OK]
  • Then, click on the Design Tab, select your project for simulation (tutorial > serial), and click [OK]
vsim -L cycloneive_ver -L altera_ver -sdftyp /=/home/moecke/Using_ModelSim/timing/simulation/modelsim/serial_vhd.sdo tutorial.serial 
  • Using the sim tab and the Objects window we can select signals for simulation. To add a signal A, B, resetn, start, clock, sumfrom serial entity. Include also reg_sum|q, reg_A|q, reg_B|q signals.
  • Add signal current_state and counter from my_control component.
add wave -position end  sim:/serial/resetn
add wave -position end  sim:/serial/clock
add wave -position end  sim:/serial/start
add wave -position end  sim:/serial/A
add wave -position end  sim:/serial/\reg_A|q\
add wave -position end  sim:/serial/B
add wave -position end  sim:/serial/\reg_B|q\
add wave -position end  sim:/serial/sum
add wave -position end  sim:/serial/\reg_sum|q\
add wave -position end  sim:/serial/\my_control|counter\
add wave -position end  sim:/serial/\my_control|current_state\
  • To set the clock period to 20ns (50 MHz), set start and resetn signals to 0, and set A = 143 and B = 57.
force -freeze sim:/serial/clock 0 0, 1 {10 ns} -r 20 ns
force -freeze sim:/serial/resetn 0 0
force -freeze sim:/serial/start 0 0
force -freeze sim:/serial/A 10#143 0
force -freeze sim:/serial/B 10#57 0
run 20 ns
  • To set start and resetn signals to 1,
force -freeze sim:/serial/start 1 0
force -freeze sim:/serial/resetn 1 0
run 200 ns

Using a do file

  • save the wave format, end create a new do simulation file serial_add_timing.do,
vsim -L cycloneive_ver -L altera_ver -sdftyp /=/home/moecke/Using_ModelSim/timing/simulation/modelsim/serial_vhd.sdo tutorial.serial 
do wave.do
force -freeze sim:/serial/clock 0 0, 1 {10 ns} -r 20 ns
force -freeze sim:/serial/resetn 0 0
force -freeze sim:/serial/start 0 0
force -freeze sim:/serial/A 10#143 0
force -freeze sim:/serial/B 10#57 0
run 20 ns
force -freeze sim:/serial/start 1 0
force -freeze sim:/serial/resetn 1 0
run 200 ns
  • The simulation now takes account of the circuits and tracks delays.

ModelSim serial add timing.png