Showing posts with label jig. Show all posts
Showing posts with label jig. Show all posts

Thursday, March 06, 2014

Debugging the pillar test jig

When the cause of a problem is not immediately often it is often good practice to first check for the most obvious mistakes, isolate a few small portions and check if they work and then work your way up, combining the parts you've checked. This approach works pretty well in debugging software and I use it a lot.

I should've used it here as well.

As I wrote in my previous post, only the bottom LED in my pillar would light up properly when I inserted it in the jig. What I also noticed is that this is also when I put the serial data line high (for the other 7 points in the cycle it's low). I also noticed that the serial data pin on the shift register is right next to output pin 0, to which the bottom LED is connected. It's obvious to expect a bad soldering job (if you're familiar with my soldering) so I wanted to rule that out first.
What I did was modify the code a bit, so will put the data line high after 4 cycles as well. This would give me 2 lit LEDs in the loop and would give me a chance to see if only the bottom LED would light up brightly or not. That wasn't the case; both LEDs would light up brightly whenever the serial data pin went high.
Next up was measuring voltages and current on the bright and dim LEDs, this confirmed that the dim LEDs got less volts across them than the bright ones, but it still didn't explain why.
I slowed down the code a bit (one update per two seconds) and started to notice something odd: the shift register would reset after a brightly lit LED would go off. Expecting something more fundamentally to be wrong I ripped all of the jumper wires out of the protoboard and pulled the shift register IC out of its socket. Then I started checking all connections on the protoboard.

I should've started with that really.

I forgot to connect the power supply of the shift register to the power supply of the ATtiny. There was a wire going there and it was soldered to the board, but on the bottom I never connected the wire to the VCC pin... Doh!
I also forgot to solder the pull up resistor on the reset line to 5V and the ceramic capacitor was floating as well. What a mess. I'm a bit puzzled as to why the LEDs would even light up in the first place, probably the shift register got some current through its input pins just enough to keep running. Anyway, I hooked everthing up and it works like a charm now!


Here's the Arduino code. Yes, it's messy and more complicated than it should be since I'm not using any Arduino functions. This way I can simply copy/paste it to AVR studio so it can run on the ATtiny (apart from the timer prescaler setting and counters).I'm using PORTB since that's what the ATtiny13 also has. Arduino pins 8-10 should connect to cathodes R, G and B.Pin 11 should connect to DS and pin 12 to SHCP and STCP.


1:  void setup()  
2:  {  
3:      PORTB = 7; // pull cathode pins high, no current will flow
4:      DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB3) | _BV(DDB4);  
5:      // initialize timer
6:      TCNT0 = 0;  
7:      TIMSK0 = (1 << OCIE0A); // interrupt on compare match  
8:      TCCR0A = _BV(WGM01);  
9:      TCCR0B = _BV(CS02); // F_CPU / 256
10:      OCR0A = 250;  
11:      asm("sei");  // enable interrupts
12:  }  
13:    
14:  uint8_t cathodeCounter = 4;  
15:  uint8_t anodeCounter = 0;  
16:    
17:  void loop()  
18:  {  
19:      // do nothing!  
20:      asm("sleep");  
21:  }  
22:    
23:  ISR(TIMER0_COMPA_vect, ISR_NAKED)  
24:  {  
25:      uint8_t sreg = SREG;  
26:      static uint8_t counter = 0;  
27:      ++counter;  
28:      if ( counter >= 20 )  
29:      {  
30:          counter = 0;  
31:          ++anodeCounter;  
32:          if ( anodeCounter == 8 )  
33:          {  
34:              PORTB |= _BV(3);  
35:              anodeCounter = 0;  
36:          }  
37:          else if ( anodeCounter == 1 )  
38:          {  
39:              PORTB |= cathodeCounter;  
40:              cathodeCounter <<= 1;  
41:              if ( cathodeCounter >= 8 )  
42:              {  
43:                  cathodeCounter = 1;  
44:              }  
45:              PORTB &= ~cathodeCounter;  
46:              PORTB &= ~_BV(3);  
47:          }  
48:          PORTB |= _BV(4);   
49:          PORTB &= ~_BV(4);  
50:      }  
51:      SREG = sreg;  
52:      asm("reti");  // return from interrupt
53:  }
Here is the board with the ATtiny installed. The jumper wires are there to supply power from USB. The second protoboard in the background is my home made programming socket for the ATtiny. It's just a DIP 8 socket with all pins available on female headers. There's a 10 pin male header connected to the necessary ISCP pins so I can just simply connect a flat cable to the USB programmer (shown on the left).
Now all that's left to do is fix the board to the jig and add a power connector, or maybe a 7805 voltage regulator so I can power it from a battery or other external source and make the whole thing more portable :)
As for the ATtiny code:
1:  /*  
2:   * TinyPillarTester.c  
3:   *  
4:   * Created: 6-3-2014 21:48:11  
5:   * Author: Daniel  
6:   */   
7:    
8:    
9:  #include <avr/io.h>  
10:  #include <avr/interrupt.h>  
11:    
12:  int main(void)  
13:  {  
14:      PORTB = 7;  
15:      DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB3) | _BV(DDB4);  
16:    
17:      TCNT0 = 0;  
18:      TIMSK0 = (1 << OCIE0A); // interrupt on compare match  
19:      TCCR0A = _BV(WGM01);  
20:      TCCR0B = _BV(CS01); // F_CPU / 8  
21:      OCR0A = 250;  
22:      asm("sei");  
23:    while(1)  
24:    {  
25:        // do nothing!  
26:        asm("sleep");  
27:    }  
28:  }  
29:    
30:  uint8_t cathodeCounter = 4;  
31:  uint8_t anodeCounter = 0;  
32:    
33:  ISR(TIM0_COMPA_vect, ISR_NAKED)  
34:  {  
35:      uint8_t sreg = SREG;  
36:      static uint8_t counter = 0;  
37:      ++counter;  
38:      if ( counter >= 75 )  
39:      {  
40:          counter = 0;  
41:          ++anodeCounter;  
42:          if ( anodeCounter == 8 )  
43:          {  
44:              PORTB |= _BV(3);  
45:              anodeCounter = 0;  
46:          }  
47:          else if ( anodeCounter == 1 )  
48:          {  
49:              PORTB |= cathodeCounter;  
50:              cathodeCounter <<= 1;  
51:              if ( cathodeCounter >= 8 )  
52:              {  
53:                  cathodeCounter = 1;  
54:              }  
55:              PORTB &= ~cathodeCounter;  
56:              PORTB &= ~_BV(3);  
57:          }  
58:          PORTB |= _BV(4);  
59:          PORTB &= ~_BV(4);  
60:      }  
61:      SREG = sreg;  
62:      asm("reti");  
63:  }  
64:    
Notice how similar it is to the Arduino code. The name of the interrupt handler is a bit different, and I've chosen different values for the timer prescaler and counter, and the setup and loop functions are combined in one main function. This code uses 208 bytes (20%) of ROM and 4 bytes (6%) of SRAM. Even the ATtiny13A is a bit overkill for something like this :)

