Before we get stuck in to the build, we need to take a look at resistor values. An LED will suck as much current from the CPLD chip as it can but what if your CPLD can only supply so much? The most likely result will be a dead pin on the chip. We don’t want that. To get round this, we will use a current limiting resistor between the CPLD chip and the LED itself. Now, you could go gung-ho and just keep trying resistors until something either works or goes pop but again, we don’t want to do that….
This was actually my biggest stumbling block when I started with my CPLD board. I had no idea how to get started and nearly gave up with it altogether. Eventually, I struck up a conversation with Mike Burr who guided me through the thought process involved and didn’t simply give me the values I needed. This was more than helpful because it made me understand why I needed the values and not just that I needed them…so thanks Mike, this guide is dedicated to you!
The first thing you’ll need to do is find the datasheet for your particular CPLD chip. In our case, it’s an Altera EPM240 chip so we will need this info. It’s a huge amount of information so I’ll give you the important stuff here. The chip outputs 3.3v and can supply an absolute maximum current of 25mA per pin. It does state, however, that pulling the max current isn’t a good idea so we’ll aim for 20mA or less. It is slightly more complicated than that when running more LEDs because we have to think about the max current draw for the entire chip but we’ll cover than in a later article.
To work out which resistor to use, we need to employ the help of Ohm’s law. You can either use the diagram provided and do some maths or you can cheat entirely and use an Ohm’s law calculator like this one. I like to cheat.
First of all, we look at the voltage (3.3v) and then decide what current we’d like to draw (20mA). Put these values into the calculator and we get a result of 165 ohms. The closest I have to that is a 220 ohm resistor. It’s fine to go for a higher value but not a lower one. If we re-calculate Ohm’s law with 3.3v and 220 Ohms, we get a current draw of 15mA which is plenty enough to light an LED and also draws less current from the CPLD chip. Win!
Now we’ve found our resistor value, we can start building the circuit. First of all, connect the ground pin of your CPLD to your breadboard. I’ve opted to use the ground rail on the breadboard but don’t worry if your breadboard doesn’t have one, just connect it to any row. Next you’ll want to connect the cathode (shorter leg or flat edge) of your LED to the same ground line. Obviously the anode leg will need to go into a different row. You then need to add one end of your 220 ohm resistor to the same row and the LED anode and the other end to yet another row. finally, add a jumper wire from the spare resistor leg to pin1 of your CLPD (remember we chose pin1 in our previous article).
You should end up with something similar to this.
Because we programmed the CPLD chip in the last part, the only thing to do now is give your CPLD board some power and watch that LED light up!
That’s it, you’ve gone from knowing nothing to installing the development software, building a project using schematic entry, programming your chip, building your circuit and seeing the fruits of your labour in that little glowing LED.
Give yourself a pat on the back!!
Stay tuned for part 4 where I we will discuss adding some extra features to the circuit. As nice as a glowing LED is, it soon gets boring.