Monday, September 27, 2010

Questasim: How to force an internal signal from another signal through TCL script?

The 'force' command available in Questa / ModelSim allows force of value but not signal onto a signal.

Solution

The following example TCL script will do the job:


  when /tb/dut/signal_b {
        force /tb/dut/signal_a [examine /tb/dut/signal_b]   }


where, /tb/dut/signal_a is the source and /tb/dut/signal_b is the destination signal.


Note that in the above case one should provide visibility to the internal object(s) during simulation by either using vsim option -voptargs="+acc" when in optimized(vopt) mode or using vsim option -novopt to be in non-optimized (novopt) mode. Please see User's Manual for details on internal object visibility during simulation - see the section "Preserving Object Visibility for Debugging Purposes".


For details on how to use TCL script, please refer to User's Manual under chapter "Tcl and Macros".


One could force value of a signal onto another signal in the heirarchy within the source code by using Signal Spy feature in Questa / ModelSim. Refer to section "init_signal_driver"

Questasim: How to find all signals with X value in simulation

Modelsim/Questa currently doesn't have a built in command to list all X signals in the design.

Solution

 The following is an example of a TCL script that can be used to print out a list of all signals in the design that have an X or U value at the current simulation time.

foreach item [find signals -r /*] {

    if { [examine -expr $item'hasX] eq "true"} {

        echo "$item [examine $item]"

}

}


To run this script:

1) Save the code to a file.

2) On the modelsim command line or transcript use the 'do' command followed by the path and name of the script file to run the script. If the file was saved in the current directory as "script.do" the command would look like this:

> do script.do


The following is a brief explanation of the script functionality.

The script uses the 'find' command to build an array recursively from the root of the design hierarchy of all signals, and then that array is iterated through a foreach loop.

foreach item [find signals -r /*] {

The following line tests if each item has an X or U value

if { [examine -expr $item'hasX] eq "true"} {


Finally, if it does, the signal and its value are printed to the transcript.

echo "$item [examine $item]"