Jump to content
Sign in to follow this  
meera

adder - hierarchy- output issue

Recommended Posts

Hi,

 

  i was trying to obtain a fulladder through half adder. i was able to build and run the program but i find that outputs are not as expected. i feel it must be something to do with sensitivity. could anyone pls suggest that the mistake is.

 

full_adder.h

 

#include "half_adder.h"
SC_MODULE (full_adder) {
sc_in<bool>a,b ,cin;
sc_out<bool>sum,carry;
sc_signal<bool> c1,c2,s1;
 
void disp()
{
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"cin="<<cin<<endl;
cout<<"sum="<<sum<<endl;
cout<<"carry="<<carry<<endl;
cout<<endl;
}
 
void or()
      {
carry= c1|c2;
}
 
half_adder *halfl_adder1_ptr , *halfl_adder2_ptr;
 
SC_CTOR(full_adder){
 
halfl_adder1_ptr= new and("half_adder1");
halfl_adder1_ptr->a(a);
halfl_adder1_ptr->b(B);
halfl_adder1_ptr->sum(s1);
halfl_adder1_ptr->carry(c1);
 
   
halfl_adder2_ptr= new and("half_adder2");
   halfl_adder2_ptr->a(s1);
   halfl_adder2_ptr->b(cin);
   halfl_adder2_ptr->sum(sum);
   halfl_adder2_ptr->carry(c2);
 
SC_METHOD(or);
sensitive <<c2<<c1;
SC_METHOD(disp);
sensitive <<sum<<carry;
  }
~full_adder(){
delete halfl_adder1_ptr;
delete halfl_adder2_ptr;
}
};
 
 
 
 
 
 
 
 
 

Share this post


Link to post
Share on other sites

I'm not sure what you mean. You could change the printing code to use an SC_THREAD, and then you could add a small wait to allow the outputs to settle. And make the printing process only sensitive to sum, e.g.

#include "half_adder.h"
SC_MODULE (full_adder) {
  sc_in<bool>a,b ,cin;
  sc_out<bool>sum,carry;  
  sc_signal<bool> c1,c2,s1;
 
  void disp()
  {
    while (true) {
      wait(1, SC_NS);
      cout<<"a="<<a<<endl;
      cout<<"b="<<b<<endl;
      cout<<"cin="<<cin<<endl;
      cout<<"sum="<<sum<<endl;
      cout<<"carry="<<carry<<endl;
      cout<<endl;
    }
  }
 ...
 
 
  SC_CTOR(full_adder){
   ...
    SC_THREAD(disp);
    sensitive <<sum;
  }
...
};

regards

Alan

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
Sign in to follow this  

×