Hi all,
I am new to systemC and i am trying to create two modules( a constant and counter module) and trying to make a connection between them and see the outputs and see how the data flows.
please see the code of the modules and connection between them.
Constant.h #include "systemc.h" #include <stdlib.h> #include <iostream> SC_MODULE(constant) { sc_in<bool> clk; sc_out<bool> output; bool A; void process(){ A=1; output.write(A); cout<< "@"<< sc_time_stamp() << " ::constant output written" << output << endl; } SC_CTOR(constant){ SC_METHOD(process); sensitive << clk.pos(); } };
counter.h #define SC_INCLUDE_FX #include <systemc.h> #include <iostream> SC_MODULE (counter) { sc_in<bool> reset; sc_in<bool> enable; sc_out< sc_ufixed< 12,12, SC_TRN, SC_SAT> > counter_out; sc_ufixed < 12,12, SC_TRN, SC_SAT> count; void incr_count () { if (reset.read() == 1) { count = 0; counter_out.write(count); cout<<"@" << sc_time_stamp()<< "::COUNTER IS RESET " << counter_out.read() << endl; } if (enable.read() == 1) { count=count+1; counter_out.write(count); cout<<"@" << sc_time_stamp() <<" :: Incremented Counter "<<counter_out.read()<<endl; } } SC_CTOR(counter) { cout<< " executing counter"<< endl; SC_METHOD(incr_count); sensitive <<reset << enable ; } };
test.cpp
#define SC_INCLUDE_FX #include "systemc.h" #include "counter.h" #include "constant.h" int sc_main (int argc, char* argv[]) { sc_buffer<bool> rstsignal; sc_buffer<bool> ensignal; sc_buffer <sc_ufixed<12,12, SC_TRN, SC_SAT > >outputsignal; sc_clock clock("CLOCK", 1, SC_SEC); constant c1("constant"); c1.clk(clock); c1.output(ensignal); counter c2("counter"); c2.reset(rstsignal); c2.enable(ensignal); c2.counter_out(outputsignal); rstsignal = 0; sc_start(3, SC_SEC); rstsignal = 1; sc_start(3, SC_SEC); return 0; }
output
executing counter @0 s :: constant output written 0 @0 s :: Incremented Counter 0 @0 s :: constant output written 1 @0 s :: Incremented Counter 1 @1 s :: constant output written 1 @1 s :: Incremented Counter 2 @2 s :: constant output written 1 @2 s :: Incremented Counter 3 @3 s:: COUNTER IS RESET 4 @3 s :: Incremented Counter 4 @3 s ::constant output written 1 @3 s:: COUNTER IS RESET 1 @3 s :: Incremented Counter 1 @4 s :: constant output written 1 @4 s:: COUNTER IS RESET 1 @4 s :: Incremented Counter 1 @5 s ::constant output written 1 @5 s:: COUNTER IS RESET 1 @5 s :: Incremented Counter 1
As expected whenever there is posedge clock , the constant module produces the output and the counter module is getting incremented.
But as you can see @0s and @3s i am getting two outputs of the counter module.
Can anyone what is the reason behind it ? which output should i consider ? and do i need to change any timing constraints to avoid it?
Thanks in advance.