Showing posts with label Fritzing. Show all posts
Showing posts with label Fritzing. Show all posts

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:
  • 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.
It's probably easier to put everything in an interrupt handler and leave the main loop empty. All we need to do is set a timer. Factory default for an ATtiny13 is 9.6MHz (depends a lot on ambient temperature and supply voltage), If we set the timer prescaler to 64 we'll have the timer running at 150,000Hz. If we then set the timer to generate an interrupt every 250 timer ticks we get an interrupt frequency of 600Hz. If we execute our code every 75th interrupt we'll get exactly 8Hz, perfect!
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.

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.