Received a bunch of spacers today (HTS-310) and they fit the cathode boards perfectly.
The whole construction feels pretty solid, very little flex. That's a good thing, since putting in the cables requires quite a bit of force. Speaking of cables, that's one more extra time consuming job...
Not much time spent on the cube lately. I'll probably be able to find a couple of free hours this weekend (yay for second Easter day). I did spend some time on some other stuf.
Showing posts with label design. Show all posts
Showing posts with label design. Show all posts
Thursday, April 17, 2014
Tuesday, March 04, 2014
Theory
In this post I want to take some time to explain the schematics. I want this to be as accessible as possible, so we'll start at the very beginning.
To accomplish this we put a resistor in series with the LED. To get the right resistor value you need a couple of parameters: the forward voltage of the LED (VF), the input voltage (VI), and the forward current (IF). The forward voltage of an LED depends on its color. Red usually means 2.4V, Green and Blue 3.4V. The input voltage of my cube is 5V. The forward current of an LED is typically 20mA (0.02A). Check your datasheets for your specific LEDs to verify this.
Now we need our input voltage VI to drop to VF, so that's VI - VF Volts. Then we simply apply Ohm's law (I = U/R, or R = U/I) and we get R = (VI - VF) / IF. So for a red LED that's (5 - 2.4) / 0.02 = 130 Ohm. For green and blue it's (5 - 3.4) / 0.02 = 80 Ohm.
Let's wire up a red LED to 5V. 130 Ohm resistors aren't that common, so we'll use the next best thing: 150 Ohm. Remember, LEDs are Light Emitting Diodes, so they'll only let current flow from one lead to the other, specifically from the anode (long lead) to the cathode (short lead, and the side where there's a flat spot).
That was simple enough, now let's try something more interesting.
Does it matter which one you use? Not really, as long as you know what type you're using/ordering. This also has consequences for where you place the series resistor. You shouldn't connect your resistor to the common lead of your LED, unless you have a bi-color LED where both LEDs have the same forward voltage, or you're using the highest resistor value.
For the rest of this post we'll be using common anode LEDs, since that's what I'm going to put in my cube.
Connecting it is easy, just hook 5V to the common anode, a few resistors to each cathode and the other end of the resistor to ground.
While this works fine for one RGB LED, and even for two or three, any more will start to become a problem. Remember how an LED has a forward current of 020mA? If you turn all three colors of an RGB LED on that becomes 60mA. If you connect 4 RGB LEDs and turn them all on you'll be putting 240mA through the microcontroller. Now google the datasheet for the Atmega328 and have a look at chapter 29. Electrical Characteristics, section 1 Absolute Maximum Ratings. It says: DC Current Vcc and GND pins: 200mA. Whoops, we possibly just killed our Arduino. Also note how the DC Current per I/O pin is just 40mA, so don't even think about connecting more than one LED to a pin.
So we'll need to come up with some way to reduce the amount of current going through our microcontroller. Fortunately, there's this thing called a transistor. With just a tiny amount of current you can control a much larger amount of current. A transistor has three leads: Base, Collector and Emitter. The base lead is used to control the amount of current flowing between the collector and emitter. There are two types of transistors: NPN and PNP. In an NPN transistor, a small current entering the base is amplified to produce a large collector and emitter current. (http://en.wikipedia.org/wiki/Bipolar_junction_transistor#NPN)
A PNP transistor works the other way around. When you pull the base low (connect to ground) a larger current will flow from the emitter to the collector (notice how the flow of current between the emitter and collector is reversed compared to a NPN transistor).
We'll be using a NPN transistor. We need a transistor that has a maximum collector current of at least 20mA. Then there's this thing called the gain. This figure indicates how much more current there is going to flow through the collector and emitter, compared to how much flows through the base and emitter. Basically it's your amplification. We need at least 20mA, but we don't want to use that much to control it. So let's use a gain of 10, this way we only need 2mA to control 20mA.
If you have a look at the datasheet of the 2N3904 you can find the following figures:
Collector Current : 200mA
DC current gain (at 1mA IC (input current)) : 70
That's well within specs.
The required base current will be 20mA / 70 = 0.3mA. Now we need to find a resistor to give us at least 0.3mA. First we have another look at the datasheet, we need to find the base-emitter saturation voltage, which happens to be between 0.65 and 0.85V, so 0.75 average. Enter Ohm's law again. (5V - 0.75V) / 0.0003A = 14166 Ohm. So a 10K resistor will do the trick, this will give us (5V - 0.75V) / 10000 = 0.4mA. A lower resistor like 1K will work as well, but it'll increase the power consumption, add extra heat, shorten the life of our components, etc. Don't even think about directly connecting your I/O pin to the transistor base lead since you'll effectively be shorting it to ground and kill your micro controller. If you want to read a bit more, click here.
That's it for now, next time I'll explain the anode driver and shift registers :)
Connecting an LED
LEDs arent' like ordinary light bulbs. You cannot (read: should not) connect an LED directly to a battery. The reason for this is that an LED has a very low internal resistance, so you'll effectively be shorting the battery. Sure, it will work if the voltage is right, but you risk damaging the LED. They're also picky about the voltage, so you'll want to provide an LED with just the right voltage.To accomplish this we put a resistor in series with the LED. To get the right resistor value you need a couple of parameters: the forward voltage of the LED (VF), the input voltage (VI), and the forward current (IF). The forward voltage of an LED depends on its color. Red usually means 2.4V, Green and Blue 3.4V. The input voltage of my cube is 5V. The forward current of an LED is typically 20mA (0.02A). Check your datasheets for your specific LEDs to verify this.
Now we need our input voltage VI to drop to VF, so that's VI - VF Volts. Then we simply apply Ohm's law (I = U/R, or R = U/I) and we get R = (VI - VF) / IF. So for a red LED that's (5 - 2.4) / 0.02 = 130 Ohm. For green and blue it's (5 - 3.4) / 0.02 = 80 Ohm.
Let's wire up a red LED to 5V. 130 Ohm resistors aren't that common, so we'll use the next best thing: 150 Ohm. Remember, LEDs are Light Emitting Diodes, so they'll only let current flow from one lead to the other, specifically from the anode (long lead) to the cathode (short lead, and the side where there's a flat spot).
Connecting an RGB LED
Multicolor LEDs come in two configurations: common Anode and common Cathode. They are basically multiple LEDs in one package with either the anode or cathode lead shared between all LEDs.Does it matter which one you use? Not really, as long as you know what type you're using/ordering. This also has consequences for where you place the series resistor. You shouldn't connect your resistor to the common lead of your LED, unless you have a bi-color LED where both LEDs have the same forward voltage, or you're using the highest resistor value.
For the rest of this post we'll be using common anode LEDs, since that's what I'm going to put in my cube.
Connecting it is easy, just hook 5V to the common anode, a few resistors to each cathode and the other end of the resistor to ground.
Controlling an RGB LED
So we've got our RGB LED burning, but now we want to control it. We want to be able to turn each color on and off. So we grab our Arduino (or other microcontroller) and hook our LED up. Instead of connecting the resistors to ground, we connect each resistor to a I/O pin of the microcontroller. With an AVR, like the Atmega328 that's on an Arduino Uno/Nano, we can set the pin to OUTPUT mode (low impedance), and by writing a digital LOW we connect the pin to ground (it sinks current), and the LED will turn on. By writing a digital HIGH we connect the pin to 5V (it sources current) and the LED will turn off (since both the anode and cathode are connected to 5V, no current will flow).While this works fine for one RGB LED, and even for two or three, any more will start to become a problem. Remember how an LED has a forward current of 020mA? If you turn all three colors of an RGB LED on that becomes 60mA. If you connect 4 RGB LEDs and turn them all on you'll be putting 240mA through the microcontroller. Now google the datasheet for the Atmega328 and have a look at chapter 29. Electrical Characteristics, section 1 Absolute Maximum Ratings. It says: DC Current Vcc and GND pins: 200mA. Whoops, we possibly just killed our Arduino. Also note how the DC Current per I/O pin is just 40mA, so don't even think about connecting more than one LED to a pin.
So we'll need to come up with some way to reduce the amount of current going through our microcontroller. Fortunately, there's this thing called a transistor. With just a tiny amount of current you can control a much larger amount of current. A transistor has three leads: Base, Collector and Emitter. The base lead is used to control the amount of current flowing between the collector and emitter. There are two types of transistors: NPN and PNP. In an NPN transistor, a small current entering the base is amplified to produce a large collector and emitter current. (http://en.wikipedia.org/wiki/Bipolar_junction_transistor#NPN)
A PNP transistor works the other way around. When you pull the base low (connect to ground) a larger current will flow from the emitter to the collector (notice how the flow of current between the emitter and collector is reversed compared to a NPN transistor).
We'll be using a NPN transistor. We need a transistor that has a maximum collector current of at least 20mA. Then there's this thing called the gain. This figure indicates how much more current there is going to flow through the collector and emitter, compared to how much flows through the base and emitter. Basically it's your amplification. We need at least 20mA, but we don't want to use that much to control it. So let's use a gain of 10, this way we only need 2mA to control 20mA.
If you have a look at the datasheet of the 2N3904 you can find the following figures:
Collector Current : 200mA
DC current gain (at 1mA IC (input current)) : 70
That's well within specs.
The required base current will be 20mA / 70 = 0.3mA. Now we need to find a resistor to give us at least 0.3mA. First we have another look at the datasheet, we need to find the base-emitter saturation voltage, which happens to be between 0.65 and 0.85V, so 0.75 average. Enter Ohm's law again. (5V - 0.75V) / 0.0003A = 14166 Ohm. So a 10K resistor will do the trick, this will give us (5V - 0.75V) / 10000 = 0.4mA. A lower resistor like 1K will work as well, but it'll increase the power consumption, add extra heat, shorten the life of our components, etc. Don't even think about directly connecting your I/O pin to the transistor base lead since you'll effectively be shorting it to ground and kill your micro controller. If you want to read a bit more, click here.
That's it for now, next time I'll explain the anode driver and shift registers :)
Monday, March 03, 2014
Pillar testing jig
After soldering a pillar of LEDs you'll want to test it to make sure you didn't make any mistakes. It's much easier to fix mistakes at this point than fixing them when the cube's fully assembled. So here's a little setup I came up with to make testing easier:
It's an ATtiny13 connected to an 74HC595 shift register. The outputs of the shift register are connected to the anodes of the pillar. The cathodes of the pillar are connected to pins PB0-2 of the ATtiny and have a few series resistors. By configuring the pins as output pins we can sink some current when we write them low, turning the LEDs on. When we write a high to the pins we source current and the LEDs go off. So with the shift register we can control which LED should be on, and with the input pins we can select the color.
Normally you'd use some transistors instead of connecting the LEDs to the pins/register directly because the ATtiny nor the shift register will be able to handle the current of all LEDs going on simultaneously (3 x 8 x 20mA = 480 mA), but we'll program the ATtiny to only turn on one LED at a time so we can get away with this setup.
Both the storage and shift clock of the shift register are connected to PB4, this causes data that is shifted into the register to appear almost directly on the output pin, which is fine for this setup. The output enable is connected to ground so we'll have continuous output. The reset pins of both ICs are connected to +5V through a 10K pull-up resistor. The DS pin of the 595 is connected to PB3, the Q7S pin is left floating since we're not using it, which seems to be common practice. There's a 100nF ceramic cap added as a bypass for the ICs, and a power connector of course.
And for kicks, here's a dirty PCB:
For my test jig I'm not going to put those LEDs on the board, instead I'll have a three terminal connector near the resistors to connect the cathode wires of the pillar to. And an eight terminal connector for the anodes.
As you can see, I used Fritzing for this quick prototype. It just works a bit faster and the breadboard view is handy for this situation. If you want to download the Fritzing project, click here.
As for the programming: that's easy:
One thing I can't remember correctly is whether or not the system clock prescaler is active by default. If so then it's set to 8, reducing the system clock to 1.2MHz. We can tackle this by changing the timer prescaler to 8, so we'll still have our 150,000Hz timer clock. Easy!
Here's a video of the setup without using the cathode shifting.
And here is the setup on a protoboard, connected to the pillar. Still no cathode shifting and driven by an Arduino; I've stuck some jumper wires into the DIP socket for the ATtiny to connect the Arduino.
I'm not too happy with the custom cable I made. It's a bit too much work to stick those connectors in and I risk bending the anode legs. I think I'll create a wooden jig with some contacts, to place the pillar in.
It's an ATtiny13 connected to an 74HC595 shift register. The outputs of the shift register are connected to the anodes of the pillar. The cathodes of the pillar are connected to pins PB0-2 of the ATtiny and have a few series resistors. By configuring the pins as output pins we can sink some current when we write them low, turning the LEDs on. When we write a high to the pins we source current and the LEDs go off. So with the shift register we can control which LED should be on, and with the input pins we can select the color.
Normally you'd use some transistors instead of connecting the LEDs to the pins/register directly because the ATtiny nor the shift register will be able to handle the current of all LEDs going on simultaneously (3 x 8 x 20mA = 480 mA), but we'll program the ATtiny to only turn on one LED at a time so we can get away with this setup.
Both the storage and shift clock of the shift register are connected to PB4, this causes data that is shifted into the register to appear almost directly on the output pin, which is fine for this setup. The output enable is connected to ground so we'll have continuous output. The reset pins of both ICs are connected to +5V through a 10K pull-up resistor. The DS pin of the 595 is connected to PB3, the Q7S pin is left floating since we're not using it, which seems to be common practice. There's a 100nF ceramic cap added as a bypass for the ICs, and a power connector of course.
And for kicks, here's a dirty PCB:
For my test jig I'm not going to put those LEDs on the board, instead I'll have a three terminal connector near the resistors to connect the cathode wires of the pillar to. And an eight terminal connector for the anodes.
As you can see, I used Fritzing for this quick prototype. It just works a bit faster and the breadboard view is handy for this situation. If you want to download the Fritzing project, click here.
As for the programming: that's easy:
- Setup
- DDRB should be set as input for PB5 (reset) and output for PB0-4
- PORTB should be set high for PB0, PB1 and PB2 so they don't sink any current.
- define an eight bit anode counter variable, initialize it with 1.
- define a cathode counter variable, initialize it with 1.
- Main loop
- Start setting PORTB to 7, so we set PB0-2 high
- Shift the anode counter variable out on PB3 while toggling PB4.
- Set PB3 low and toggle PB4 twice to shift out a zero, because the 595's output is lagging behind one cycle.
- Shift the anode counter variable left by one.
- Toggle one of the output pins by writing the cathode counter variable to PINB.
- Shift the anode counter variable left one position.
- If the result is zero, set it to one. Shift the cathode counter variable left one position as well.
- If the result is eight, set it to one.
- Add a delay for 1/8th of a second.
One thing I can't remember correctly is whether or not the system clock prescaler is active by default. If so then it's set to 8, reducing the system clock to 1.2MHz. We can tackle this by changing the timer prescaler to 8, so we'll still have our 150,000Hz timer clock. Easy!
I'm not too happy with the custom cable I made. It's a bit too much work to stick those connectors in and I risk bending the anode legs. I think I'll create a wooden jig with some contacts, to place the pillar in.
Saturday, March 01, 2014
Some PCB tweaking
Digging through some datasheets I discovered that I had the MR pin (Master Reset) of the 74HC595 shift registers tied to 5V, so I wouldn't be able to reset it from a microcontroller. I fixed it by widening the data connector to 5 pins and connecting the extra column to MR. I also realized the footprint on the design doesn't match the package of the chips I've ordered; the footprint should've been slightly narrower.
On the cathode board there was no room for the extra pins, so I had to move the power indicator LED to the other side of the board, It's now located near the power connector. I've also added a bunch vias in various places that are connected to GND. This helps the ground fill occupy a larger part of the board. I've also rerouted a couple of traces to make things prettier :)
On the anode board there was a bit more room for the extra pin, but connecting the extra pin took a bit more work. On the anode board the pins are pretty much right next to the pins on the IC. On the cathode board the traces have to cross each other.
One of my colleagues noticed the 100 Ohm resistor between the MOSFETs drain and GND. Ohm's law tells us that a 100 Ohm resistor at 5 Volts will have 0.05 Ampères running through it (I = U/R). It also tells us that there will be 0.25 Watt to handle (P = U^2/R). That doesn't sound like much, but an ordinary 0603 sized resistor is only rated at 1/8th or 1/10th Watt. I don't want to add through hole resistors, so I ordered a bunch of 2512 sized resistors, they're rated at 1 Watt (and easier to find than 1210s). There's plenty of space on the board for the increased footprint, so no problem there. I may be moving the caps to the other side of the board so the MOSFETs have more room for heat dissipation (and electrolytic caps don't like heat much).
Thursday, February 27, 2014
Designing some PCBs
Having decided that I didn't want a big mess of wires and several square feet of prototype boards, I set out to design a PCB to accommodate all the circuitry. Initial drafts were made using Fritzing, a very accessible open source program.
I wanted to have one shift register with eight transistors and all required resistors on one small board, so I could control 8 cathodes. The design had to be small and stackable; you should be able to put multiple boards on top of each other easily.
Designing a PCB is surprisingly easy. All you need to do is create the schematic in the schematic view by placing all components and drawing wires between the connectors.

Then you go to the PCB view and set all the right footprints for the components (components may come in various forms, like through hole or surface mount, check the datasheets of your components). After that it's simply a matter of placing the components on the PCB in a logical way. The software will draw lines between pads that need to be connected to each other (so called rats nests) and all you need to do is draw traces between unconnected pads, making sure they don't cross and aren't too close to each other. The software will check for the most obvious design faults.
The above pcb is about 5 by 2 cm (2 by 0.8 inch) and can control the cathodes of 8 LEDs. Check out the result in 3D (made with KiCad):
The row of 8 pins are connected to the cathodes of the LEDs. The double pin header next to the shift register are the data pins which are connected to the microcontroller. The pins of the bottom row are connected to the pins above them, except for the last one in each row. The bottom one is data in, the top one is data out. When you stack these boards, you can connect the top 4 pins (output) to the bottom 4 pins (input) of the board above it. The data out of the bottom board will be connected to data in of the board above it. Pretty neat eh? The signal on the other pins of that connector are the same for all boards. They´re (in no particular order) Clock, Reset and Latch. The three pin connector (drawn in blue) is the power connector.
Although Fritzing is very easy to use, it has its limitations. Which is why I switched to KiCad, which is also open source and free, but it's much more professional. Id' say Fritzing is nice to learn the basics, but KiCad is great when you start to run into Fritzing's limitations. The learning curve for KiCad is much higher though, but there are some great tutorials that'll help you get started. Plus it has a 3D view :)
I've also designed an Anode driver board to hold a shift register and the MOSFETs, it can be connected the same way as the Cathode boards.
You've probably noticed the thick traces, those are needed to handle the 5 A current that will be flowing when the cube is fully lit. It's about 7 by 5 cm (3 by 2 inch).
The cool thing about these boards is that you can use them not just for a cube, but also for LED bars or LED matrices.
Above pictures are of older versions, the current design has some minor improvements.
I wanted to have one shift register with eight transistors and all required resistors on one small board, so I could control 8 cathodes. The design had to be small and stackable; you should be able to put multiple boards on top of each other easily.
Designing a PCB is surprisingly easy. All you need to do is create the schematic in the schematic view by placing all components and drawing wires between the connectors.

