how to write text in vhdl

X

Xin Xiao

i want to write some text in the output of my simulation. In my code I have
a variable and I would want that, when the simulation reaches, say, 10 ns,
the simulator writes the text "the variable p is blah blah ". Should I use
the instruction "writeline" in my test-bench or there is another solution?
the scope of the variable is outside of the test-bench.

thanks
 
D

David Bishop

Xin said:
i want to write some text in the output of my simulation. In my code I
have a variable and I would want that, when the simulation reaches, say,
10 ns, the simulator writes the text "the variable p is blah blah ".
Should I use the instruction "writeline" in my test-bench or there is
another solution? the scope of the variable is outside of the test-bench.

try time'image

Something like this:

variable L : line;
.....
write (L, "The variable P is " & time'image(P) );

I don't think you need a string' here because the output of time'image
is a string.
 
K

KJ

Xin Xiao said:
i want to write some text in the output of my simulation. In my code I have
a variable and I would want that, when the simulation reaches, say, 10 ns,
the simulator writes the text "the variable p is blah blah ". Should I use
the instruction "writeline" in my test-bench or there is another solution?
the scope of the variable is outside of the test-bench.

thanks

If you happen to be inside a process where you want to output the text, you
can simply use 'report'.

report "the variable p is " & integer'image(p) & " at time " &
time'image(now);
report "the variable p is " & std_logic'image(p) & " at time " &
time'image(now);

If 'p' happens to be an integer or std_logic. Unfortunately you can't say
"std_logic_vector'image(p)" if p is a std_logic_vector, you'll need a
function that converts a std_logic_vector into a string. This is not really
a limitation on 'report' you'd have the same issue with the writeline
procedure as well. For a package of functions that do such conversions,
Google for "Ben Cohen" VHDL image_pkg

KJ
 
J

Jim Lewis

David said:
try time'image

Something like this:

variable L : line;
....
write (L, "The variable P is " & time'image(P) );

I don't think you need a string' here because the output of time'image
is a string.

You may also wish to add a new line:

write (L, "The variable P is " & time'image(P) & LF );
 
M

Mike Treseler

Xin said:
Should I use the instruction "writeline" in my test-bench or there is
another solution? the scope of the variable is outside of the test-bench.

I use the modelsim "step" command
to trace code and internal variable values.

-- Mike Treseler
 
A

Andy

If you happen to be inside a process where you want to output the text, you
can simply use 'report'.

report "the variable p is " & integer'image(p) & " at time " &
time'image(now);
report "the variable p is " & std_logic'image(p) & " at time " &
time'image(now);

If 'p' happens to be an integer or std_logic. Unfortunately you can't say
"std_logic_vector'image(p)" if p is a std_logic_vector, you'll need a
function that converts a std_logic_vector into a string. This is not really
a limitation on 'report' you'd have the same issue with the writeline
procedure as well. For a package of functions that do such conversions,
Google for "Ben Cohen" VHDL image_pkg

KJ

If the std_logic_vector does not contain meta values, you can use
something like integer'image(to_integer(unsigned(p))).

Unfortunately, the output would be in decimal (which could be handy at
times!), not binary/hex.

Andy
 
K

KJ

If the std_logic_vector does not contain meta values, you can use
something like integer'image(to_integer(unsigned(p))).

Unfortunately, the output would be in decimal (which could be handy at
times!), not binary/hex.

It also can't be longer than 32 bits.

The nice thing about Ben's package is that you can just say
"image(blah_blah_blah)" without having to know what type
"blah_blah_blah" is (as opposed to integer'image(blah_blah_blah)).
The downside though is that the package, as it exists today, can not
be used inside synthesizable code without surrounding every usage with
"synthesis translate_off/on" pragmas because the package uses access
types and 'deallocate' calls...ahh well.

At some point though, one should arm themselves with a set of
functions that convert types to text strings. Effective log files can
be a useful artifact of a simulation run as well.

KJ
 
T

Tricky

You may also wish to add a new line:

write (L, "The variable P is " & time'image(P) & LF );

This only writes the string to the line, you then need to do something
with the line itself.
Normally you then use:

writeline(OUTPUT, L);

with this you dont need a LF on the end as the writeline procedure
adds one for you.

If you construct a line using write commands, and want to report it,
use:

report L.all.

This will not flush the line thoug like th writeline procedure.
 
K

karthik

Hi

If time variable has real/float values, how can we get those values?
Like,

variable add_result : time := 282.25 NS ;

....
write (L, time'image(add_result));
writeline(output,L);

This just displays : 282

How can I get the whole value?

Thanks in advance.

-- Karthik
 
M

Martin Thompson

karthik said:
Hi

If time variable has real/float values, how can we get those values?

Time variables are not reals or floats - they are integer numbers of
femtoseconds. The use of the other units is a convenience.
Like,

variable add_result : time := 282.25 NS ;

...
write (L, time'image(add_result));
writeline(output,L);

This just displays : 282

Works here...

# vsim -do {run -all} testtime
# // ModelSim PE 6.2d Oct 16 2006
......
# run -all
# 282250 ps
How can I get the whole value?

Have you got your simulator time resolution set to less than
nanoseconds? If not, you will get what you see:

....
# run -all
# 282 ns
#

Cheers,
Martin
 
P

Paul Uiterlinden

karthik said:
Hi

If time variable has real/float values, how can we get those values?
Like,

variable add_result : time := 282.25 NS ;

...
write (L, time'image(add_result));
writeline(output,L);

This just displays : 282

It should work. What simulator are you using?

By the way: it is not needed to use time'image here. You can use write
directly:

write(L, add_result);

Using write this way, you can even specify the unit in which you want the
result to be printed. For example:

write(L, add_result, unit => us);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top