TFT experiments with CPLD >>>> 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. 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 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.
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. 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. 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:
Now I miss only anti-aliasing. :-) 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. (c) 2012, Stanislav Mašláň - All rights reserved.
|