ModelSim tcl expression

Status
Not open for further replies.

echo47

Advanced Member level 6
Joined
Apr 7, 2002
Messages
3,933
Helped
638
Reputation
1,274
Reaction score
90
Trophy points
1,328
Location
USA
Activity points
33,176
In my ModelSim testbench, I'm trying to drive a 16-bit bus with the results of a tcl expression. For example:

force mybus [expr int(10000*sin(4.0))]

ModelSim complains that -7568 is unacceptable. Well yes, "force" expects a format such as -16'd7568 or 1110001001110000. What do I add to my expression to do the necessary format conversion?
 

Hi,

May be you can use the concat command in a macro :

set a "16'd"
set b int(10000*sin(4.0))
if [expr $b > 0] then {set c [concat $a$b]} else {set c [concat -$a[expr abs($b)]]}
force my_bus $c

:wink:
 

So wise answer , and I don't understand it at all, because I know a very small of Tcl (OK! still after years and years!) However, as far as I know, there are many ways for generating a sine wave. Just generate the coefficients with a C program ( for one period of pulse ) and put them all in a file, and the remaining is to write a simple Verilog , VHDL code to read the file, and drive the bus.
 

Hi mami_hacky

I agree with you, I prefer generating text file with the stimuli values.
And because I'm not a C programmer, I use MS Excel to generate my values 8)
 

Actually, tcl is very powerful. You can achieve what you want by:
force mybus [format "16#%x" [expr int(10000*sin(4))]];
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…