Altera_Forum
Honored Contributor
13 years agoWarning Combinational Loop
I'm getting a warning (332125) from Quartus which is telling me that it found a combinational loop. I found an example of a schematic of what a combinational loop means and I understand that. Its feeding the output back to the input through some logic that is not clocked so it generates a race condition.
The problem is I do not know why my verilog source code is creating such a loop and I don't know how to accomplish the task I'm trying to do. The goal is to create an address register which I can set from the outside world by toggling an address latch enable (ALE) bit. Then I want to auto increment the address inside the device every time I toggle a read bit (which reads what the address is pointed to). Heres the code I'm trying to use (simplified):
module foo(inout wire data, input bit ale, input bit rd, input bit clk);
reg data_in;
reg addr;
// clock the data bus into the input register
always_ff @ (posedge clk)
data_in <= data;
// set the addr at the pos edge of ale, increment it at neg edge of rd
always_ff @ (posedge ale, negedge rd)
begin
if (ale) addr <= data_in;
else addr = addr + 1'b1;
end
The addr increment seems to create the combinational loop because if I comment it out then there are no problems. But how can I do what I want? I can't use the clk signal to create sequential logic because that will clock it many times, not just on the falling edge of rd. Do I need to create a state machine?