Using CPLDs and FPGAs in hobby electronics

ian – Sun, 2006 – 07 – 09 06:38

Maybe I've just been asleep, but the price and difficulty of using CPLDs and FPGAs in hobby electronics projects has gone through the floor in recent months.

CPLDs and FPGAs are types of PLDs - programmable logic devices. They let you implement digital logic without the expense of fabricating a new IC. As a simple example, you could buy one FPGA device and program it to act like a large collection of AND gates. Then you could reprogram it to act like a CPU, or a JPEG encoder. One physical device can implement the functionality of any device.

This is similar to what a microcontroller does; indeed, for many projects, microcontrollers are preferable because they're easier to use. As soon as you need high performance, specialist hardware or flexible I/O, CPLDs and FPGAs are superior.

(Full disclosure: my employer has a close relationship with Xilinx. This doesn't lead to bias because I want to support them; it just means that I know more about Xilinx stuff than I do about other manufacturers.)

As an example, my recent H-bridge controller was implemented on a PIC microcontroller. This worked well enough, but performance was suboptimal, and some nasty hacks were required because the I/O lines couldn't do exactly what I wanted. With a CPLD, I have dedicated hardware to implement things like the PWM controller, H-bridge logic and I2C interface; these subsystems would have operating frequencies in the hundreds of megahertz, instead of kilohertz.

A few years back, there were crippling problems that prevented hobbyists from making use of CPLDs and FPGAs. Just about all of these have been remedied.

Cost, capacity and performance

Two years ago, I studied the price/performance ratios of FPGAs for encryption applications. Back then, you were looking at several hundred dollars for each device. Now, the clock rates have quadrupled, the capacities have increased by a factor of twenty, and the devices cost a small fraction of what they did before. And that's just two years! CPU performance has barely even moved in that period; the 3GHz Pentium IV was released well before, that, and things haven't improved a great deal in the meantime.

(Anyone who mentions Moore's Law around me will likely be shot. No-one who cites it understands what it means or how it relates to reality.)

Excited rambling aside, FPGA tech is moving really, really fast. The FPGA manufacturers (generally Xilinx and Altera) have the goal to make the devices cheap enough that people will buy them instead of manufacturing their own ASIC, and damn it, it's working. Xilinx Spartan 3 devices can be had for less than $10, and they're large enough to implement custom microcontrollers in.

CPLDs are probably more useful to the hobbyist, and they're similarly cheap. You pay more money for more capacity, where the capacity of the device dictates how much logic you can fit in there.

Obtaining devices

Because PLDs were previously expensive, and slow, and couldn't actually do much, there wasn't much demand for them. Hence, they weren't stocked in many places.

Now, they're appearing in more and more distributor's catalogues. You still can't (easily) get them in Australia, but I dream of the day!

PCB manufacturing

All modern CPLDs and FPGAs are surface mount. This has been a problem for hobbyists in the past; it meant you had to manufacture a high-quality PCB using photographic techniques, which was expensive and difficult if you didn't do it often. To date, I've made one photo PCB; it came out beautifully, but was a lot of effort and expense.

Nowadays, there are plenty of good options. Mail-order PCB manufacturing is cheap and relatively fast (unless you're in Australia, damnit!). The quality is excellent. Making your own PCB with the toner transfer method is fast, easy and cheap.

Performing SMT soldering is easier than ever. The traditionalist (masochist?) can buy quality soldering irons and fine tips very cheaply; you can make solder masks by hand; you can use the drag soldering method, or the toaster oven method. Once you're proficient at SMT soldering, drilling holes in PCBs seems to be a major hassle...

Design software

Most manufacturers give away their design software for free now, and it's extremely high quality compared with a few years ago.

The design software is how you write a 'program' for the CPLD or FPGA. Most programming languages concentrate on moving data around and controlling program flow; assign this literal to a variable, do an operation on it, call this function, get the value back. Languages for PLDs are more concerned with performing logic operations on signals. They're also fully concurrent - each signal within a device can be manipulated simultaneously - so the program structure reflects the inherent parallelism. Most people use VHDL or Verilog to program their PLDs.

Compiling a design (or program) for an PLD is more involved than for a typical CPU, because you have to worry about timing. Instead of moving abstract values between functions, you're now moving very physical electrical signals between pieces of hardware. A function on a CPU may define the data types of inputs and outputs. A PLD also has to worry about when the data will arrive, how long it has to perform its operations, when it should send the output, and what the output means (just what does it mean to set a bit high?)

The compilation process is computationally intensive, but modern desktops are generally fine with it. Formerly, you'd have a shared 'compile box' that had as much as much CPU and RAM as you could find.

Programming equipment

JTAG is the usual interface used to program a PLD (although many other options exist). You need a JTAG cable to link the FPGA and your computer. Usually, these would come as part of a development kit, with the associated 'development kit tax' which made it infeasibly expensive for hobbyists.

Now, more options are available; many devices can use SPI or I2C for programming, and free interfaces are available for that. If you want to stick with JTAG, you can build an 'official' Xilinx design, or a cheap and nasty cable. You use your free design software to program the devices over JTAG.

Conclusion

Electronics hobbyists are now able to take advantage of CPLD and FPGA technology. The cost and difficulty of using PLDs has decreased immensely.

Expect to see more PLD articles on here soon!


Nope. Farnell have a little

Nope. Farnell have a little bit, but they're not the latest and greatest and they're very expensive.

I've done well with Digi-Key. You have to pay for overseas shipping, but it usually works out a lot cheaper than buying the parts locally from Farnell or RS. Shipping has been very quick so far - only about three days.

Futurlec and Oatley sometimes get interesting FPGA parts in.

There's always eBay!

ian – Fri, 2007 – 07 – 06 02:43

Have you found a

Have you found a reliable/cheap supplier of Xilinx parts in Australia?

I'm looking for XC9536XL-10VQ44, can only find it in the 64-pin package from the usual suspect (Farnell)

Any advice on where to buy from, even overseas, would be appreciated!

Tom (not verified) – Fri, 2007 – 07 – 06 01:49

Post new comment

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
More information about formatting options