Jump to content

Getting blank output screen executing the systemc-ams based adc module


Recommended Posts

I Have built adc module using tdf model using systemc-ams. But on debugging I can't get any output results.please do check the code below and give some suggestions.

 

#include<systemc-ams.h>
#include<systemc.h>
 
int main(int argc, char *argv[])
{
    sc_start();
    getchar();
    return 0;
}
 SCA_TDF_MODULE(ad_converter)
// Very simple AD converter
 {
 sca_tdf::sca_in<double> in_tdf;
// TDF port
 sca_tdf::sc_out<sc_dt::sc_int<12> > out_de; 
 
// converter port to DE domain
 void processing()
 {
 out_de.write( static_cast<sc_dt::sc_int<12> >(in_tdf.read() ) );
 }
 SCA_CTOR(ad_converter){}
};
 
Link to comment
Share on other sites

There are some things missing or incorrect in your setup, and that is the reason why you do not see any signals:

  • Use sc_main instead of main
  • You need to instantate the SystemC and/or SystemC-AMS (TDF) modules in your sc_main. You need at least a signal generator (stimuli) and the ADC. You also need to bind them together via a signal of type sca_tdf::sca_signal<double>. This means you also need to instantiate an object of this signal type.
  • You need to enable tracing in sc_main, by opening a trace file using e.g. sca_util::sca_create_tabular_trace_file(...)  and assigning signals or ports to be traced using sca_util::sca_trace(...).
  • I recommend the use of a time limited simulation by specifying the end-time. Example for 1ms simulation: sc_start(1.0, sc_core::SC_MS);

Please have a look into the SystemC AMS user's guide, which is part of the SystemC AMS standard download, section 2.6.3 which shows an example of the sc_main and instantiation of various modules, signals and tracing mechnism.

Link to comment
Share on other sites

Sir, as you had said to instantiate two modules and bind between them via signal sca_tdf::sca_signal<double>.I'm still getting the error that "Undeclared identifier".Below is my complete code for adc and lpf module.Find where I'm facing problem exactly.

 

#include<systemc-ams.h>
#include<systemc.h>
 
int sc_main(int argc, char *argv[])
 
//Instantiate the modules
     lp_filter_ltf lp_filter_ltf("lpf");
     ad_converter ad_converter("adc");
 
//Signals
sca_tdf::sca_in<double> rf;
sc_core::sc_out<sc_int<8> > if_lpf;
sca_tdf::sca_signal<double> if_d;
 
sc_start(1.0,SC_MS);
getchar();
return 0;
}
const double PI=3.1415;
 
SC_MODULE(front_end) {
sca_tdf::sca_in<double> rf;
sc_core::sc_out<sc_int<8> > if_lpf;
sca_tdf::sca_signal<double> if_d;
 
SCA_CTOR(front_end) 
{
adc = new ad_converter("adc");
adc->in(rf);
adc->out(if_d);
lpf = new lp_filter_ltf("lpf");
lpf-> in(if_d);
lpf->out(if_lpf);
 }
};
 SCA_TDF_MODULE(ad_converter)
// Very simple AD converter
 {
 sca_tdf::sca_in<double> in_tdf;
// TDF port
 sca_tdf::sc_out<sc_dt::sc_int<12> > out_de; 
 
// converter port to DE domain
 void processing()
 {
 out_de.write( static_cast<sc_dt::sc_int<12> >(in_tdf.read() ) );
 }
 SCA_CTOR(ad_converter) 
 {}
};
 SCA_TDF_MODULE(lp_filter_ltf) {
sca_tdf::sca_in<double> in; // input
sca_tdf::sca_out<double> out; // output
sca_tdf::sc_in<bool> ctrl; // gain ctrl
sca_tdf::sca_ltf_nd ltf; // LTF object
sca_util::sca_vector<double> num, den;
 
void initialize() {
num(0) = 1.0;
den(0) = 1.0; den(1) = 1.0/(2.0*PI*1.0e4);}
void processing() {
double tf = ltf(num, den, in.read());
if (ctrl.read()) out.write(2.0*tf);
else out.write(1.0*tf);
}
SCA_CTOR(lp_filter_ltf) {}
};
 
The error that compiler is throwing out is mentioned below :
 
error C2065: 'lp_filter_ltf' : undeclared identifier.
error C2065: 'ad_converter' : undeclared identifier
Link to comment
Share on other sites

If you don't know C or C++, using SystemC-AMS is going to be challenging - I highly recommend learning at least how C is compiled first.

 

The problem is that you must declare things before you use them. So you need to put your modules in the correct order. Move the sc_main function to the bottom of your file,

 

kind regards

Alan

Link to comment
Share on other sites

Sir, but how to declare an identifier prior to be used. And how come I need to rearrange the blocks to work is synchronization/flow. Please, tell me the correct sequence to be used as I'm new to systemC. I tried to use sc_main function at the bottom of my file but still problem not resolved. 

Link to comment
Share on other sites

What error did you get?

 

Regarding declaring before use, here is a simple example.

int main() {

  int i;
  j = i;  // won't work, j is not yet declared
  int j;
  return 0;
}

In your original code, you are trying to use lp_filter_ltf before it is declared, which is why sc_main should be at the bottom of the file.

 

I notice also that you are trying to use the class name as an instance name - that won't work, you should write e.g.

     lp_filter_ltf lpf("lpf");
     ad_converter adc("adc");

regards

Alan

Link to comment
Share on other sites

Sir,I'm getting error inside SCA_CTOR(front_end) that "adc" and "lpf" are undefined identifier even after declaring on the top.

 

SCA_CTOR(front_end) 
{
adc = new ad_converter("adc");
adc->in(rf);
adc->out(if_d);
lpf = new lp_filter_ltf("lpf");
lpf-> in(if_d);
lpf->out(if_lpf);
 }
 
please,help me out to declare it giving some syntax for it.
Link to comment
Share on other sites

If you declare objects in a static manner, you cannot "new" them using the same instance name in the code. In your constructor, adc and lpf are expected to hold a pointer to an instance, but you did not declare them as pointers.

 

As suggested by Alan, please get familar with C/C++ before starting with SystemC and SystemC-AMS.

Link to comment
Share on other sites

  • 4 weeks later...

Sir,how will I generate .vcd file from above code for my model.I have written sc_create_vcd_trace_file() for my code but getting an access violation error at the output.I there there might be somewhere NULL pointer assigned.So, just want to know where it is going wrong.Below is my code for sc_trace

 

 int sc_main(int argc, char *argv[])
{   
sca_tdf::sca_in<double>rf, osc;
    sc_core::sc_out<sc_int<8>>if_d;
 
sc_trace_file *wf = sc_create_vcd_trace_file("wave");
sc_trace(wf,rf,"rf");
sc_trace(wf,osc,"osc");
sc_trace(wf,if_d,"if_d");
sc_start(1.0,SC_MS);
sc_start();
getchar();
sc_close_vcd_trace_file(wf);
    return 0;
}
Link to comment
Share on other sites

You cannot trace SystemC-AMS signals using the SystemC (sc_trace*) methods, because SystemC is not aware of the additional types introduced in SystemC-AMS. Therefore you need to use the sca_trace* methods. These SystemC-AMS trace methods also support SystemC build-in types.

 

Furthermore, your sc_main does not contain any module instantiatons. Also the use of ports in sc_main is not correct. You need to use signals (e.g. sca_signal<bool> mysig) to interconnect instantiate blocks with signals

 

Again, please read the SystemC AMS user guide more carefully before you start coding. For tracing usage read section 6.2.

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...