Anyway, that's it for today, I'm always glad when something is working by the time I decide to call it a day :)

Sunday, March 02, 2014

Jig: Mk. 2

Sunday afternoon, a perfect moment to spend some time in the man cave :)

I decided to build another jig, since the first one is, well... crap. The main reason for that are my lack of skills. Fortunately there are plenty of tools to compensate for it, and my old man has a shed full of 'em :)

Starting with a nice jig to compensate for my horrible skills with a saw (it even says "no skills required" on the box, perfect!)
 Finally, 90 degree angles! I decided to make the columns in the jig 10mm deep, that will leave 15mm of space left for putting the LEDs in. I want the columns to be about 14mm wide, so there will be around 11mm of space between the LED pillars when they're installed. Unfortunately the wood is 22mm thick. Sawing that off would be a pain in the behind, so enter tool nr 2:
Yes, it's an electric planer. At the highest setting it turns 2mm of wood into a large pile of dust. So after using it four times I end up with a 14mm wood instead of 22, and a work bench covered in wood particles. Nice.
Back to the hand saw, 8 columns of 10mm done. Time to put some holes in them.
Since they're 14 mm wide, I've drawn a line 7mm from the top, and a vertical line right in the center. For the drilling, enter tool nr 3:
It's my trusty Dremel in the Dremel Workstation. Perfect for drilling some perfectly vertical holes.
Spot on, right through the center! That's just a 3mm drill, but the hole needs to be 5mm. I enlarged the holes using my cordless drill. The existing hole will guide the larger drill, so the hole remains in the center.
Then it's simply a matter of drawing a few lines on the base plate. The lines are spaced 25mm apart and there are two lines crossing them to mark the sides of the colums. Those are 14mm apart and 15mm from the edge.
Add glue, apply pressure. This is the fast drying type, takes about 15 minutes to cure. Tightening and loosening the clamps needs to be done carefully. Add the center clamp first, then the outer ones. Don't tighten them completely right away, but tighten each one a bit and move to the next. Removal is done in reverse order (center one last).

In the mean time, I created a small jig for bending the LED's legs.
Simply insert the LED, bend the legs, and press another piece of wood on top. Easy! The front and back plate are done as well:
The outer holes are 14mm apart, the center hole is 7mm above the outer holes.
After the glue has dried, it's time to drill a couple of holes from the bottom into the colums. Again, I used the Dremel for this to make sure the holes are perfectly vertical and spot on down the center of the colums.
Let's put in some screws. It's important to put a load of pressure on the columns so they won't start to rotate when you put the screws in. Clamping the whole thing down seems to work pretty well. The front and back plate had the same treatment.
And after about 3.5 hours it's done! Let's put in some LEDs!
 Nice! Works like a charm, now let's cut the three wires so we can pull the pillar out of the jig.
