kvn0smnsn
Junior Member level 2
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:
and my Verilog code for (t_sQueue) is:
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:
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.
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
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
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?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
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.