linear1 forums
[part of the linear1 network]
+ [linear1 case mods]
+ [LED Center]
+ [privacy policy]
Welcome, Guest. Please login or register.
March 21, 2010, 04:15:10 AM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Login Register

linear1 forums  |  LED discussion  |  Microcontroller madness  |  Topic: RGB color matching lamp « previous next »
Pages: [1] Print
Author Topic: RGB color matching lamp  (Read 2572 times)
Superbad
Strong like bull
*
Offline Offline

Posts: 4


« on: June 29, 2006, 06:06:24 PM »

Here is what I am trying to  accomplish.  I want to use a color scanner to get the RGB values for a particular item and have a set of LED's project that color.  I had started planning this project, and then I saw the Philips lamp that does the same thing.  That is exactly what I am looking to do.  I am starting with Basic STAMP as I own one already and also have a TAOS color sensor to go with it.  The sensor will allow me to read R, G, and B as a value between 0 and 255.  I want to the have the controller then trigger the particular LED to shine with a brightness between 0 and 255.  I am gathering a few parts still, but my plan (for each color, so x3) is to use a 2N3904 transistor to control the current into an AD5204 (4X 256 step digital pot on a single chip) and feed that into the LED.  Is my thinking flawed?  I am relatively new to Microcontrollers and LED's and I appreciate any advice given.
Bobby
Logged
Rob
LED guy
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1970


The constant-current gardener


WWW
« Reply #1 on: June 29, 2006, 06:39:34 PM »

Welcome to the boards.

I'm not very uC literate, but I think you have the big picture right. I'd say that most of the effort would be developing a table that calibrates the sensor input to a digipot output. You could PWM the output and omit the digipot too. I believe that approach could actually be simpler, but your uC capabilities will come into play. I dunno if the BASIC Stamp gives you 3 PWMable outs.
Logged

justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #2 on: June 29, 2006, 09:42:33 PM »

I agree with Rob, PWM is the way to go if you already have a microcontroller, but again, I'm not sure of what the stamp basic language can and cannot do.

There should be a PWM command of some sort, which accepts a pin number, duty cycle and duration as arguments.  So you'll need three of these commands, and will call them in a loop, or better yet, with a timer driven interrupt.

Here's some pseudo code to get you started:

Code:
Setup:
Timer0 period 1ms ' fire timer0 counts to 1ms and then overflows, firing an interrupt
Dim RedValue, GreenValue, BlueValue as Byte

On Interrupt Goto DoPwm
Goto ReadColor 'jump over the interrupt handler

Disable Interrupts 'turn off interrupt checking inside handler routine
DoPwm: ' interrupt handler
Pwm Pin1, RedValue, 2 'pwm your "red" pin for 2 processor cycles
Pwm Pin2, GreenValue, 2 'same for green
Pwm Pin3, BlueValue, 2 'and again for blue

Reset Timer
Reset Interrupt
Resume Program
Enable Interrupts 'turn interrupt checking back on

ReadColor:

Read ColorSensor
Process Results
Delay 5 seconds

Goto ReadColor ' do it all over and over

The hardware side should be pretty straight forward, use transistors to amplify the feeble current from the microcontroller into a more substantial current for driving leds.  As Rob points out, you'll most likely need some sort of table mapping sensor readings into accurate colors, the biggest problem will be matching the "brightness", since that is going to be a variable.
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Superbad
Strong like bull
*
Offline Offline

Posts: 4


« Reply #3 on: June 29, 2006, 11:47:56 PM »

Thanks for the help.  Can you suggest a controller that will allow me to use multiple pwm output simultaneously.  The BS2 stamp appears to only support one pwm output at a time.  I have no programmer yet, so I am not tied to a particular brand but I do have the ability to get samples from Microchip. 
Logged
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #4 on: June 30, 2006, 09:31:48 AM »

I suggest you consult the instruction manual for your chip ... as I read it, nearly all the stamps support the PWM command on up to 16 pins.  Check out page 359 of the Basic Stamp Syntax and Reference Manual v2.2

You may be confusing the hardware PWM generator with the software capabilities of the chip.   Since parallax has started using chips other than pic processors, I can't say for certain .  Hardware pwm is generally used for motor control, where you require a very stable frequency base... with leds, it doesn't much matter, achieve more than 60 or so cycles/second and there will be no noticeable flicker to the naked eye.   Software pwm, the PWM command, will do this quite nicely ... persistence of vision will let you control an rgb led easily in this manner.   There are other alternatives out there as well, I know there is code for the microchip pic that will give you eight programmable pwm outputs on one chip, spend a little time with our good friend Google and you should find a ton of examples, as rgb leds continue to fascinate the experimenter crowd.

Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Superbad
Strong like bull
*
Offline Offline

Posts: 4


« Reply #5 on: June 30, 2006, 11:32:03 AM »

It was my understanding that you can use the pwm command on any pin of the Stamp, but it can only support one pwm output at a time.    Thanks for the help.  I hope to eventually get away from stamp as it is very expensive for the chips compared to other microcontrollers.

 
Logged
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #6 on: June 30, 2006, 01:44:29 PM »

check out the picaxe ... it is very stamp like, but a whole-lot-cheaper!

the pwm command will be the same, regardless of what chip you end up with ... you will need three commands, and will have to call them in a loop.  persistance of vision will take care of the rest.  the easiest way to do a loop is with the goto command, but I recommend an interrupt based loop, which will allow you to do pseudo multitasking.

here check out this video:
http://www.manisteecomputers.com/video/garden-light(short_clip).mov

The color fading is done with a PIC microcontroller, using three PWM commands, called in a loop.

full story here.
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Superbad
Strong like bull
*
Offline Offline

Posts: 4


« Reply #7 on: June 30, 2006, 05:53:02 PM »

Thanks for the link.  I appreciate all the help.  I just recieved 5 TLC5940 chips from Texas Instruments to also experiment with.  Has anyone used these? More info at http://focus.ti.com/docs/prod/folders/print/tlc5940.html
Logged
rgbphil
Smart like tractor
**
Offline Offline

Posts: 11


« Reply #8 on: September 17, 2006, 03:21:52 AM »

Hi,
I had a look at doing this a while ago in this thread over at CPF:
http://candlepowerforums.com/vb/showthread.php?t=92733
It's not as simple as it sounds, there is no simple translation between the TAOS sensor and RGB settings on an RGB setup.
However apparently there is a special chip for this sort of thing from Agilent (for details read the thread).
Phil
Logged
justDIY
Microcontroller Madman
Administrator
Smart like tractor
*****
Offline Offline

Posts: 1652


UFOric


WWW
« Reply #9 on: September 17, 2006, 12:25:59 PM »

Hi Phil!

Welcome to the forums.
Logged

Want to contact me directly? gmail gordonthree
My Project Blog - http://projects.dimension-x.net

Favorite numbers:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Pages: [1] Print 
linear1 forums  |  LED discussion  |  Microcontroller madness  |  Topic: RGB color matching lamp « previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.199 seconds with 21 queries.