sc_fox Posted May 1, 2013 Report Share Posted May 1, 2013 How to output "float (double)" from sc_fixed type class using sc_trace? I have an existing model (all in floating point design, using "sc_signal<double>"), and am trying to convert it to its fixed point one (i.e. using sc_signal<sc_fixed< ,,,, > >"). sc_signal<double> ch_a; sc_signal<sc_fixed<16,8, SC_RND, SC_SAT> > ch_a_fix; sc_trace(tf, ch_a, "ch_a" ); // floating point channel tracing, it traces signal in "double". sc_trace(tf, ch_a_fix, "ch_a_fix ); // fixed point channel tracing: it traces signal in "integer numbers". The question is, how can I trace the sc_fixed type class (sc_signal<sc_fixed<...:> >) in floating point numbers? For waveform viewer-wise, I'm using gtkwave for now. I have found one posting that has the same question that I have now. But it doesn't have any replies there. http://www.accellera.org/Discussion_Forums/helpforum/archive/msg/msg?list_name=help_forum&monthdir=200802&msg=msg00035.html Many thanks in advance. Annossyenudge 1 Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted May 2, 2013 Report Share Posted May 2, 2013 I'm afraid there is no builtin way to do this. You can't just trace the value returned from ch_a_fix.to_double() as this is returned as a temporary double (and you can only trace persistent objects). You may need to use a helper process doing the translation. Something like (untested): double ch_a_fix_tr; void update_ch_a_fix() { ch_a_fix_tr = ch_a_fix.to_double(); } // in constructor ... SC_METHOD(update_ch_a_fix); sensitive << ch_a_fix; and then trace ch_a_fix_tr instead.Of course, you can wrap all of this in a helper class and implement your own sc_trace_fixed_as_double function based on it. hth, Philipp Quote Link to comment Share on other sites More sharing options...
sc_fox Posted May 2, 2013 Author Report Share Posted May 2, 2013 Thank you, Philipp, for your answer. I appreciate it. Just one more thing, Because "ch_a_fix" is "channel" defined as: sc_signal<sc_fixed<...> > ch_a_fix; "sc_signal" class doesn't have "to_double()" as its member function. So I had compile error with the code in your message. So I have modified your code slightly as follows: double ch_a_fix_tr;void update_ch_a_fix() { ch_a_fix_tr = ch_a_fix.read().to_double(); // just added sc_signal<T>.read(), to get the value.}// in constructor ...SC_METHOD(update_ch_a_fix);sensitive << ch_a_fix; I'm not sure if that is the right way to do, but it looks working. Philipp, do you have any comments on this? Thanks, again. Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted May 3, 2013 Report Share Posted May 3, 2013 "sc_signal" class doesn't have "to_double()" as its member function. So I had compile error with the code in your message. ... ch_a_fix_tr = ch_a_fix.read().to_double(); // just added sc_signal<T>.read(), to get the value. Your solution is correct. That's why my example said "untested". Sorry. /Philipp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.