Monthly Archives: January 2008

LED lamp software

I don’t even have the SOIC-8 test clip so I can program it, but between a couple hours last night and an hour tonight, I’ve already written most of the code for the ATtiny13.

One thing I like about the AVR microcontroller is avr-gcc and avr-libc. It makes for really quick development using tools I’m familiar with. I think I’m 80% done with the code (everything but saving the brightness levels in the EEPROM), and I’ve only used about 1/3 of the 1K program flash.

The basic operation is as follows:
Timer 0 is clocked at the internal 9.6 Mhz RC oscillator divided by 256. It is an 8 bit timer, and OC0A (PB0) is toggled in Fast PWM mode, therefore, this is a PWM output at 9600000/(256*256) = 146.5 Hz with a duty-cycle variable in 256 levels. That is fast enough to avoid flicker, but slow enough to PWM the ZXLD1350 in the ideal manner, varying the LED brightness from off to full power according to whatever value we put in the OCR0A register (with no other software overhead).

The QT100 output goes to PB1, configured as INT0, interrupt-on-rising edge. Thus touching the touch sensor triggers an interrupt which steps the OCR0A level through one of 4 different brightness levels (e.g. OFF, LOW, MEDIUM, HIGH). The QT100 has handled ‘debouncing’ the actual touch sensor.

The two tiny pushbuttons are debounced using a software routine, see this article for some examples. They then increment or decrement the current brightness level in steps of 8, allowing configuration of a particular one of the four brightness levels to one of 32 possible levels.

The Timer 0 overflow (146.5 times per second) triggers an interrupt. Think of this like your generic timer interrupt in a simple OS, usable for running periodic tasks which are not run as a result of external inputs. In this code, it causes two things to happen periodically: Sampling of the two pushbuttons (the debouncing routine considers a valid button value to be 8 consecutive samples) and incrementing a timer value which is zeroed each time a button is pressed. When this timer value exceeds a certain threshold (equivalent to 30 seconds of no buttons pushed), the in-RAM brightness levels are compared with those in EEPROM. If they are different, the RAM values are written to EEPROM. In this way, writes to EEPROM are minimized, but once brightness levels have been reconfigured, they are written out to EEPROM.

At startup, the main() function sets up the I/O lines, the Timer/PWM, loads brightness levels out of EEPROM, sets the current PWM value, enables interrupts and enters a while(1) loop.

LED lamp, done making boards

Though I have a cold, I had to do something with my time (such is life without a TV), and I redesigned the board and etched this:
LED Lamp board, final

This is a project of firsts. Not only my first time designing PC boards, but my first time soldering surface mount devices. I put everything except the ATtiny13 on the board yesterday, and while it was slow, I did it without destroying anything in the process:
LED Lamp board

My observations on surface-mount soldering:
Use plenty of flux. The RMA stuff works okay.
Yes, you want tiny solder (I’m using stuff that’s .015″ diameter.)
Sometimes a small soldering iron tip was good, sometimes a really tiny one was better.
The only hard things were the tiny TSSOP ICs and the nearly-leadless parts (big electrolytics and the inductor).

I was very pleased that the ZXLD1350 part of things works:
LED Lamp board, testing

On the other hand, with the power transformer I had lying around, the input to the ZXLD1350 is too low, resulting in less than maximum LED current, and alarmingly high duty cycle. For the moment, I shorted one of the LEDs for testing purposes, though I’m going to order a 16 volt transformer when I also order a SOIC test clip and some parts for another project. I also need to find some smaller nylon screws and nuts to mount the LEDs to the aluminum stock I’ll be mounting them on for support and heatsinking. 4-40 or M3, I think. The 6-32 is just too big.

Today, I drilled the mounting holes in the PC board — I’d forgotten to do that first, so I had to do it VERY carefully.
(I’ll post the Eagle files and source code once I finish everything.)

Working on a third board rev…

I got the parts for my LED Lamp project from Digikey today. Once I got home from work, I decided to engage in the relatively relaxing and quick task of verifying that everything fits the pads on the board and the board layout.

Most of it is okay, but a couple things are wrong:

I chose a different ATtiny13 SOIC package from someone else’s eagle library than the one I bought. The one I bought has gull wing leads that stick out further.

