fpga4fun.comwhere FPGAs are fun

Graphic LCD panel 2 - video generator

Prior to be able to display anything on the panel, we need to generate video-sync signals (H-sync and V-sync).

The LCD used for this project has the following characteristics:

With a 4-bit data input, we need 480/4=120 clocks horizontally.
With 320 lines, a complete video frame takes 120x320=38400 clocks.

The code looks like that:

parameter ScreenWidth = 480;
parameter ScreenHeight = 320;

reg [6:0] CounterX;  // counts from 0 to 119
reg [8:0] CounterY;  // counts from 0 to 319
wire CounterXmaxed = (CounterX==ScreenWidth/4-1);
wire CounterYmaxed = (CounterY==ScreenHeight-1);

always @(posedge clk)
begin
  if(CounterXmaxed)
    CounterX <= 0;
  else
    CounterX <= CounterX + 1;
end

always @(posedge clk)
if(CounterXmaxed)
begin
  if(CounterYmaxed)
    CounterY <= 0;
  else
    CounterY <= CounterY + 1;
end

reg HSync, VSync;
always @(posedge clk)
begin
  HSync <= CounterXmaxed;
  VSync <= CounterYmaxed;
end

Now, let's provide data to be displayed - first some graphics, then some text.