Skip to main content
Tweeted twitter.com/#!/StackElectronix/status/641758712328253440
Added information requested in comments or that I thought would clear something up.
Source Link

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b1;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.

Update 1: oe is an input to the device under test and is set like so -

@ (posedge clk) begin
    oe = 0;
end

Update 2: enter image description here

Update 3: iverilog was used as the simulation tool.

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b1;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b1;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.

Update 1: oe is an input to the device under test and is set like so -

@ (posedge clk) begin
    oe = 0;
end

Update 2: enter image description here

Update 3: iverilog was used as the simulation tool.

edited body
Source Link

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b0;1'b1;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b0;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b1;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.

Source Link

Register behaving like latch in verilog

I have the following block of code -

always @(posedge clk) begin
    if (reset) 
        oe_hold <= 1'b0;
    else begin
         oe_hold <= 1'b0;
         if (oe && (oe_hold | we)) 
             oe_hold <= 1'b0;
    end
end

In the above fragment, oe and we are driven using combinational logic. I'd expect that if oe_hold and oe are high, at clock edge 0 and oe goes low at t=1, then oe_hold would go low at t=2, since oe_hold is a register and should take on its input a cycle later.

However, in simulation, oe_hold behaves like a latch. It goes low at the same clock edge as oe. If I drive oe on the negative edge in the testbench, oe_hold goes low on the following clock edge (i.e., the same edge it went low were oe driven on the positive edge).

Can someone explain this behavior and tell me why it occurs?

Thank you.