Tuesday, March 27, 2012

CPLDs, and the importance of knowing when to quit.

As an engineer, I can have a natural tendency to become obsessed with problem solving. Every problem I come across is a personal test, "If this problem is solvable, I will be victorious, I will conquer it". I think the hard thing can be recognizing when the solution isn't worth the effort. The ability to spot this before others is what can make a great manager, that's not what this post is about, however.

Let me tell you a little story about CPLD's:

Now if you ask my wife, she'll tell you I'm the cheapest, stingiest man alive, if you ask my mother, well she'd probably agree, but if you asked me, I'd tell you I just take pride in being resourceful. I've always had a hard time paying someone to do something I could easily do myself.

One of the things that I really enjoy about  hobby electronics is the thrill of sourcing parts for a fraction of what the unwashed masses might pay. I built my own sd card-breadboard adapter for my .Net Micro Framework Project. It was really fun, cost me probably around three or four dollars, and was much less than the $20 similar boards went for at the time. (prices now seem to be about half what they were 2 years ago). One thing I've noticed is that I really tend to discount the cost of something in terms of my time. I might spend 3 evenings of free time to make something that saves me $10, and I've historically viewed that as a win. It's easy to write off such a time-sink with self excuses like: "it was fun", "I learned something", "I gained a skill" etc. The problem , I've come to realize is that those are attributes of anything I undertake in any hobby project. So the net win isn't really there.

On to my CPLD story... A couple of years ago, I really wanted to get into programmable logic devices - CPLDs, FPGAs, and VHDL. I noticed that Atmel makes an "ATF15XX" line of CPLDs that are essentially functional clones of Altera 3000/7000 series logic devices. The Atmel chips seemed to sell for significantly less than the equivalent Altera chips. I was already a fan of Atmel's ARM and AVR line of MCU's so I bit. I ordered an array ( :) ) of various sized chips, and started pouring over documentation.

Programmable logic chips seem to lag behind MCU's in the hobbyist-friendly area, there are no DIP form factor CPLDs or FPGAs, PLCC is the best you can do. While there are PLCC-breadboard adapters, they seemed priced a little high for me, at $15-$25, especially since the sockets themselves where under $1. I decided to build my own:

Rat's nest perf board solder job for an Alter/Atmel

As you can imagine, this was quite a lot of work.

One advantage CPLD's have over most (but not all) FPGA's is that they often contain their own non-volatile memory to hold programming. The flip side to this is that you need a way to program that memory, and the method is proprietary to each manufacturer. Atmel's CPLD's can indirectly use the programming files from Altera's Quartus software, after running some conversion tools. However Altera's software and Altera's "USB Blaster" (or my cheap knock off) will not program the file to the Atmel chip.
Atmel makes their own programming software, "Atmel ISP" that can use Atmel's own proprietary USB cables, but can also use an Altera "Byte Blaster" which is essentially an electrically buffered connection to a PC's LPT port. I picked up a Sparkfun Byte Blaster knockoff, but found it was extremely sensitive, I had to plug it directly into my ancient tower PC's printer port, and even then I only successfully programmed the chip  1/4 of the time. Frustrating! Oh, and "Atmel ISP" does *not* work with Altera's "USB Blaster" programming cable, only the much older LPT based one. Still with me? Good, that makes one of us.

In furtherance of my quest to conquer Logicland, I immersed myself deeper into irrationality. The Atmel USB programming cable sells for ~$42-$52 online, if you can find it in stock. Atmel's documentation is scant on the design, and I can find no examples on the Web where someone has hacked one of these apart, unlike the much-cloned USB Blaster. $42+ was just too much to me for a device that had such a limited utility. I ran across some really old software that Atmel has once published that used an AT90somethingorother MCU to program Atf15xx series CPLDs. This package (which has since disappeared from Atmel's website, you may be able to find it somewhere if you Google "EISP15XX.exe", sorry I can't post it) included MCU and PC side source for reading in a programming file and "bitbanging" the jtag lines to program the CPLD.

My next moment of brilliance was to decide that I would make my own programming software and hardware, why it could even be a stepping stone to my own custom JTAG hardware and software suite. It only took me a could evenings to have a GUI up, and to be able to read in the Atmel programming "jed" data/fuses into memory. I would then use libUsb and V-USB as I had done on another project to talk to an Atmega to do the heavy lifting on the chip side.

Then the project went cold. I don't remember why, I jump around a lot, and sometime I forget to jump back to something.

I'd been thinking about revisiting this project lately, and that's when the truth in the opening paragraph of this post hit me. It's not worth it. When I started to look into the hardware and code needed to make my programmer, I realized that this project, which I viewed as a prerequisite to other project ideas, is a battle that I should not fight. $42 is money well spent in this case. Making a limited use JTAG programmer would not have the return on investment to make it worthwhile. It's not about the money, its about the time.

So now I have two options. Since I last left off on this project, I learned that the venerable Bus Pirate has an XSVF player mode, I may be able to get the Atmel jed files into xsvf format. Of course, the down side to that approach is that I think it is unable to verify the bits, a big concern given my very high fail rate with the Byte Blaster. The other option is to finally pony up the $42 and buy the Atmel USB programmer cable, and move on to more exciting projects. I already broke down and bought a 84 pin PLCC bread board adapter for the larger CPLD's.

When it comes down to it, I also have a third option, one that I've already started down; to just buy some real Altera CPLD's. It's just that sometimes it's hard to admit you've fallen victim to the sunk-cost fallacy.

You win this time, Atmel.


PS. If anyone has pictures of this Atmel CPLD cable, I'd love to see it. It's part# ATDH1150USB.


  1. I should add that my board as pictured does not show some of the signal conditioning steps I took to try and improve the JTAG reliability. I also know that the fact that I used a lot of cloned tools and homebrew "dev boards" meant that what sparse documentation I could find about these chips wasn't always applicable to my circuit. So I did a lot of trial and error. The 25% success rate was my peak performance, it was often much worse than that.

  2. you nailed our marriage perfectly... pay the 42.00 and move on to a bigger project... like building that cleaning robot I wanted... love, your wife.

  3. Done. I'll make something bigger out of it. Maybe I'll post a tear-down. At the very least, I'm going to open it up and see what makes it tick. If it's easy to clone, maybe the next stingy nerd wont have to shell out for the real thing to play with CPLDs, so in a small way it will have made the world a better place.

  4. Hey, not so fast.... :) I'm stuck in a similar situation. Except this is work related. We "HAD" to convert some old Xilinx stuff because of End-of-life. The decision was to go with the Atmel ATF15xx series. Now, not only was it like pulling teeth to get software to synthesis for Atmel's CPLD, driving a hired temp to borderline insanity trying to convert Xilinx Foundation 3.0 board schematics to Verilog, but now I gotta figure out a way to put it all on the CPLD. I got the Altera USB Blaster because it was pin compatible to Atmel's Dev Board (which is out of production and had to bought on e-bay) for the ATF15xx.

    Now, I'm to understand that AtmelISP won't work? Please, tell me I'm crazy.
    I have the usual suspects installed, ProChip 5, Altera Quartus, and Icarus Verilog, on and WinCUPL. AND NOBODY around has a parallel port.

    What's a guy to do? Any help or suggestions would be appreciated.


I welcome you're thoughts. Keep it classy, think of the children.