Implementing a counter in VHLD with edge triggered clear

I'm still giving my first steps learning VHDL and after a couple of days I could not yet find a solution for this problem.

What I'm trying to do is to implement an LCD controller on an Altera MAX II CPLD that will receive signals from an existent device.

One of the signals is the frame signal that is high while a frame is being received and low otherwise. I also have a clock signal that changes state from low to high for each pixel data available.

On my CPLD I have a line and a column counter that need to be reset on the first rising edge of the clock, after the beginning of each frame and the column counter needs to be incremented on each rising edge of the clock.

What I'm trying to achieve is represented on the following diagram.

The problem I'm facing is that if I try to reset the counters on the rising edge of the frame signal and increment them on the rising edge of the clk signal I get the following error:

Error (10821): HDL error at AddressController.vhd(116): can't infer register for "line[0]" because its behavior does not match any supported register model


I think that should be an easy way to do this but I'm having trouble to figure it out.

• Do everything on clock edges. Reset the counters on the first clock edge after Frame goes high. (Hint : Save a copy of Frame on the same clock edge so you can tell that succeeding clocks aren't the first...) – user_1818839 Nov 8 '14 at 14:50
• @BrianDrummond: It might not be that simple. Based on the diagram, there may not be any clock edges that occur while frame is low. – Dave Tweed Nov 8 '14 at 14:54
• Thank you Brian for your suggestion, but as @DaveTweed noticed the problem is that I only have clocks when frame is high, so I cannot use the clock in oder to do that. – Bruno Ferreira Nov 8 '14 at 14:56
• So Frame would have to be used as an active-low Reset to the "save Frame" register. – user_1818839 Nov 8 '14 at 14:58
• @BrianDrummond Thank you for your suggestion. I had already thought about using a variable in order to identify the first clock edge but I was not sure when to clear it or set it. – Bruno Ferreira Nov 8 '14 at 15:35

In this specific case, you could use a simple R-S latch. This latch would be set by a low on the frame signal, and cleared by a high on the clk signal. Call the output of this latch first. In your counter, which is driven by the clk signal alone, if first is set, you clear the counter; otherwise, you increment the counter.