Well, I completed the project last night. Here is what I did…
First, I measured the current draw of the LED strip from the PSU. It was 1.45A max. I found a 12V 2A wall wart laying around (trusting it would actually provide 2A), and it fit perfectly in the space at the bottom of the lamp (where the ballast transformer was). I removed the plastic case of the adapter, soldered the power input and output cables (also stabilized them with black hot glue), and used the bottom half of its case for insulation.
After screwing the cover plate of the bottom part back into its place, it was time to make another LED driver card. I had made one of these for a sculptor friend, who is going to use it for one of his lamps. So the firmware and the PCB was ready, all I needed to do was to print the PCB on a piece of PNP paper, laminate it on a 50 mm x 100 mm copper clad, etch it, and solder the components on. The whole process of making this card took me about an hour and a half.
My friend, who wanted this LED driver built for him, needed to control the brightness of the LEDs with an optical quadrature encoder in his project (well, he actually said: “no turn limits, very little friction, high resolution”). So the PIC counts the pulses, checks the direction, and feeds it to the PWM DC registers. No look-up tables, no gray code, simple and functional. Works with both mechanical and optical encoders. The only difference is, the mechanical encoders’ A and B pins can’t be reversed, optical ones don’t care. They only need the extra power pin on the board. The mechanical encoder I use in this project is 24 P/R, the optical one I used for his project is 400 P/R. Here’s the schematic, and the PCB shot. Schematic and PCB files are in Proteus Isis & Ares format, but there’s also a PCB print in PSD format. The PIC was programmed in Hitech PIC C. The code is rather simple and efficient. All can be downloaded from here.
The circuit is simple. 12V DC is fed to the LEDs through an N-MOSFET, which is PWM driven by the PIC. The plastic box is an efficient, 5V, switching DC/DC converter, which requires no external components. You could use a 7805 with the necessary capacitors if you chose. The N-MOSFET IRF530 can drive 100V at 14A, continuously. A bit of an overkill, but good for future uses. The firmware limits the DC (duty cycle) of the PWM to 98%, since the N-MOSFET heats up badly (there is a technical explanation for this, but I don’t know what it is) at 100%. The LED on the card is on whenever the min (0%) or the max (98%) value is reached. The PWM frequency is 980Hz, and the DC is adjusted by loading the number of encoder pulses from 0 to 250 (250 is 98% and 255 is 100%) to CCPR1L. Since it would take the mechanical encoder 250 / 24 = 10.42 turns to sweep the whole range, I multiplied the counter with 10, to be able to cover the whole range with 25 pulses (one pulse more than a whole turn). This was no problem with the 400 P/R optical encoder, since 62.5% of a turn (250 / 400) was covering the whole range. It took me a while to be able to fit the card in the space at the head of the lamp. I had to remove a terminal block which was actually unnecessary. I also added two 100 nF capacitors from the A and B pins, which are on the side of the mechanical encoder, to the center GND pin of the encoder for debouncing.
As I was thinking about drilling a hole in the head of the lamp for the quadrature encoder, I realized could actually use the hole for the starter of the old fluorescent lamp. But there was a problem. The hole was too deep for the length of the knob on the encoder. So I turned a 25 mm long aluminum cylinder with 20 mm diameter (good for the 22 mm hole), and drilled a 6 mm hole 12 mm deep (encoder shaft length) at its center. I also cut a grove around the end, and sanded the edges for a better finish. Later on I drilled and tapped a hole on the side for a M4 setscrew. I was actually proud of this last part. It looks really good IMO.
After stabilizing the card in its place, and making the necessary connections with the cables, I screwed the plastic cover back in its place, and finished this project / hack. Here are some extra shots of the lamp and other details.
I also made a rather affordable MIDI Thru box for my music setup in the meantime. I will be writing about it in my next post.
I decided to put the status LED outside for better visibility. Since I didn’t turn off the lamp (what a noob!) as I was unscrewing the cables, I shorted the PSU, and fried it. I mounted the LED in a hole by the knob anyway. The fuse was blown, so I went and got another 0.5A glass fuse. But when I came back, I realized I had fried the IC as well. So I went and got another PSU, 12V 5A (3A was the same size) this time. The case looked bigger than what the space at the bottom of the lamp could handle. Yet, when I opened it, I realized I could saw off an ample part of the PCB, since the traces were straight, thick, and long towards the right. And I didn’t need the 220V socket. So I did that, soldered and gunked the cables back in their places and closed case cover.
Ok, now I can use my lamp…