Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why won't EDA Playground show all eight times I set my clock to zero?

kvn0smnsn

Junior Member level 2
Joined
Nov 20, 2022
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
165
I'm trying to create a module that stores the contents of a queue, with two parameters, (nmElems) for the number of elements in the queue and (nmBits) for the number of bits in each element. My Verilog code for module (sQueue) is:
Code:
// (c) Kevin Simonson 2024

module sQueue #( nmBits = 2, nmElems = 1)
              ( head, clock, tail, shift, reset);
  localparam         maxBit  = nmBits  - 1;
  localparam         maxElem = nmElems - 1;
  output [ maxBit:0] head;
  input              clock;
  input  [ maxBit:0] tail;
  input              shift;
  input              reset;
  reg    [ maxBit:0] data [ maxElem:0];
  var                elem;

  always @( posedge clock)
  begin
    for (elem = 0; elem < nmElems; elem = elem + 1)
    begin
      if      (reset)
        data[ elem] <= 0;
      else if (shift)
      begin
        if (elem < maxElem)
          data[ elem] <= data[ elem + 1];
        else
          data[ maxElem] <= tail;
      end
    end
  end

  assign head = data[ 0];

endmodule
and my Verilog code for (t_sQueue) is:
Code:
// (c) Kevin Simonson 2024

module t_sQueue;
  reg  [ 7:0] insertee;
  reg         clock;
  reg         shift;
  reg         reset;
  wire [ 7:0] extractee;

  sQueue #( 8, 4) sq_8_4( extractee, clock, insertee, shift, reset);

  initial
  begin
    reset       = 1'b1;
    shift       = 1'b0;
    insertee    = 8'b00001000;
    clock       = 1'b0;            // Queue gets reset to all zeroes.
    #2 clock    = 1'b1;
    #2 reset    = 1'b0;
    clock       = 1'b0;            // 8 doesn't get inserted.
    #2 shift    = 1'b1;
    insertee    = 8'b00001010;
    clock       = 1'b1;            // Insert  10.
    #2 clock    = 1'b0;
    #2 shift    = 1'b0;
    clock       = 1'b1;            // (shift) is zero, so 10 only gets inserted
    #2 clock    = 1'b0;            // once.
    #2 shift    = 1'b1;
    insertee    = 8'b01000101;
    clock       = 1'b1;            // Insert  69.
    #2 clock    = 1'b0;
    #2 insertee = 8'b00000011;
    clock       = 1'b1;            // Insert   3.
    #2 clock    = 1'b0;
    #2 insertee = 8'b10001000;
    clock       = 1'b1;            // Insert 136. 10 should be visible.
    #2 clock    = 1'b0;
    #2 insertee = 8'b10100101;
    clock       = 1'b1;            // Insert 165. 69 should be visible.
    #2 clock    = 1'b0;
    shift       = 1'b0;
    #2 clock    = 1'b1;
  end

  always @( clock)
  begin
    if (clock == 1'b0)
      $display
        ( "time: %2t, reset: %1d, shift: %1d, insertee: %3d, extractee: %3d."
        , $time     , reset     , shift     , insertee     , extractee       );
  end

endmodule
When I go to EDA Playground and put (t_sQueue) in the left window and (sQueue) in the right window, and click on (Run), I get:
CPU time: .251 seconds to compile + .255 seconds to elab + .286 seconds to link
Chronologic VCS simulator copyright 1991-2021
Contains Synopsys proprietary information.
Compiler version S-2021.09; Runtime version S-2021.09; Jan 4 17:21 2024
time: 0, reset: 1, shift: 0, insertee: 8, extractee: X.
Execution interrupted or reached maximum runtime.
Exit code expected: 0, received: 137
Done
What am I doing wrong here? Why does it only show the time (clock) is zero at time 0, and doesn't show any of the other seven times (clock) gets set to zero?

A poster here suggested I post articles like this to the forum at "https://groups.google.com/forum/#!forum/eda-playground". I did that two hours ago, and nobody has responded to it yet, so I'm posting it here too.
 
the way you define the clock is a mess, that is why. your delay assignments are not doing what you think they do.

try this structure:
clock = 0;
#2;
clock = 1;
#2;

(note: this is still terribly unnecessary code for clock generation)
 
Use something like the following for clock generation in test-benches. Depending on the intended clock frequency, use an appropriate value for CLKIN_PERIOD.

initial
sys_clk_i = 1'b0;
always
sys_clk_i = #(CLKIN_PERIOD/2.0) ~sys_clk_i;
 
The testbench is o.k., there's however a trivial fault in sQueue causing stuck of the for loop

var elem must be integer elem

Code:
# time:  4, reset: 0, shift: 0, insertee:   8, extractee:   0.
# time:  8, reset: 0, shift: 1, insertee:  10, extractee:   0.
# time: 12, reset: 0, shift: 0, insertee:  10, extractee:   0.
# time: 16, reset: 0, shift: 1, insertee:  69, extractee:   0.
# time: 20, reset: 0, shift: 1, insertee:   3, extractee:   0.
# time: 24, reset: 0, shift: 1, insertee: 136, extractee:  10.
# time: 28, reset: 0, shift: 0, insertee: 165, extractee:  69.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top