Recently, I finished the first working version of my VGA graphics card which I built using a 144 macrocell CPLD*. It's capable of driving 640x480 by 8 bit color resolution on most any monitor which will take a VGA input, from almost anything which has an SPI output.
I walk you through what it takes to create an FPGA graphics card with VHDL (or a CPLD, like I did) - follow along!
Video card with Programmable Logic
I wanted to talk about the project (and share information, code, and instructions to build it for yourself!). A usable product is now complete and available for you to build, program, and improve upon:
- Hardware designed and assembled
- Firmware for uC and CPLD written and working
- User space drivers working (in Arduino and on Linux)
- Framebuffer drivers working on Raspberry Pi 2 Model B
For the impatient, you can skip ahead to:
- Download all of my code, firmware and hardware collateral
- Read a detailed log of my decision making process and engineering decisions for the 2014 Hackaday Prize
- Follow the project detailed logs for the second version for the 2015 Hackaday Prize
*(please ignore the 10 month gap in updates - it took some time for the motivation to come back!)
Technical Details for the CPLD Graphics Card
This version of the project has the following technical specifications:
- 640x480 @ 60Hz Standard Mode VGA
- 8 bit color (RGB332 or 8 Shades of Red, 8 Shades of Green, 4 Shades of Blue, 256 colors total)
- Plugs into SPI (Serial Peripheral Interface)
- 5V, 3.3V or 2.5V input
- Up to 59.5 MHz SPI support (suggested, but read the note below)
As for how that breaks down in performance (Worst case assumption: the entire screen needs a refresh every time, which is highly unlikely):
- 25 Frames Per Second minimum over SPI at 62.5 MHz worst case.
In the RPi2 driver, I have set the FPS at 25 and the SPI speed at 62.5 MHz and it luckily doesn't overwhelm any of the hardware. Also, 25 FPS may seem low, but it's perfectly acceptable even for some games... which you can see below in the video.
You probably shouldn't enter any tournaments, though.
What Can Drive This CPLD Video Card?
Technically, anything with SPI output (or even GPIOs you will program - see my note on the Intel Edison below).
The initial release includes code for the Raspberry Pi 2 Model B with the Broadcom BCM2836 SoC. I don't have an original Raspberry Pi with a BCM2835 SoC, but I imagine they are substantially similar and could be made to work (and in fact might work already - hopefully someone will let me know or send me one to test?).
Want a more substantive demo? Here it is running Doom on the Pi 2:
This first release will be for the Raspberry Pi 2 Model B only.
(Editor: Since publishing this article, I successfully got the FPGA graphics card working with the Intel Edison, saturating the 25 MHz SPI link. Here's the writeup on Hackaday.io: https://hackaday.io/project/7025-a-vga-display-for-the-intel-edison . As far as I know, I was the first to build a standard graphics interface on the Edison.)
I also have a driver for the Odroid C1.
Feel free to write drivers yourself for other boards; the protocol is detailed in the links and it will usually take around 30 lines of code.
If you have perfect soldering skills, you can probably make one for about $24 (less if you have more parts lying around).
- Acquire PCBs and assemble hardware (Link to schematic, gerbers, BOM, etc)
- Flash the CPLD with the video driver code
- Flash the microcontroller with the code to reprogram the clock module
- Follow the instructions on Github to build the kernel module
- Load the modules
- Do whatever you would normally do with a framebuffer. Notro has some good ideas here.
A note on the CPLD/FPGA Graphics Card dichotomy
VGATonic is a CPLD Graphics card, mainly because of the challenge I wanted in fitting all of the logic into a constrained part.
An FPGA Graphics card would have many more resources and on-chip resources like PLLs, so you should be able to take this project much further!
Other Engineering Projects
Feel free to subscribe, but DQYDJ is mostly a finance site. I have a bunch of projects I've completed, however, and some of them did end up online. Here are some notable ones:
- 640x480x8 colors from an Arduino - A hack (and bragging rights, or something like them)
- How to Double Clock Frequency with Digital Logic (and How to Divide) - Documenting the hack. Don't do it at work; use a PLL.
- Real time Christmas Light FFT Controller on an Arduino - because real time processing is possible if you do the calculations up front!
Software, on the other hand, is all over this site. Try our calculators and visualizations page for more.
- Hackaday Prize 2014 (for motivating my initial project)
- Hackaday Prize 2015 (for motivating the continuation)
- Matt Porter, Neil Greatorex, Kamal Mostafa, and notro for all of their amazing work on SPI framebuffers and deferred IO. I was able to build upon:
And thank yous to some of the prior art and instruction:
- 320x240 x 64 colors VGA on a CPLD, by Ulrich Radig
- 320x240 x 16 colors Composite on a CPLD, by 'elm'
- 640x360 x 65,536 colors Custom LCD on an FPGA, by Andy Brown
- All of Hamster's VHDL tutorials
Let us know if you build a CPLD... or an FPGA graphics card.