Then you go to the PCB view and set all the right footprints for the components (components may come in various forms, like through hole or surface mount, check the datasheets of your components). After that it's simply a matter of placing the components on the PCB in a logical way. The software will draw lines between pads that need to be connected to each other (so called rats nests) and all you need to do is draw traces between unconnected pads, making sure they don't cross and aren't too close to each other. The software will check for the most obvious design faults.
The above pcb is about 5 by 2 cm (2 by 0.8 inch) and can control the cathodes of 8 LEDs. Check out the result in 3D (made with KiCad):
The row of 8 pins are connected to the cathodes of the LEDs. The double pin header next to the shift register are the data pins which are connected to the microcontroller. The pins of the bottom row are connected to the pins above them, except for the last one in each row. The bottom one is data in, the top one is data out. When you stack these boards, you can connect the top 4 pins (output) to the bottom 4 pins (input) of the board above it. The data out of the bottom board will be connected to data in of the board above it. Pretty neat eh? The signal on the other pins of that connector are the same for all boards. They´re (in no particular order) Clock, Reset and Latch. The three pin connector (drawn in blue) is the power connector.
Although Fritzing is very easy to use, it has its limitations. Which is why I switched to KiCad, which is also open source and free, but it's much more professional. Id' say Fritzing is nice to learn the basics, but KiCad is great when you start to run into Fritzing's limitations. The learning curve for KiCad is much higher though, but there are some great tutorials that'll help you get started. Plus it has a 3D view :)
I've also designed an Anode driver board to hold a shift register and the MOSFETs, it can be connected the same way as the Cathode boards.
You've probably noticed the thick traces, those are needed to handle the 5 A current that will be flowing when the cube is fully lit. It's about 7 by 5 cm (3 by 2 inch).
The cool thing about these boards is that you can use them not just for a cube, but also for LED bars or LED matrices.
Above pictures are of older versions, the current design has some minor improvements.
Subscribe to:
Posts (Atom)














