Jump to content

Problem with the case statement


kihtrak

Recommended Posts

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 :)
 
 
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)
 
 
 
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...