I'm practicing Verilog using the HDLBits website, and I am trying to solve this problem where I have been given a 32-bit wide input signal and I have to detect whenever a 1 to 0 transition occurs and set the corresponding output bit high until I receive a reset signal. If both the transition and the reset occur simultaneously, the reset takes precedence. The reset is a synchronous reset.
A sample waveform is attached below:
My attempt at this problem was to find the AND of the input at the previous clock cycle and the negative of the input in the new clock cycle to set the bit where the 1 to 0 transition occurred. My logic:
Input (previous clock cycle): 10011001
Input (next clock cycle): 01001010
Negative of that input: 10110101
AND of old input and new input: 10010001
Verilog code:
module top_module (
input clk,
input reset,
input [31:0] in,
output [31:0] out
);
reg [31:0]in_prev;
always @(posedge clk) begin
in_prev <= in;
if(reset)
out <= 32'b0;
else
out <= in_prev & ~in;
end
endmodule
However, the console shows me that my code is wrong and there are mismatches in the waveform. Can anyone tell me why this is happening?
Mismatch waveforms:


