Author Topic: RGB LED lighting an S-10 truck gauge cluster  (Read 2595 times)

0 Members and 1 Guest are viewing this topic.

Offline SegTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: us
RGB LED lighting an S-10 truck gauge cluster
« on: September 23, 2014, 10:30:45 am »
So a friend cleaned out their lab and gave me a big box of fun stuff to play with. Just need to figure out a project...

Well, the last lingering light bulb in the gauge cluster of my wife's '92 S-10 truck (Heirloom from her father) finally burned out, so now I have to fix it. Hmm, maybe I can fit some ShiftBrites in there...

Took the dash apart, (Thanks S10Forum!) the gauge cluster has six backlight bulbs that twist-and-lock into the back of it. The back of the cluster module has a flex circuit covering it. No easy way to attach ShiftBrites there without risking damage, and there's no room anyway. But the structure behind the cluster has holes in it for the back of the light bulb mounts to stick through. Will they fit there? Yes they will! In the interest of getting this done fast I got the hot glue gun out and gooped them in...



I cut up a plastic milk jug to make mounting tabs for the larger holes. There's a sixth bulb that goes toward the center. Testing with a flashlight determined it doesn't do anything but pathetically light the odometer, so rather than waste a ShiftBrite on it, I took the still working bulb for the worthless seatbelt reminder light and put it there.



Even with the sub-optimal placement and diffusion of the LEDs, it glows quite nicely and looks good even in daylight so I may not even bother to wire it into the headlight switch. For now power is tapped from the subwoofer's terminals...



I initially ran the ShiftBrites off a Shifty VU shield but I didn't want to blow a whole Arduino on this. Also in the box of stuff came a bunch of MSP430 Launchpads. I can't think of a better use for that dinky '2211 they give you, so I ported my code to the Launchpad and built a custom board to put in the truck.



A Chinese LM2596 buck converter (eBay, less than $1.50 USD) provides 5.5v to run the ShiftBrites. A LP2951CN-3.0 regulator (7 came in a Jameco Linear series grab bag) provides 3v to run the MSP430.



I just pull the chip to program in a Launchpad so I tried to keep the socket clear, and crammed it all in a corner to see how small I could make it.



For now it just slowly shifts through a color spectrum, using 16-bit fixed point HSV to RGB conversion. (The '2211 doesn't even seem to have enough flash to fit the FP library...)

I've got enough ShiftBrites left over to have a test string on my desk, someday I'll come up with some better effects...
 

Offline SegTopic starter

  • Regular Contributor
  • *
  • Posts: 71
  • Country: us
Re: RGB LED lighting an S-10 truck gauge cluster
« Reply #1 on: November 06, 2014, 05:02:49 am »
Suppose I should post some code since I spent way too much time banging my head against it all.  |O

If you look around for HSL/HSV to RGB code, you'll probably find nothing but floating point implementations. Modern micros such as an AVR seems to be plenty fast enough to pull this off in float, but as an obsessive optimizer I gotta have me some fixed point...

I messed around with HSL, I could not find a fixed point implementation so I tried converting a float implementation to fixed point myself, with no success. So I looked at HSV instead, which looked much simpler, and with some digging found some fixed point implementations, that were written for 32bit machines and did not work on an 8bit micro. The compiler on a 32bit architecture will happily promote everything to 32bit math at the slightest provocation, skirting overflow issues. This does not happen on an 8bit micro, you have to be very careful with your casts. I hid all that ugliness in the multiply macro.

Anyway, here's some code that should work properly on any architecture:

First, 8-bit. This is really raunchy and coarse, and does not cut it for the 10-bit ShiftBrites. But it should be as fast as can be, and may be good enough for something like an LPD6803, which only do 5-bits per channel, or direct PWM.
Code: [Select]
// 8 bit integer HSV to RGB
static void HSVtoRGB8(
uint8_t& r,
  uint8_t& g,
  uint8_t& b,
  uint8_t h,
  uint8_t s,
  uint8_t v
){
if(s==0){
r=g=b=v;
return;
}

uint8_t f = (h%43)*6;
// fixed point multiplication
#define mul8(a,b) ((((uint16_t)a)*((uint16_t)b))>>8)
uint8_t p = mul8(v,255-s);
uint8_t q = mul8(v,255-mul8(s,f));
uint8_t t = mul8(v,255-mul8(s,255-f));

switch(h/43){
case 0: r=v; g=t; b=p; break;
case 1: r=q; g=v; b=p; break;
case 2: r=p; g=v; b=t; break;
case 3: r=p; g=q; b=v; break;
case 4: r=t; g=p; b=v; break;
default: r=v; g=p; b=q; break;
}
}

And now the 16-bit version. This gives silky smooth fades with the ShiftBrites. (Remember to shift right by 6!) And should be fast as can be on an MSP430, being 16-bit plus the 32-bit multiplier, it was made for 16-bit fixed point! (However I have not confirmed gcc is actually utilizing the MPY...)
Code: [Select]
static void HSVtoRGB16(
uint16_t& r,
  uint16_t& g,
  uint16_t& b,
  uint16_t h,
  uint16_t s,
  uint16_t v
){
if(s==0){
r=g=b=v;
return;
}

uint16_t f = (h%10923)*6;
// fixed point multiplication
#define mul16(a,b) ((((uint32_t)a)*((uint32_t)b))>>16)
uint16_t p = mul16(v,65535-s);
uint16_t q = mul16(v,65535-mul16(s,f));
uint16_t t = mul16(v,65535-mul16(s,65535-f));

switch(h/10923){
case 0: r=v; g=t; b=p; break;
case 1: r=q; g=v; b=p; break;
case 2: r=p; g=v; b=t; break;
case 3: r=p; g=q; b=v; break;
case 4: r=t; g=p; b=v; break;
default: r=v; g=p; b=q; break;
}
}

Have fun!  8)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf