Jump to content

Error when trying Clock divider or multiplier circuit using sc_clock


viswanathb

Recommended Posts

My intention is to devise a clock multiplier or divider circuit based on a reference clock.

 

//CLOCK DUT
//clk_dut.h

#include "systemc.h"

SC_MODULE(clk_dut)
 {
  void gen()
  {
  double ref_clk =100;
  double clk1_div =10;
  double clk2_div=5;

sc_clock refclk("refclk",ref_clk,SC_NS);
sc_clock clk1("clk1",ref_clk/clk1_div,SC_NS);
sc_clock clk2("clk2",ref_clk/clk2_div,SC_NS);
  }
 SC_CTOR(clk_dut)
  {
   SC_THREAD(gen);
    sensitive << refclk.pos() << clk1.pos() << clk2.pos();
  }
};


//TOP MODULE

#include "systemc.h"
#include "clk_dut.h"

int sc_main(int argc,char *argv[])
 {
//instantiating the dut
clk_dut dut("dut");

dut.gen();

 sc_start(100,SC_NS);

return0;
  }
 

Error Message

 

clk_dut.h: In constructor ‘clk_dut::clk_dut(sc_core::sc_module_name)’:
clk_dut.h:18: error: ‘refclk’ was not declared in this scope
clk_dut.h:18: error: ‘clk1’ was not declared in this scope
clk_dut.h:18: error: ‘clk2’ was not declared in this scope
./sim: Command not found.
Please help me resolve this.

Also When i try to trace the clock files in the SC_THREAD after the sensitivity list using

 

sc_trace_file *fp;

fp=sc_create_vcd_trace_file("wave");

sc_trace(fp,refclk,"clk");

I get the same kind of scope error.

Please help me resolve this.

Link to comment
Share on other sites

You've declared your clock objects as member variables of an SC_THREAD, which is a bad idea - when the thread ends, the clocks disappear. Also your thread has no infinite loop, so it will end immediately.

The clock objects should be class members, something like this:

//CLOCK DUT
//clk_dut.h

#include "systemc.h"

SC_MODULE(clk_dut)
 {

  sc_clock refclk;
  sc_clock clk1;
  sc_clock clk2;


 SC_CTOR(clk_dut): refclk("refclk",100,SC_NS), 
                   clk1("clk1",10,SC_NS),
                   clk2("clk2",5,SC_NS)
  {

  }
};

If you want to declare them in a module, as you've shown, then you'll probably want to bind the clocks to some ports as well,

 

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