I am working on a school project for a 2-stage pipeline processor in Verilog HDL and have run into an issue that has stumped me for a few days. I will add small code snippets and a picture of the signals I am getting through ModelSim through my description. I am simply taking the output from my ALU:
ALU #(BUS_WIDTH(BUS_WIDTH)) alu (
.A(Amux),
.B(Bmux),
.sel(ALUsel),
.Dout(ALUout)
);
I am then passing it directly to the buffer between my stages in the same file in the following manner (other signals and data being buffered removed for ease of reading):
Buffer #(.BUS_WIDTH(BUS_WIDTH)) buff(
.clk(clk),
.reset(reset),
.aluA(ALUout),
.aluB(ALUoutM),
);
The inside of the buffer module looks like the following (I am again removing everything else being buffered for ease of reading:
module Buffer(
input clk,
input reset,
input [31:0] aluA,
output reg [31:0] aluB
);
always @(posedge clk)
begin
if (~reset)
begin
aluB <= 32'h00000000;
end else
begin
aluB <= aluA;
end
end
endmodule
The following image is what I am having issues with:
This is happening a few cycles after the testbench has been started and the previous cycles run successfully. Looking at the image, the top signal is the ALUout and the second signal is ALUoutM. My desired outcome is for my ALUoutM signal to match my ALUout signal from the previous clock cycle (I have verified that a full clock cycle is the period between the signal changes in the image). As previously stated, this desired outcome is seen in all cycles previous to this one. Between the first and second cycle, the outcome isn't as desired, but then goes back to being correct. I have triple checked and verified that my ALUoutM isn't being driven by any other signals. I am mostly trying to figure out if I am making a beginner mistake with verilog that I am unaware of. Thank you for any help.
ADDITION
Per the comments of Oldfart (I love that name), I was able to add the signals of the buffer into my simulator also, but it is displaying the exact same behavior as the input signals are. In the following image, you'll notice a correct behavior for the first 4 clock cycles and then a random value of 0x00000000 coming out of the buffer. Then it is correct for one more clock cycle before completely flying off the rails.
aluB
inBuffer
an input? – Unnalu
andaluB
from yourBuffer
module in the waveform display and trace where things go wrong. Why? Because I don't believe in "triple checking" even if I do it myself. It is just too easy to overlooks a case. – OldfartALUout
is directly plugged into thealuA
port ofBuffer
andALUoutM
is plugged into thealuB
port ofBuffer
. Since that is the case, I am understanding you to mean that I should grab both the ports themselves? How would I do this? – Cody Berry