Lately I’ve been refreshing my Verilog skills—Verilog is a hardware description language (or HDL), which means that the code you write can be synthesized into actual hardware (e.g. logic gates and flip flops). As luck would have it, I stumbled across a great book that allowed me to combine learning Verilog with one of my passions, vintage computer and video game hardware. The book is called Designing Video Game Hardware in Verilog, written by Steven Hugg. In addition to the book, the author created an awesome Verilog IDE (Integrated Development Environment) on the 8bitworkshop website, where you can explore sample code, as well as write your own code. Not only does this IDE include a waveform viewer so you can see the signals your code is driving, it also includes a virtual TV screen, allowing you to write code that creates digital RGB signals and to immediately see what the results would look like if you connected your hardware to an RGB TV or monitor.
As soon as I saw this book, I thought about making something that would drive my vintage Sony TV—I wrote about building an RGB cable for this TV in a previous post. One way to actually implement what you’ve written in Verilog is to synthesize your code and download it into a field-programmable gate array, or FPGA chip. The book suggests using an iCEstick evaluation board, which is based on a Lattice FPGA. One nice thing about this board is that it comes with an onboard USB interface, so it will plug directly into your computer for programming without any additional hardware. Another great thing about this board is that there is an open source toolchain (IceStorm) available to program the FPGA using Verilog, which means it’s totally free to use the tools!
The first thing to do was download the tools and make sure I could install and use them. Thankfully, there are scripts that will automatically complete the installation on OSX (using Homebrew), and I was able to get through this with only a few easily resolved hiccups. Next, I tried using the tools to go through the complete Verilog to FPGA flow. There are four tools needed to go from Verilog to a programmed FPGA:
- yosys takes your Verilog code and synthesizes it into an actual logic circuit
- arachne-pnr takes the circuit from yosys and, with knowledge of the specific FPGA you are using, does place and route (determining how to map the logic circuit to the resources available on the FPGA)
- icepack takes the output of arachne-pnr and converts it to a bitstream, which can be directly downloaded into the FPGA in order to configure it with your circuit
- iceprog uses the USB port to send the bitstream to the FPGA, programming it
For my first design, I decided to implement a simple SMPTE color bar pattern generator. This would allow me to see all 8 colors possible with 3-bit digital RGB, which is what the examples in the book use. Thanks to the 8bitworkshop IDE, I was immediately able to see the TV output of my code:
Whoops! I swapped the position of the red and blue bits, so the colors aren’t in the correct order. The beauty of using Verilog to define hardware is that a change is as simple as editing your code. A quick fix and everything was working correctly. I ran the IceStorm toolchain and everything seemed to go okay, so I was ready to order the iCEstick evaluation board. In my next post I’ll talk about my experience with using this board to try to get a picture on the TV!