Jump to content
milind.shende5

can we input a stimuli from a text file ?

Recommended Posts

Hello All, 

I have a problem regarding Input stimuli. I have a text file, In which I have written an AC signal.

 

Text file example:

 

Time              output voltage (volt)

0   us             2.0 v

10 us             2.1 v

20 us             2.2 v

.

.

.

100 us          3.0 v

 

and so on.....

 

I want to use this file, more specifically the "output voltage" signal as an input stimuli to a SystemC-AMS code say for example an amplifier or an A2D converter. 

 

in SystemC-AMS code, I do have a signal      sca_tdf::sca_signal<double> in;

 

how can i assign the output voltage in the text file to a "in" signal ?

how can i handle time intricacies ?

 

thanks in advance !!!

regards, 

 

Milind

Share this post


Link to post
Share on other sites

Hello Milind,

 

you cannot directly assign the stimuli values from a file to a TDF signal. You will have to implement a source module, which opens and reads the file using, e.g., the standard <fstream> library. If the time step between the samples is constant in the file, you can simply set the source's output port time step to that value and then read the next stimuli value from within the processing() callback and write it to the output port.

 

If the time step varies, you can either use the new Dynamic TDF features or you can generate the stimuli by implementing a DE source (SC_MODULE), which has an SC_THREAD, which alway waits for the next time step after it has written the last value. The DE signal can be then connected via a TDF converter port of type sca_tdf::sca_de::sca_in<double> to your TDF model.

 

You can extend both approaches to implement, e.g., interpolation between two samples.

 

You might also want to have a look to the TU Vienna SystemC AMS Building Block library available from:

 

http://www.systemc-ams.org/BB_library.html

 

Regards, Torsten

Share this post


Link to post
Share on other sites

Hello Torsten, 

 

as per the above discussion, I have written the code for a dummy source as follows, I might need ur kind comments.  (code runs with out compilation errors)

 
 
#include<systemc-ams>
#include<systemc>
 
#include<iostream.h>
#include<fstream.h>
 
using namespace std;
 
SCA_TDF_MODULE (dummy_src)
 
{
  sca_tdf :: sca_out<double> output; 
  ifstream infile;
  double val;
 
  dummy_src(sc_core::sc_module_name nm, sca_core::sca_time Tm_ = sca_core::sca_time(25, sc_core::SC_US)): output("output"), Tm(Tm_){}
 
    void set_attribute()
    {
      set_timestep;
    }
 
    void processing ()
    {
      infile.open("../datalog.txt");
      while (infile >> val)
{
 output.write(val);
 sc_core::wait(25, sc_core::SC_US); //user guide page: 38, top block
}      
    }
 
 private:
    sca_core::sca_time Tm;
};

Share this post


Link to post
Share on other sites

Hello Milind,

 

your dummy_src won't work as you're mixing in it DE and TDF semantics! In the context of TDF module, you are not at all allowed to call sc_core::wait()! Instead of the while loop in your processing() callback, use something like:

 

if (infile >> val) {

  output.write(val);

} else {

  output.write(0.0);

}

 

The time distance between the output samples is defined by the module timestep, which you specified in set_attributes().

 

Regards, Torsten

Share this post


Link to post
Share on other sites

Hello Torsten, 

In the above code context, I have written following codes and encountered an error message. could you please help me to locate the mistake?

Codes are as follows:

 

-- datalog.txt --

 

3.000315

3.000944
3.001572
3.002199
3.002829
3.003457
3.004085
3.004714
3.005342
3.005970
3.006599
3.007227
3.007855
3.008483
3.009112
3.009740
3.010368
3.010997
3.011625
3.012253
3.012881
3.013510
3.014138
3.014766
3.015395
...cont...

 

-- dummy_source.h --

 

#include<systemc-ams>
#include<systemc>
 
#include<iostream.h>
#include<fstream.h>
 
using namespace std;
 
SCA_TDF_MODULE (dummy_src)
 
{
  sca_tdf :: sca_out<double> output; 
  //  ifstream infile;
  //  double val;
 
  dummy_src(sc_core::sc_module_name): output("output"){}
 
    void set_attribute()
    {
      set_timestep(25, sc_core::SC_US);
    }
 
    void processing ()
    {
      ifstream infile;
      double val;
      infile.open("datalog.txt");
      
      if (infile >> val) {
output.write(val);
      else {
output.write(0.0);
}
      
    }
    
 };
 
-- dummy_test.cpp --
 
#include<systemc-ams.h>
#include<systemc.h>
#include<dummy_source.h>
using namespace std;
 
SC_MODULE(top_level)
{
  dummy_src vtg_src;
  sca_eln::sca_tdf::sca_vsource vin;
 
  top_level(sc_core::sc_module_name): vtg_src("vtg_src"), vin("vin"), n1("n1"), n2("n2"), gnd("gnd")
    {
      vtg_src.output(n1);
 
      vin.inp(n1);
      vin.p(n2);
      vin.n(gnd);
    }
 public: 
  sca_tdf::sca_signal<double> n1;
  sca_eln::sca_node n2;
  sca_eln::sca_node_ref gnd;
 
};
 
 
int sc_main(int argc, char* argv[])
{
  
  top_level dut("dut");
 
  sca_util :: sca_trace_file* atfs = sca_util :: sca_create_tabular_trace_file("datalog.dat");
  sca_util :: sca_trace(atfs, dut.n1, "out");
  sc_core::sc_start(0.5, sc_core::SC_SEC);
  sca_util :: sca_close_tabular_trace_file (atfs);
 
  return 0;
  
}
 
-- Error Message --
 
Error: SystemC-AMS: Error at least one sample period must be assigned per cluster 
the following modules are included in the current cluster (max. 20 printed):
dut.vtg_src
sca_linear_solver_0 containing modules:
dut.vin
 
I tried out changing set_timestep to output.set_timestep, but the error persists !!!
 
regards, 
Milind.

Share this post


Link to post
Share on other sites

   void set_attribute()

 

The function to set attributes for TDF MoC elaboration is called set_attributes() (plural form). You should be able to find such an error quite quickly by either adding simple debugging messages ("printf-debugging") or by using a proper debugger.

 

Greetings from Oldenburg,

  Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×