TCL/TK and ModelSim for Microelectronic Debugging - UT Graduate Project, Study Guides, Projects, Research of Digital Systems Design

A graduate project presentation about using tcl/tk with modelsim to create powerful visualization and debugging interfaces for microelectronic systems. The presentation covers the reasons for using tcl, an introduction to modelsim and tcl/tk, and the creation of a custom visualization tool for a device or a board. The project includes a tutorial on simulating an altera up-2 demo board and creating an animation of a traffic signal controller.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/27/2009

koofers-user-g15-1
koofers-user-g15-1 🇺🇸

10 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Microelectronic Systems--University of Tennessee
1
1
Animating Logic Simulations
Graduate Project Presentation
Prepared by
Narayanan Raghuraman
Department of Electrical Engineering
University of Tennessee - Knoxville
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download TCL/TK and ModelSim for Microelectronic Debugging - UT Graduate Project and more Study Guides, Projects, Research Digital Systems Design in PDF only on Docsity!

Microelectronic Systems--University of Tennessee (^11)

Animating Logic Simulations

Graduate Project Presentation

Prepared by Narayanan Raghuraman

Department of Electrical Engineering University of Tennessee - Knoxville

Microelectronic Systems--University of Tennessee (^22)

TCL/ TK

Definitions

  • TCL => Tool Command Language
  • TK => Tool Kit

Why TCL?

  • Scripting Language => Higher level of programming
  • Easier to learn and works on many platforms
  • Powerful text processing commands
  • TCL TK provides an easy way to create a graphical interface

TCL is a scripting language hence it is at a higher level of programming. This implies that this is easier to program than languages like C or C++.

TCL can be used to send commands to interactive programs such as simulators and debuggers.

TCL is easy to learn and applications can be implemented very fast

TCL is platform independent and is programmable

Programmability ensures that new commands can be added to TCL. This feature is of immense use in simulators where customized commands can simplify complex problems.

Microelectronic Systems--University of Tennessee (^44)

Extending ModelSim with TCL/TK

There are three problem areas for extending ModelSim with TCL to create a custom visualization tool for a device or a board.

  • TCL/TK program to generate a simulator to display the target device’s output data
  • Extract the necessary signal data from the simulation results
  • Embedding this extension to the ModelSim GUI to make it behave in an intuitive and convenient way

Suppose you are simulating a device that will drive a small full-graphic display panel, for instance on a mobile phone. Using Tcl/Tk you can create a window displaying the panel's appearance, allowing you to visualise the simulation results directly instead of having to interpret the display controller's output signals.

When creating this kind of extension to ModelSim there are three distinct problem areas.

•A Tcl/Tk program must be written to create the display, based on the simulator's output data. Tcl/Tk's canvas widget is so powerful and easy to use that this task is usually quite straightforward.

•The Tcl/Tk display generator must be provided with the necessary signal data, extracted from the simulation results. ModelSim's "examine" command makes it very easy to get hold of the required data, but...

•The whole extension must be hooked into the ModelSim GUI environment so that it behaves in an intuitive and convenient way. This means, for example, making the display generator update correctly in response to changes in the position of a cursor in ModelSim's wave window. It's also necessary to add appropriate menu items or toolbar buttons so that the new functionality is readily accessible from the familiar ModelSim GUI.

Microelectronic Systems--University of Tennessee (^55)

ModelSim - TCL Commands

  • When – To execute a function or a set of commands when a signal changes state
  • Force – To force the value of a signal to a required value
  • Examine – To extract the current value of a named signal
  • Wave – Add specific signals to the wave window
  • Run – Execute the simulation for a specified time Example
  • Create a clock waveform on signal "clk" with period 40, with value '0' for the first half and '1' for the last half: force clk 0 0, 1 20 -rep 40

These four commands are the basic requirements in using TCL to animate and debug VHDL designs using ModelSim. The same can be done with Verilog designs too.

In the example provided, the syntax is described as follows.

Force (signal_name) value1 time1, value2 time2 –rep period

