Sven Krasser’s Blog

Musings on technology, security, and sundries.

VGA From Scratch (Part 2)

After creating a basic VGA signal using discrete CMOS logic chips in Part 1, my goal was to get something more interesting onto the screen. Long story short, after adding thirty-something additional ICs, this is the outcome:

So how does it work? The circuitry is divided into three stages. The first stage is the VGA signal generator that also generates an x coordinate, a y coordinate, and a signal indicating whether we’re in the visible area. Since there’s animation and hence a time dependency, there’s also a frame counter now (i.e. a t coordinate). The second stage computes the basic geometry, mainly by using adders to combine x, y, and t to achieve animation and the slanted blocks. Finally, the third stage combines everything into output colors. Colors are 5 bit red, 5 bit green, and 2 bit blue for a theoretical maximum of 4096 colors, implemented again as R-2R ladders like in the Arduino raster bars project.

Between each stage are flip-flops holding the relevant signals. With the 16 MHz pixel clock the VGA generator uses, that means there are about 60 ns the logic in each stage can take. Especially the adders take a bit of time, so I deviated from the 74HC series chips the VGA signal generator is based on and use the faster 74AC variants in a few spots. There’s still a bit of jitter left on the green channel (but I leave cleaning that up for another day). All parts combined make for a decently sized breadboard.

To plan what graphics to create, I first wrote a small simulator (available on GitHub). The simulator loops over all pixels and computes their colors using simple computations that can easily be implemented using logic ICs. That makes it quite a bit easier to try things out. It also allows taking a (digital) screenshot of the final result as opposed to taking an actual photo or video of the screen and dealing with the associated deteriorated quality.

This has been a fun project, and I’m happy to report that my monitor survived it. Although I have to say that I wished they made breadboards with version control and an undo button…

Other VGA posts:

Update: read about it on the Hackaday blog.