Jump to content

process running only once?


afzalmd

Recommended Posts

Hi,

In my module, if input reset signal is LOW, then module should produce a defined delay and after that it should make the output reset signal to HIGH (which will be given to other modules). In vice versa it should write the input reset to the output reset signal as it is. Stimulis are given in the testbench file, changing after every 50ns. In this case, module works fine for the first time, but when after some time input reset goes again to LOW, it is not working and does not produce any delay (process is not called after that).

Can you described what is wrong in this code or something missing?

Code is given:

//init.h

class init:public sc_module{

public:

sc_in<bool> ck_t_i;

sc_in<bool> reset_i;

sc_in<sc_lv<CKE_C> > dcke_i;

sc_out<bool> reset_o;

sc_out<sc_lv<CKE_C> > dcke_o;

void conv();

init(sc_module_name name):sc_module(name){

SC_THREAD(conv);

sensitive<<ck_t_i.pos();

}

private:

SC_HAS_PROCESS(init);

};

//init.cpp

void init::conv(){

sc_time Tint;

sc_time Tact;

sc_time Tstab;

sc_time diff;

Tint = sc_time(tINT, SC_PS); //8000

Tact = sc_time(tACT, SC_FS); //8ntCK and tCK is 4ns

Tstab = sc_time(tSTAB, SC_NS); //5

diff=Tint-Tact;

if(!reset_i.read()){

wait(diff); //after diff, DCKE should be zero

dcke_o.write("00");

wait(Tact); //after tACT (or initialization time), reset should be true

reset_o.write(true);

wait(Tstab); //after tSTAB

dcke_o.write("11");

}

else{

reset_o.write(reset_i.read()); //for normal operation

}

}

In attached waveform, d_rst is input reset and q_rst is output reset.

post-171-0-99659100-1351594364_thumb.png

Link to comment
Share on other sites

According to the SystemC standard, an SC_THREAD process is indeed only started once. Once the function completes, the corresponding thread is terminated. If you want to keep it running, you need to put an (endless) loop inside the process body.

Don't forget to put at least one wait() on each control flow path. Something like:

void init::conv()
{
 //it's C++  - prefer direct initialization over assignment
 sc_time Tint (tINT, SC_PS);  //8000
 sc_time Tact (tACT, SC_FS);  //8ntCK and tCK is 4ns
 sc_time Tstab(tSTAB, SC_NS); //5

 sc_time diff = Tint-Tact;

 while(true) // endless loop
 {
if(!reset_i.read()){
  wait(diff);	//after diff, DCKE should be zero
  dcke_o.write("00");
  wait(Tact);	//after tACT (or initialization time), reset should be true
  reset_o.write(true);
  wait(Tstab);	//after tSTAB
  dcke_o.write("11");
}
else{
  reset_o.write(reset_i.read());	//for normal operation
}
wait(); // wait for the next clock edge (required!)
 }
}

Greetings from Oldenburg,

Philipp

Link to comment
Share on other sites

Hi Phillip,

I tried to implement in this way . First problem I got, I can't display the result on a waveform. it does not appear. When I check manually, system still remains in the first instance of module. For example: if input reset stimuli is changing after every 50ns, then say, system will check for reset and it finds reset to be LOW, until 50ns. Then after 50ns it enters in the "else" statement and remains there. I tried to print the time_stamp and it does not change the value of time after 50ns.

Link to comment
Share on other sites

It's quite hard to understand your answer without more details.

I tried to implement in this way . First problem I got, I can't display the result on a waveform. it does not appear.

What does this mean? How does a waveform "appear"?

  • How do you generate your clock events?
  • How do you start the simulation?
  • How/when do you stop it?

When I check manually, system still remains in the first instance of module.

This is very hard to parse.

  • What is the "first instance"?
  • How do you "check manually"? Debugger? printf?

For example: if input reset stimuli is changing after every 50ns, then say, system will check for reset and it finds reset to be LOW, until 50ns. Then after 50ns it enters in the "else" statement and remains there. I tried to print the time_stamp and it does not change the value of time after 50ns.

How can the control flow "remain" in the else part? What is the clock frequency? It looks like you want to model a synchronous design, where you check the reset signal at every rising clock edge. I would expect to see an advance of the timestamp according to the clock frequency.

Wild guess:

  • Did you include the last line in the loop I posted above?
  • I.e. do you have a wait() for static sensitivity on the input clock after your condition?

Greetings from Oldenburg,

Philipp

Link to comment
Share on other sites

Hi Phillip,

What does this mean? How does a waveform "appear"?

  • How do you generate your clock events?
  • How do you start the simulation?
  • How/when do you stop it?

