TFT experiments with CPLD

[cze]

>>>> WARNING: very poor translation!!! <<<<

   I have a few unused 640x480 color TFT modules. these modules of course don't have controller with video-memory so it's necessary to continuously refresh it with image data same as CRT's with frame rate 50-60Hz and pixel clock 25MHz or so. That's of course impossible with small 8-bit MCU's I'm used to (over 50MBytes/s data rate). But fortunately I have developement kit XILINX CoolRunner 2 XL with XC2C256-7. This CPLD is more than enough for entire controller design.

XILINX CoolRunner2 XL kit XILINX CoolRunner2 XL kit + Sharp's LQ064V3DG01 TFT (640x480x18-bit)

1. Bitmap ping-pong

   After some basic experiments with color stripes, rainbow, etc. I've tried to implement small bitmap into CPLD. It's resources are limited but it was possible to fit few hundred pixels in it.
   TFT connection is very simple, everything is connected in 3V3 logic but because of high slew rate of CPLD signals it was neccessary to insert 100R damping resistors in series. The value of resistors depends on cable type/length. In my case it is 10cm of standard 1.27mm flat cable. Without these resistors I had troubles with synchronization and there were some random pixels.

Circuit diagram

   TFT is connected with static ENABLE signal so visible area is fixed according to datasheet. Color data are connected in 16-bit mode only because I needed few more pins from kit connector. CPLD is clocked at double rate (50MHz) so it is much easier to setup correct timing of pixel-clock. It can be shifted with 90° step.

Bitmap test Bitmap test Bitmap test

   Demo program is made in XILINX ISE 9.2 in VHDL. I'm not very skilled in this language so I guess it's not well optimized or pretty but it does work just fine.
   Source image is inserted as function "std_logic pixels(std_logic_vector col, std_logic_vector row)" which is generated with simple utility I made. It can convert any 24-bit black/white bitmap to VHDL package that can be included into project. Size of input image is unlimited but the CPLD is not able to handle more than 1000 pixels or so (depends on image complexity).

Source code download: CoolRunner2_TFT_test.zip (1522kB).



2. Rotozoomer

   Following program generates one of the basic demo effects: Rotozoomer. It may look a bit complicated for CPLD but in fact the algorithm is pretty simple. It's an ordinary vector rotation except in iterative form:

// precalculate sin/cos coefficients
dsin = scale*sin(angle);
dcos = scale*cos(angle);

// render surface
x = 0;
y = 0;
for(j=0;j<rows;j++)
{
	x = xrow;
	y = yrow;

	for(i=0;i<columns;i++)
	{
		// new pixel
		x += dcos;
		y += dsin;

		// get source image pixel
		pixel=GetSourceRasterPixel(x % xsize, y % ysize);

		// put it on current surface position
		PutPixel(pixel, i, j);
	}

	// new row
	xrow += dsin;
	yrow -= dcos;
}

   As it is obvious the only problem is to generate sine and cosine functions. CPLD is simply not enough to implement full lookups so I generated only 5-bit differences, 32 points per half wave. Rest up to 256 points per half period is generated runtime (integration). In this case all tables are just 2x32x5 bits and that fits into XC2C256 with no problems. The lookups also contains amplitude modulation (zoomer effect). This solution is not optimal but for higher rotation speeds it looks smooth.

Rotozoomer Rotozoomer Rotozoomer

   Since it worked fine with chess-board I tried to add small bitmap. After some optimalizations I was able to fit it into my CPLD:

Rotozoomer + bitmap Rotozoomer + bitmap Rotozoomer + bitmap

   Now I miss only anti-aliasing. :-)

Source code download: CoolRunner2_TFT_roto.zip (1622kB).


3. Rotozoomer + color BMP

   My last experiment was to remove rainbow generator and implement small color bitmap instead. After color palette reduction it fits. Optimalizator generates few warnings about buffering some of the outputs but it works. Following zip also containts new version of utility for bitmap to VHDL covnerison. It now can convert 24-bit color bitmap into three separate functions with RGB layers.

Source code download: CoolRunner2_TFT_roto_color.zip (1715kB).

Rotozoomer + RGB bitmap


(c) 2012, Stanislav Mašláň - All rights reserved.

Last update: 15.5.2012 Up