The United Chemi-Con MVE-series electrolytics I bought are a little different shaped than I interpreted from the datasheet (pdf), forcing me to change their location with regard to some other stuff. On the positive terminal side, the base has the corners are cut in at a 45 degree angle. The data sheet doesn’t give a clear measurement of how far they are “cut” from a full square. In making a part in Eagle, I assumed more than the real dimensions of the part, so as a result, if I were to use my board, I’d have capacitors overlapping the ua78L05 voltage regulator and screw holes. Oops.

At least it’s good experience making boards.

I’ve got a cold though, so I think I’m going to have to take it easy for a couple days.

Second LED lamp board

LED lamp board, second revision
LED lamp board, second revision
From my comments on the flickr post:
All hand-routed this time. The more I get familiar with the particular board layout, the less the autorouter impresses me.

[The second image is] with jumper in place. I laid it out as to use a 1206 zero ohm resistor, but since I hadn’t ordered any, I just put a piece of 24 AWG wire in place.

Either I didn’t etch long enough, or I smudged the toner resist, or I just got too greedy, because the area where the ground connects through needed some work with a knife to properly separate the traces.

I’m thinking of going to doing double-sided boards and making the bottom side just a ground plane and doing vias to the ground plane below. All I need is suitable drilling equipment (cheap drill press thing for a Dremel and appropriate bit, maybe) and to figure out some kind of easily removable resist I can apply to the backside.

Link to the schematic

LED lamp, PC board design, soldering stuff

I’d been working on the LED lamp design. I have the circuit design basically done, and I’ve been spending my free time in the past week learning Eagle CAD and designing the board. It’s quite a learning curve, but I’m also satisfied that this software can do what I need.

Here is my first board design that was good enough to try making:
led touch lamp - final board layout

I spent all Sunday afternoon working on the toner-transfer method of PC board fabrication, both for reasons of cost and turnaround time. If I were making boards in some quantity greater than one, there are several places that offer great service and prices, but for this, I’m aiming to do a simple etched board, no silk-screening, etc.

In essence, what you do in the toner-transfer process is print a mirror image of the copper traces you want with a laser printer onto glossy paper or special plastic film (I’m using the Press and Peel Blue), then you iron it onto clean copper-clad board so that it sticks, and peel away the film. This leaves behind a layer of toner on the board, which then you etch in an acid (ferric chloride solution), but the toner acts as a resist, preventing the acid from eating all the copper away. Then you wipe away the toner with acetone. (Recommended disposal of the used etchant is by neutralizing with sodium carbonate, precipitating out all the metal ions — copper is not too good for some aquatic life, so it’s preferred that it’s not dumped in the sewer — also, ferric chloride can cause damage to metals, including stainless steel sinks.)

This leaves you with something like:
LED Touch Lamp - Etched circuit board

I still need to work on a little bit of the technique. A couple places the toner didn’t adhere perfectly, and I have a break in a trace. Both I could jumper around, but I’d like to avoid that. Searching the web, I see other people suggest that you don’t want the plastic film extending beyond the board, because it will warp from the heat — I noticed this. I may try some other improvements, even up to buying a “dry” iron that has a flat surface on the bottom (no holes for steam).

About a week ago, I was soldering some parts onto the 9090 boards I bought a couple years back, intent on finally building that, when the cheap iron (the most basic 12W Weller model, non-replaceable tip and heater) I was using FELL APART. The tip just fell out. This was what finally drove me to go and buy a decent temperature controlled soldering station. All-Spec had the Hakko 936 on sale, and everything I read suggested it was a decent soldering station. So, I bought that and a bunch of stuff to make SMT soldering easier: .015″ 63/37 solder, flux pen (got both with RMA flux), a small tip, a really small tip, and some desoldering braid (Chem-Wik). I also noticed that some people seem to like these replacements for the traditional soldering sponge, like the Hakko 599B, so I picked one up. Well, I got my order today and played with stuff, and the waterless tip cleaning stuff really works nicely!

I played with the board I etched a little — while I’m still waiting for my parts order, I figured I’d solder the wires that attach to the board, just to test things out. This is where I learned that 16 mil clearances around the pads is just not going to work. I couldn’t un-bridge the solder bridge I made with repeated application of desoldering braid. So, I’m redesigning the board, for at least 24 mil around pads, maybe even more. I think though, that that particular place was even smaller than 16 mil, due to poor toner transfer.

Just in the little time I’ve looked into redesigning the board this evening, I have learned that Eagle lets you set different nets to different “classes” which have their own width and clearance values. So, for example, I can make signal traces smaller than power traces, easily. But, now, it’s time to sleep.