Well, since my question in my first post was both vague and overly specific (graphic LCD controller for STN, not all that common) rather than create another topic, I'll start with asking questions that can help me move along. Although I studied basic programmable logic at university (some 13 years ago..CPLD's, state machines etc..) I'm getting back into it because, well, its a handy skill to have, plus theres an ever growing list of my own projects that I think could benefit from it. So bear with me as its quite basic stuff.
I decided to make a basic pipeline, where the block is clocked at 8x the pixel clock, giving me 8 clock cycles between writes, so a state machine/pipeline that performs tasks sequentially before every write to the LCD. I am aware that is is best not to divide down the input clock to clock other logic, but have it all clocked by the same clock, so the first port of call is a simple 3-bit counter that outputs single pulses when the counter is 000, 001, 010 etc.. then use these as 'enable' lines to the various parts. I fell at the first hurdle.
parameter ScreenWidth = 6;
parameter ScreenHeight = 6;
reg [ 7:0] CounterX;
reg [ 7:0] CounterY;
wire outupdate;
wire halfway_pipe;
wire pix_strobe;
reg [2:0] state_count;
wire CounterXmaxed = (CounterX==ScreenWidth/4-1);
wire CounterYmaxed = (CounterY==ScreenHeight-1);
assign outupdate = (state_count == 0);
assign halfway_pulse = (state_count == 4);
assign pix_strobe = (state_count == 0);
always @(posedge clk)
begin
state_count <= state_count +1;
if (outupdate)
pxlclkout <= 1;
else if (halfway_pulse)
pxlclkout <= 0;
end
always @(posedge clk)
begin
if (outupdate)
begin
if(CounterXmaxed)
CounterX <= 0;
else
CounterX <= CounterX + 1;
end
end
always @(posedge clk)
begin
if (outupdate)
begin
if(CounterXmaxed)
begin
if(CounterYmaxed)
CounterY <= 0;
else
CounterY <= CounterY + 1;
end
end
end
'pxlclkout' produces 50% duty cycle at clock/8 as expected, so the 'state_counter' is counting, and 'outupdate' must produce a single pulse, one clock period, when the counter is 000. Same goes for halfway_pulse at state_count == 4. The 'pix_strobe' is redundant but I just added it as an output signal for testing. CounterXmaxed remains high, and CounterX does not change. However, CounterY does increment, and indeed produces a pulse - one CounterX period wide, every 6 pxlclkouts. So counterY is counting as CounterX should.
CounterY should only be incremented when counterX rolls over. I didn't use a single counter because I would like to be able to change the resolution later on for configuring it to work with different LCD's.
I'm probably missing something obvious, and 'asking on a forum' is down in the list of things to try, but I just can't see where I'm going wrong here. Thanks!