Jump to content

How can I control counters within a for loop with a control signal in a SC_THREAD?


Recommended Posts


I'm writing a module in SystemC which basically works as follows: it receives a string of bytes through a port p_in and a control signal through the port h. The module must save the bytes within a matrix matrix just if the h signal is true. Within the SC_THREAD I'm using I implemented this:

void MY_MODULE::my_method(){

  //put all the output ports to 0


    //The module waits while the signal h is false
    while(!h) wait();

    //The iterations to fill in the matrix begin
    //The iterations must work just if h = true
    for(i=0; i<100; i++){
      for(j=0; j<100; j++){
        matrix.nmmatrix[i*matrix.width+j] = p_in;
        while(!h) wait();

The problem I have is that the counters i and j start to increment one clock cycle after h passes from false to true. The behavior I'm trying to simulate is that the counters i and j start to increment in the same clock cycle when h passes from false to true and the counters must not increment while h is false. Could you please give a hint of what I am doing wrong?


Link to comment
Share on other sites

It looks to me that if you assign h true and the first value to p_in using the same clock as your process, then it should work, i.e. you should be able to sample p_in with i = 0 and j = 0 correctly.

It's hard to say without seeing now you are applying the stimulus to h and p_in.




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.

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