Jump to content

How to implement adding function using next_trigger in SC_METHOD?


Minu

Recommended Posts

Hi @David Black,

Thanks for answering my question.

This I have implemented earlier but in this way I am not getting correct out.

MY testbench input is 

@0ns a=0     b=0. Out=0

@5ns a=5.     b=0. Out=5

@8ns a=5.     b=10 out=15

@15ns a=7.     b=7 out=14

And I should get output after 2ns so the output will be appear at 

@0ns a=0     b=0. Out=0

 

@7ns a=5.     b=0. Out=5

 

@10ns a=5.     b=10 out=15

 

@17ns a=7.     b=7 out=14

Above code is not fulfilling this requirement.

It would be great if you provide some insights on this requirement.

Link to comment
Share on other sites

  • 3 weeks later...

The code that uses SC_THREAD has two waits:

  while(1){
    wait();//wait for sensitive list to occur
   	wait(2,SC_NS);
      		cout<<"\nWriting on out,at time"<<sc_time_stamp();

  	out.write(a.read()+b.read());
  }

The first `wait` blocks until one of the entries in its static sensitivity fires:

    SC_THREAD(adding);
    sensitive<<a;
    sensitive<<b;

The SC_METHOD replacement has only a single `next_trigger` - so it is not equivalent to the earlier implementation:

  int c;
  c=a.read()+b.read();
  out.write(c);
  next_trigger(2,SC_NS);

You need to implement a state machine in the SC_METHOD using next_triggers if you want the same behavior. Check this post for example:

 

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