Category Archives: LED

Touch sensor tweaking

The one thing that wasn’t quite behaving right about the LED lamp was the touch sensor. I was having trouble both with it being far too sensitive (and sensitive to interference from other devices nearby — I’d plug in my laptop to an adjacent outlet and it would sense a “touch”), but also it was often not self-calibrating properly.

So, I reread Quantum Research Application Note AN-KD02, “Secrets of a Successful QTouch Design”, and I finally tried properly doing the procedure in section 3 for probing the sensor field. And I discovered one thing: the Rsns value I’d previously guessed at was far too small. I was using 1K, while I got the appropriate sort of risetime with about 18-25k. I decided that Cs was probably also far too high, so I tried reducing it from .044 uF to .022 uF.

It’s a little bit less sensitive now — you have to touch the area on the outside of the glass with at least a couple fingertips, but it’s far more reliable and less prone to interference.

Also, it seems to be recalibrating its threshold more quickly now.

I may try adjusting the value of Cs a little more (need to buy more values of 1206 surface-mount capacitors), but I think I’m almost “done” now.

On another note, I think there’s some FPGA design in my future. It’s got quite a learning curve, but it looks like fun.

More LED lamp software development

I’ve completed the software.

I abandoned the SOIC test clip in favor of wires soldered directly to the board. The SOIC test clip loses contact with the IC if you just look at it funny. It’s very irritating. In the future, all boards will have an in-system programming (ISP) connector.

I just need to finish the mechanical part. I’m waiting on an order for some more nylon screws because I screwed up and ordered the wrong length.

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.)