The signal indicated in signal_name is varied between value1 and value2. The period of change is specified after ‘-rep’. At ‘time1’ seconds inside the period, the signal is at value1. At ‘time2’, the signal’s value is changed to ‘value2’.

Microelectronic Systems--University of Tennessee (^77)

Simulation of Altera UP-2 Demo Board

In the ECE 551 course, the Altera UP-2 Demo board is used to introduce the students to the world of FPGA’s. The Altera Demo Board has some user interface features which are

  • Two sets of seven segment LED displays
  • 8 dip switches
  • Two Push buttons

These features are used to simulate the operation of the board. The seven segment displays are simulated by utilizing seven different ‘line’ objects. Each such ‘line’ object is connected to one bit of the output signal. The color of the line object is changed when the corresponding bit changes between ‘1’ and ‘0’.

The dip switches are also used to provide input to the VHDL testbench. Each switch is simulated a checkbox. A function bound to the checkbox is executed every time it changes state. If it is pressed it provides a value of ‘1’ to the corresponding test bench input.

The two push buttons are named ‘Start’ and ‘Reset’ for convenience.

Microelectronic Systems--University of Tennessee (^88)

Part I – Counting Up

Before I go on to detail the states of the simulator, I shall explain the TCL/TK Interface a bit.

In TCL/TK, the root window is specified as ‘.’. All subcomponents of the root window are called widgets.

The canvas is the area of the window where sub-widgets are placed and it can contain signal lights, cars, buttons, radio buttons, check boxes, labels and the slide controls. The canvas normally encompasses the whole window. The above mentioned components including the canvas are TCL/TK widgets.

This slide depicts the Simulator in it’s counting up state.

Two of the eight dip switches are utilized in this design.

The dip switch ‘dip1’ signifies this state. The dip switch ‘dip2’ sets the ‘enable’ input of the testbench.

The ‘Start’ button is pressed to initialize the simulation. The ‘start’ button is bound with a function

Microelectronic Systems--University of Tennessee (^1010)

Part I – Disabled

In this slide, the dip switch ‘dip2’ is in its depressed state. Hence the input to the ‘enable’ signal in the testbench is set to ‘0’. Hence the Counter stops counting and the value of the lower byte remains at ‘C’ as shown in the simulation interface as well as the waveform window.

Microelectronic Systems--University of Tennessee (^1111)

Part II - TCL/TK Interface Modification

STEPS

**1. Open the file ‘altera.tcl’.

  1. Go to the part which says “uncomment the following** **lines to add ‘Reset’ Button”
  2. Understand the significance of the lines and then** **uncomment them
  3. Next go to the part which says “uncomment the** following lines for adding display 2” and uncomment **them.
  4. Save the file and source the file from ‘vsim’
  5. The interface should now show the new additions.**

This page details the steps to be taken to add a button named ‘Reset’ and a custom seven segment display widget name ‘display_l’.

The complete tcl design has been done in a single file named ‘altera.tcl’. This file contains several functional procedures which are used to handle individual functions such as updating seven segment display, sending changes in the checkboxes or buttons to the inputs of the VHDL design and so on.

More details about the changes made are provided in the next slide.

Microelectronic Systems--University of Tennessee (^1313)

Part II - Interface

In this slide, it can be seen that the new seven segment display and the new ‘Reset’ button have been added. The switches dip1 and dip2 are in the pressed state, Hence the counter proceeds in the upward counting state.

Microelectronic Systems--University of Tennessee (^1414)

Part II – Up Counting Waveform

This waveform shows the waveform for the up-counting state. It can be seen that the output value keeps increasing for every second that passes in the simulation. The value of the counting interval is specified in a function procedure called ‘run_clock’. It is from this procedure that the procedure ‘update_display’ which handles the updating of the displays gets called.

Microelectronic Systems--University of Tennessee (^1616)

