Error (10818): Can't infer register because it does not hold its value outside the clock edge

Amira picture Amira · Feb 20, 2017 · Viewed 7.3k times · Source

I have been trying to implement an asynchronous counter, and the simulations are correct, but I keep on getting this error from Quartus

Error (10818): Can't infer register for "encoderCounta[0]" at EncoderComputation.vhd(35) because it does not hold its value outside the clock edge.

Any help would be appreciated!

GPIO_0(1) <= encoderBits(0);
GPIO_0(3) <= encoderBits(1);
GPIO_0(5) <= readPosition;
GPIO_0(7) <= clk;


PROCESS(a)
BEGIN
    IF (rising_edge(a)) THEN
        IF (b = '0') THEN
            IF (encoderCounta = 399) THEN
                encoderCounta <= 0;
            ELSE 
                encoderCounta <= encoderCounta + 1;
            END IF;
        ELSIF(b = '1') THEN
             IF (encoderCounta = 0) THEN
                encoderCounta <= 399;
             ELSE
                encoderCounta <= encoderCounta - 1;
             END IF;
        END IF;
    ELSE
        IF(b = '1') THEN
             IF (encoderCounta = 399) THEN
                encoderCounta <= 0;
             ELSE
                encoderCounta <= encoderCounta + 1;
             END IF;
        ELSIF (b = '0') THEN
             IF (encoderCounta = 0) THEN
                encoderCounta <= 399;
             ELSE
                encoderCounta <= encoderCounta - 1;
             END IF;
        END IF;
    END IF;
END PROCESS;


result <= encoderCounta;

Answer

Laleh picture Laleh · Feb 21, 2017

When you want a synthesizable code, code the way it will infer desired hardware.

A register is supposed to change value only on clock edge and keep the value till next clock edge. You say IF (rising_edge(a)) assign some value, which is ok. But then you have put an else! You are also assigning some values to counter when it is not rising edge. This is not how a register works. If it is not rising edge, do NOT change value, i.e. remove that else part.