kihtrak Posted April 19, 2016 Report Share Posted April 19, 2016 Hello there, Am trying to implement binary to gray converter using simple case statements. When I try to execute, only the first statement of the switch case is being executed. Here's my gtb.cpp and driver module // driver.cpp #include "driver.h" void driver::proc_driver() { while(1) { d_bin = 0; wait(5, SC_NS); d_bin = 4; wait(5, SC_NS); } } #include"gtb.h" void gtb::proc_graytobinary() { switch(bin.read()) { case 0 : grayout = 0; break; case 1 : grayout = 1; break; default: grayout = 2; break; } } Please help me solve this issue. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted April 19, 2016 Report Share Posted April 19, 2016 I don't see where you assign 1 to bin , show all related code. Quote Link to comment Share on other sites More sharing options...
kihtrak Posted April 19, 2016 Author Report Share Posted April 19, 2016 Hey Roman, I tried assigning "1" to bin, as well some other value which is not listed in the case statement. I did this to check whether "default" as well as the other case statements are executed. But, all it does is just prints "0" for any input value, i.e only the first case statement is executed. I tried changing the value in the first case statement, but still only that value is printed and rest all case statements are ignored. Please help me solve this issue Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted April 19, 2016 Report Share Posted April 19, 2016 Hello kihtrak, In your source code you don't assign any value to bin. Please provide a minimal simulation source code to reproduce your problem. Otherwise nobody can help you. apfitch 1 Quote Link to comment Share on other sites More sharing options...
Stephan Gerth Posted April 20, 2016 Report Share Posted April 20, 2016 Hi kihtrak, is proc_graytobinary made sensitive to the signal/port bin? It seems that proc_graytobinary is just run during initialization and never again. But Roman is right, please post complete code. Quote Link to comment Share on other sites More sharing options...
kihtrak Posted April 20, 2016 Author Report Share Posted April 20, 2016 Hello all , This is my complete code: #include"systemc.h" SC_MODULE(gtb) { sc_in<sc_uint<3> > bin; sc_out<sc_uint<3> > grayout; void proc_graytobinary(); SC_CTOR(gtb) { SC_THREAD(proc_graytobinary); sensitive<<bin; } }; Gtb.cpp include"gtb.h" void gtb::proc_graytobinary() { switch(bin.read()) { case 0: grayout = 0; break; case 1: grayout = 1; break; default: grayout = 3; break; } Driver.cpp #include "driver.h" void driver::proc_driver() { while(1) { d_bin = 0; wait(5, SC_NS); d_bin = 1; wait(5, SC_NS); wait(100, SC_NS); } } Gtbmain.cpp // File : decodermain.cpp #include"gtb.h" #include"driver.h" #include"monitor.h" int sc_main(int argc, char* argv[]) { sc_signal <sc_uint<3> > t_bin; sc_signal <sc_uint<3> > t_grayout; sc_trace_file *tfile = sc_create_vcd_trace_file("graytobinary"); tfile->set_time_unit(1, SC_NS); gtb d1("GraytoBinary"); d1 << t_bin << t_grayout; driver dr("GenerateWaveforms"); dr << t_bin ; monitor mon("MonitorWaveforms"); mon << t_bin << t_grayout; sc_trace(tfile, t_bin, "t_bin"); sc_trace(tfile, t_grayout, "t_grayout"); sc_start(150, SC_NS); //sc_stop(); sc_close_vcd_trace_file(tfile); return(0); } Please help me solve this issue. Thanks Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted April 20, 2016 Report Share Posted April 20, 2016 Where is Driver.h ? I don't see a place where you create SC_THREAD(proc_driver) Quote Link to comment Share on other sites More sharing options...
apfitch Posted April 20, 2016 Report Share Posted April 20, 2016 The obvious problem is that you don't have an infinite loop in the SC_THREAD gtb::proc_graytobinary(). Thus it will only run once at time zero. The quick fix is to make it an SC_METHOD instead, regards Alan Quote Link to comment Share on other sites More sharing options...
kihtrak Posted April 21, 2016 Author Report Share Posted April 21, 2016 Thanks Alan. Changing to SC_METHOD() solved the issue. The output seems to be: At time 0s: i/p:0000 o/p :0000 At time 5ns: i/p: 0001 o/p: 0000 At time 5ns: i/p: 0001 o/p:0001 At time 110ns: i/p: 0000 o/p:0001 At time 110ns: i/p: 0000 o/p:0000 At time 115ns: i/p: 0001 o/p:0000 At time 115ns: i/p: 0001 o/p:0001 1.At time 5ns, the first output is 0 , and the next displayed output is 1. Is this what they call the delta delay which occurs when writing to a port? 2.Also, after 5ns, why does it jump to 110ns instead of 105ns? Please help me in finding answers for these . Thanks Gerth and Roman Quote Link to comment Share on other sites More sharing options...
apfitch Posted April 21, 2016 Report Share Posted April 21, 2016 For your question 1, probably - I don't know exactly what triggers your monitor. But as you say, using a primitive channel such as sc_signal will result in a delta delay. For 2., it jumps to 110ns because that's what you told it to do in your driver here: d_bin = 1; wait(5, SC_NS); wait(100, SC_NS); regards Alan 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.