Part III – Traffic Light Controller

  • Without creating a device, it might be tough to visualize how the controller will work or debug it quickly.
  • Complex VHDL Blocks are also difficult to debug.
  • A real life simulation of the device or block will simplify the debugging process.
  • A Traffic Signal Controller is simulated to show the benefits of using ModelSim’s TCL/TK functionality towards achieving the goals of visualization and debugging.
  • The interface can be extended to simulate more complex interfaces and VHDL Blocks

Microelectronic Systems--University of Tennessee (^1717)

Highway Farm-Road Intersection

Inputs to the VHDL Design

  • North – South car sensor
  • East and West Left turn car sensor
  • Waiting times for the cars
  • Green, Yellow and Red state times for the signals

Outputs from the VHDL Design

- East – West , North – South and Turn signals

The various input and output signals used in the VHDL Design are shown in this slide. The North – South car sensor and the Turn car sensors are set when a car comes to rest in a particular section of the respective roads.

Immediately after the cars come to rest, a waiting time counter is set into action. This counter is provided as an input to the VHDL design and is useful in determining which of NS and Turn sensors were activated first. Based on this the state machine changes from EW green to NS or Turn states.

The inputs to the Green, Yellow and Red state times are initialized to a default value. They can also be set using ‘scale’ widgets which are described later.

The outputs from the VHDL design are used to set the various signals in their green, yellow or red states.

Microelectronic Systems--University of Tennessee (^1919)

Design Files

VHDL Files

  • Traffic_new.vhd – Design with State-Machine
  • Tb_traffic.vhd – Test-bench file which interfaces TCL

TCL Files

  • Intersection.tcl – Builds the intersection canvas
  • Controls.tcl – Adds the Timing Controls
  • Cars.tcl – sets the cars rolling
  • Lights.tcl – connects the lights to the simulation

These are the various files that have been created for the Simulator/Animator design.

The traffic_new.vhd file has the state-machine design and the assigning of the signals to the output ports according to the different states.

The testbench file provides the mapping to the VHDL file. ModelSim provides an interface wherein the various signals and variables in the loaded design are accessible to TCL scripts sourced in the ModelSim command line.

The TCL files have been programmed as functions.

The functions for building the intersection and the lights(build_intersection in Intersection.tcl) and the controls(light_controls controls.tcl) are executed on startup. The lights are connected to the simulation design by using when statements which are executed by the function connect_lights(lights.tcl).

The file cars.tcl controls the movement of the cars. It has several flags each of which are set inside loops initialized by ‘when’ statements.

Recursive loops are used to move the cars.

An important point to note here is that the ‘when’ statements should not be used inside the functions because they are very slow and return only when the signals in the testbench change state. If they are used inside recursive loops, it will make the simulation very slow.

Microelectronic Systems--University of Tennessee (^2020)

Some Examples of Command Usage

‘when’ when {/light_ew} { set flag1 [examine light_ew] } ‘move’ $root move $ta [expr -$pos_curr1] 0 ‘after’ after $tim movecar_ew $root $ta $tim $constr $flag ‘create’ $root create line $x1 $y1 $x2 $y2 -fill $color -tag $tag -width 60 ‘delete’ $root delete line -tags $ta

These are some of the important commands used in this simulation.

  1. The ‘when’ command executes the code inside its braces whenever the state of the variable or signal, to which it is attached, changes.
  2. The ‘move’ command moves the widget pointed to by the tag ($ta) by a distance specified by the x and y parameters following it. The $root specifies the root canvas to which the widget belongs.
  3. The ‘after’ command executes its argument procedure or command after the specified time ($tim). The other parameters are those that are passed to the functional procedure to be executed.
  4. The ‘create’ command creates a widget. The widget may be any of ‘line’, ‘rectangle’, ‘oval’ and so on.The edge coordinates of the widget are passed as parameters to the ‘create’ command. $root is the same as described above and $tag is the same as $ta above. The other parameters are self explanatory. More parameters can be added if required.
  5. The ‘delete’ command deletes an already created widget.

Some other commands are ‘configure’ which can be used to change the attributes of a created widget and ‘catch’ which can be used to check if a particular widget is available or not.