1
\$\begingroup\$

I am trying to write memory elements using for loop. The for loop runs, and I get the value of k changing 10 times. But I am not getting write and select values changing; they remain constant. As they are in while loop so wouldn't they change?

initial 
begin
for(k=0; k<10; k=k+1)
 begin  
  address=k;  
  data_in=(k+k); 
  write=1; select=1;
  #2 write=0; select=0;
 end
end
\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

You have zero-time glitches on the write and select signals, but you can't see them in waveforms. You need to add another delay inside the loop; the single #2 delay that you have is insufficient.

Here is a runnable example, where I added another #2 at the end of the for loop:

module tb;

reg write, select;
integer k, address, data_in;

initial 
begin
    for (k=0; k<10; k=k+1) begin  
        address=k;  
        data_in=(k+k); 
        write=1;
        select=1;
        #2 write=0;
        select=0;
        #2;
    end
end

endmodule

The waves show write and select changing.

enter image description here

The waveforms were generated from the Synopsys Verdi tool.

\$\endgroup\$
4
  • \$\begingroup\$ which simulator are you using? \$\endgroup\$
    – Zerox
    Aug 4, 2023 at 18:11
  • \$\begingroup\$ @Zerox: I used a couple simulators to check this: Cadence and Synopsys. Why do you ask? Do you get a different result? This should work on all simulators. \$\endgroup\$
    – toolic
    Aug 4, 2023 at 18:13
  • \$\begingroup\$ Than you for reply....Ut works for me....As modelsim and vivado simulator only gives green waveform by default.It is colourfull so looks amazing \$\endgroup\$
    – Zerox
    Aug 4, 2023 at 18:19
  • \$\begingroup\$ @Zerox: You're welcome. I updated my Answer with the tool information. What should I do when someone answers my question? \$\endgroup\$
    – toolic
    Aug 4, 2023 at 18:21
0
\$\begingroup\$

The write and select are changing, but you are continuously overwriting them. Each time your For Loop iterates, it sets write = 1 and then sets write = 0, this repeats itself 10 times so after the loop has ended both your write and select = 0

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.