I mean, I can't see trace file on gtkwave because when I click on that file, it doesn't dispaly result. At this point I don't know the reason. But when I don't use while loop, it appears fine.

This is very hard to parse.

  • What is the "first instance"?
  • How do you "check manually"? Debugger? printf?

I mean, for the first stimuli. I give different values at input, including "reset" and after 50ns I give some other values. Just like simple testbench. For first stimuli values, the above code behaves in the way as it should be. But after 50ns and so on, there is no increment in time. For example: if I print a statement in else statement, it will appear with time stamp of 50ns (which is true in my case), but for rest of the simulation, this time is not changing and it seems that at every rising edge of the clock, this statement is appearing again and again with the same value of time.

How can the control flow "remain" in the else part? What is the clock frequency? It looks like you want to model a synchronous design, where you check the reset signal at every rising clock edge. I would expect to see an advance of the timestamp according to the clock frequency.

Well, I am using clock signal of 4ns. Yes it is a synchronous design and I need to check different input values at rising edge of clock.

In my program. I am giving same input clock to testbench (which gives stimuli to DUT) and DUT as well.

Wild guess:

  • Did you include the last line in the loop I posted above?
  • I.e. do you have a wait() for static sensitivity on the input clock after your condition?

Yes, I used that function and also defined some time for wait statement (just to check if works or not). But each time it gives similar result.

Link to comment
Share on other sites

Muhammad,

please use proper "quote" blocks, when quoting earlier messages. Otherwise it's quite difficult to separate your reply from the previous text.

You have not given enough further details. My crystal ball is quite unreliable these days, so I think you need to show some code (preferably wrapped in a "code" block to enable syntax highlighting).

  • How does your process look like with the loop and the debugging statements included?
  • How do you generate the stimuli?
    Show the relevant parts of your testbench.
  • How do you start the simulation? With a plain sc_start() or with a fixed time?
    Show the sc_main function.

Greetings from Oldenburg,

Philipp

Link to comment
Share on other sites

Hi Philip,

Here I come across a small program to check the functionality. It uses only reset input to check the functionality(actual program uses other inputs also).

Even if I use with SC_METHOD and use next_trigger, again it gives wrong results.

dut.h

class init:public sc_module{
public:
sc_in<bool> clk;
sc_in<bool> reset;
sc_out<bool> rst_o;
void conv();
init(sc_module_name name):sc_module(name){
 SC_THREAD(conv);
 sensitive<<clk;
}
~init(){
}
private:
SC_HAS_PROCESS(init);
};

dut.cpp

void init::conv(){
sc_time Tint;
sc_time Tact;
sc_time Tstab;
sc_time diff;
Tint = sc_time(tINT, SC_PS); //it should be in micro seconds (us)
Tact = sc_time(tACT, SC_FS); //in nano seconds(ns)
Tstab = sc_time(tSTAB, SC_NS); //in micro seconds(us)
diff=Tint-Tact;
while(true){
 if(!reset.read()){
  wait(diff);   //after diff, DCKE should be zero
  rst_o.write(true);
  wait(Tact);   //after tACT (or initialization time), reset should be true
	 rst_o.write(false);
	 wait(Tstab);  //after tSTAB;
	 rst_o.write(true);
 }
 else{
  rst_o.write(reset.read());	    //for normal operation
 }
}
wait(); // wait for the next clock edge (required!)
}

For testbench, I am giving stimuli as follow:

class testbench:public sc_module{
public:
sc_in<bool> clk;
sc_out<bool> rst;
void stim();
testbench(sc_module_name name):sc_module(name){
 SC_THREAD(stim);
 sensitive<<clk;
}
~testbench(){
}
void stim(){
rst.write(false);
wait(50, SC_NS);
rst.write(true);
wait(50,SC_NS);
rst.write(false);
wait(50, SC_NS);
rst.write(true);
}
private:
SC_HAS_PROCESS(testbench);
};

All modules are attached in the top module and that module is instantiated in main file.

main.cpp

int sc_main (int argc, char* argv[]){
//default time values
sc_set_default_time_unit(1,SC_PS);
sc_set_time_resolution(1,SC_FS);
top tp("tp");
 cout<<"Simulation Started\n";
 sc_start(200, SC_NS);
 sc_stop();
return 0;
}

I hope now it will be clear to find out the problem or something which I am missing.

Link to comment
Share on other sites

Hi Alan,

I was missing that wait() statement, which was outside of while loop. Now my program is working fine and I am getting desired results (which I can check by printing time values). tINT etc are defined values of time.

Thanks to phillip as well. :)

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