No problems there, plenty of room!
That's usable, may need a bit of bending, but not bad!
And it works!
Compared with the one from the first jig (at front). The space between the LEDs and the cathode wires has become a lot smaller (20mm to 14mm) and the distance between the LEDs has been reduced from 30mm to 25, awesome.

The next step is rigging up a framework to test a pillar. I'll probably just use one shift register to turn on each anode sequentially while sourcing one of the cathodes. After cycling through all anodes it'll move to the next cathode. So it'll first light up all reds, then all greens, then all blues and then all reds again, all in a matter of a few seconds.Guess I'll wire up an AtTiny on a protoboard to make it a semi permanent setup, I just need to get my hands on a dozen alligator clips :)

Thursday, February 27, 2014

Creating a jig


Probably the most important tool when constructing the cube is the jig. It hold the wires and LEDs in place when you solder them, making life a whole lot easier. This jig is used to create a pillar of LEDs; 8 LEDs stacked on top of each other with all their cathodes connected.
I've bought a piece of wood, about 44 mm wide and 20 mm thick, and cut it into pieces. I've cut off eight pieces of 20 mm to hold the LEDs, and two pieces of 80mm to go on each end. The bottom part is about 250 mm. In the 8 "columns" I've drilled 5mm holes, 1 cm from the top. The distance between the hole and the edges of the columns determines the distance of the wires to the LED.
I've drilled three 3 mm holes on both ends to hold the wires. The position of these holes should match the top and sides of the columns, so the wires will touch the columns.

This was just a prototype I made to figure out the what works and what doesn't. I recommend taking your time for designing and constructing the jig, as it will eventually determine the quality of your cube.

Plan your cube; think about how large you want it to be. I'm going for a 1 inch spacing between all LEDs. This means that the front of a jig column should be one inch away from the front of the next and previous  jig column. The width of the columns shouldn't exceed 20mm, this leaves just 5 mm of space between the pillars of LEDs. As you can see, the design of the jig determines the dimensions of the cube. And make SURE you keep plenty of room between the bottom LED and the end of the jig, you'll need this extra wire to install the pillar.

Things that went wrong:
  • I'm not that great with wood, I used a hand saw and a portable electric drill. The result is far from perfect. Next time I'll use an electric jig saw for cutting and my Dremel workstation to drill straight holes.
  • Use glue. The columns rotate a bit, so next time I'll glue them first, then drill holes from the bottom before screwing them in place. This should keep them perfectly in place.
  • Make the columns thinner. The space between the columns is a bit too small to comfortably put the LEDs in and out; they tend to get stuck.
  • Make the columns narrower. Right now I'm creating pillars that are 20 mm wide, I think I'm going with 12 or 15 mm instead, so I'll have more space between the pillars.
 Here's the result of my first test with the jig:
 Not too shabby. I had to put quite a bit of force on it to get it out of the jig so it's a bit bent. A few more lessons learned:
  • Make sure you have plenty of clearance between the columns, one of the LEDs got stuck.
  • Make sure you bend the legs of all LEDs equally, or they might push the wire away making it difficult to solder other LEDs. I'm probably going to create a jig for bending the legs as well.
  • Place the LEDs before you place the wires, it's much easier that way.
  • When done, cut the wires at the top of the pillar first, then pull the pillar back so the LEDs are freed, then cut the wires at the bottom of the pillar on the outside of the jig, this gives you another extra cm of wire.
  • Straightening the wire is done by inserting them into the jig, tie their ends together and rotate the bunch. This will put tension on the wires and that will make them nice and straight. Don't put too much tension on them or they will break!
And a few things to keep in mind:
  • Test your LEDs before you put them in the jig, make sure they work and that the brightness is the same as the others; you really don't want to replace a LED when your cube is already constructed.
  • You can use a wire stripper to strip the wire, but I like to use a snap off knife. Just place the wire on a surface, place the knife on the wire and hold it almost parallel to the wire, then gently pull the wire along the knife and half of the insulation will be stripped away in one go. You can peel the other half off easily.
  • The wire I got is pre-tinned, and it looks great! Much better than bare copper in my opinion.
  • You can straighten the wires a bit before inserting them in the jig. Use two pliers to grab both ends of the wire, then tug on them gently a couple of times. Don't do this too hard or too often because the ends will suffer from metal fatigue and break.
  • WASH YOUR HANDS! You're not going to get lead poisoning from breathing fumes, only lung cancer. But the lead does get on your hands, so make sure you wash your hands thoroughly before you eat, drink, rub your eyes, scratch your <insert bodypart>, etc. Also clean your working surface and don't put food on it.
  • Don't breath the fumes, it's not exactly healthy. Using a small 12V computer fan is enough to blow most of the fumes away from you. Keep your mancave/shed/living room well ventilated.
That's it for now, once I'll have my final jig done I'll add another post on this subject.