Xilinx-ISim apply stimulus from tcl script (cont.):
Below is the code for a tcl script (ie.,stimulus.tcl) which when run in ISim CLI will apply input stimulus to get the output.The signal name ,duty cycle and period are the input parameters to be given in the script file .
please note that checks for validating input signal names,array bound and input signal value range are not kept .So,try to give valid values and signal name to get proper output otherwise no output will be generated.
How To Add inputs in Script File :
Open the script file (ie.,stimulus.tcl) and go to "SIGNALS_TO_SET" procedure (search for "VARIABLES T0 SET" tag ).
########################### VARIABLES T0 SET ###########################
#----------------------------------------------------------------------
# Imp Note : please check the syntax below
# Syntax : set <RetSigCnt> [AddSignal <signal_name> <Duty_cycle> <Period>]
#
# usage : for varying signals :: set RetSigCnt [AddSignal clock 50 20]
# for constant signals :: set RetSigCnt [AddSignal enb_n $FORCE_ONE $CONST_PER]
#
proc SIGNALS_TO_SET {} {
global RetSigCnt
global FORCE_ZERO
global FORCE_ONE
global CONST_PER
### !! ADD SIGNALS HERE !!:START###
set RetSigCnt [AddSignal clock 50 20 ]
set RetSigCnt [AddSignal Din 25 100 ]
set RetSigCnt [AddSignal enb_n $FORCE_ZERO $CONST_PER ]
### !! ADD SIGNALS HERE !!:END###
}
#---------------------------------------------------------------------
# TU : time unit
set TU "ns"
set RunTime 1000
########################### VARIABLES T0 SET ###########################
########################################################################
Now,go to "ADD SIGNALS HERE" to add input stimulus.
### !! ADD SIGNALS HERE !!:START###
set RetSigCnt [AddSignal clock 50 20 ]
set RetSigCnt [AddSignal Din 25 100 ]
set RetSigCnt [AddSignal enb_n $FORCE_ZERO $CONST_PER ]
### !! ADD SIGNALS HERE !!:END###
Syntax :
set <RetSigCnt> [AddSignal <signal_name> <Duty_cycle> <Period>]
<RetSigCnt> -> return value count (it will tell number of signals added)
<signal_name> -> input signal name (give valid input signal name)
<Duty_cycle> -> duty cycle of the input signal.
100 (%) -> always 1
0 (%) -> always 0
50 (%) -> 50% time 1 and 50% time 0
<Period> -> period of the input signal
AddSignal -> This procedure will add entries to array.
Usage :
(1.)Suppose, enb_n is a signal and its a constant signal.
set RetSigCnt [AddSignal enb_n $FORCE_ZERO $CONST_PER ]
Then add the above line after "ADD SIGNALS HERE" statements (see above).FORCE_ONE -> force signal to '1'
FORCE_ZERO -> force signal to '0'
(2.) Suppose,Din and clock are varying signal.
set RetSigCnt [AddSignal clock 50 20 ]
set RetSigCnt [AddSignal Din 25 100 ]
here clock name is "clock", clock duty cycle 50 % and clock period is 20 (ns).D input signal name is "Din", Din duty cycle 25 % and clock period is 100 (ns).
Similary you can add any number of signals using AddSignal procedure.
(3.) TU is time unit ,set to "ns"
(4.) RunTime is simluation run time length.
How to Run tcl script from Isim CLI :
source <path>/<file-name>.tcl
Example : source stimulus.tcl
In this example the script file is located in project base directory.
Code : (stimulus.tcl)
# This is a TCL script #
# File Name : stimulus.tcl #
# Developer : Sagar S #
# Release : REL_V_1
# Module name : Input stimulus generator for ISIM #
# How To run : source stimulus.tcl #
# execute this command in Isim CLI#
# and path to stimulus.tcl should be given#
# if its in different directory #
#
########################################################################
########################### VARIABLES T0 SET ###########################
#----------------------------------------------------------------------
# Imp Note : please check the syntax below
# Syntax : set <RetSigCnt> [AddSignal <signal_name> <Duty_cycle> <Period>]
#
# usage : for varying signals :: set RetSigCnt [AddSignal clock 50 20]
# for constant signals :: set RetSigCnt [AddSignal enb_n $FORCE_ONE $CONST_PER]
#
proc SIGNALS_TO_SET {} {
global RetSigCnt
global FORCE_ZERO
global FORCE_ONE
global CONST_PER
### !! ADD SIGNALS HERE !!:START###
set RetSigCnt [AddSignal clock 50 20 ]
set RetSigCnt [AddSignal Din 25 100 ]
#set RetSigCnt [AddSignal Din $FORCE_ONE $CONST_PER ]
### !! ADD SIGNALS HERE !!:END###
}
#---------------------------------------------------------------------
# TU : time unit
set TU "ns"
# Simulation Run Time
set RunTime 1000
########################### VARIABLES T0 SET ###########################
########################################################################
#***************** !Constant Variables! *****************#
# Should not be changed #
set HIGH 1
set LOW 0
set D 0
set T 0
array set SIGNAL {}
set index 0
set RetSigCnt 0
set sigName 0
set FORCE_ONE 100
set FORCE_ZERO 0
set CONST_PER 1115558
##########################################################
proc AddSignal {sigName duty_cycle period} {
global index
global SIGNAL
set i $index
set SIGNAL($i,$i,$i) "$sigName $duty_cycle $period"
set index [expr {$index+1}]
puts "ADDED Signal $index \n"
return $index
}
#__MAIN_FUNCTION__START
proc STIMULUS_SIM {} {
SIGNALS_TO_SET
global RetSigCnt
global HIGH
global LOW
global TU
global SIGNAL
for {set i 0} {$i < $RetSigCnt} {incr i} {
puts "$SIGNAL($i,$i,$i)"
set ii 1
foreach param $SIGNAL($i,$i,$i) {
#puts "param=$param"
if { $ii == 1} {
set sigName $param
} elseif { $ii == 2} {
set D $param
} else {
set T $param
}
set ii [expr {$ii + 1}]
}
#***************** Clock Generation *********************#
# T : signal period #
# D : duty_cycle is in % #
# if { $D == 100 } {
# set sigName $param
# }
set High_per [expr {$D*$T/100}]
set Low_per [expr {$T-$High_per}]
puts "sigName=$sigName ,High_per=$High_per and Low_per=$Low_per"
isim force add $sigName $LOW -value $HIGH -time $Low_per $TU -repeat $T $TU
#*********************************************************#
}
}
#__MAIN_FUNCTION__END
#__RESTART_SIM__START
proc RESTART_SIM {} {
puts "..Restarting Simulation.."
restart
}
#__RESTART_SIM__END
#__RUN_SIM__START
proc RUN_SIM { } {
global TU
global RunTime
puts "..Running Simulation For $RunTime $TU.."
run $RunTime $TU
}
#__RUN_SIM__END
#########################################################
############## Main invoking method ####################
RESTART_SIM
STIMULUS_SIM
RUN_SIM
#########################################################
You can also get this same code uploaded here.
If there is any Bug in this code please notify me
No comments:
Post a Comment