Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 25th June 2007, 06:01 PM   (permalink)
Default LED Controller - Fade Between Colours

After a lot of looking, I realized its just not going to happen without a uC. What Im looking to do is have a potentiometer, that I can turn from fully CCW to fully CW, and have it fade between red, green, blue, and all the different colours inbetween. Id be using a lot of RGB leds (the kind with four leads), to light up the boarder of a room, or at least part of it (and the knob would change the colour on demand).

Ive got a couple 16F84A's and one 16F873A in my cabinet, so Id like to use these if at all possible. Would anyone be able to point me in the direction of a schematic and code (considering Ive never coded a uC before, or anything for that matter), or even better, be able to at least write the code for me?
ParkingLotLust is offline   Reply With Quote
Old 25th June 2007, 09:06 PM   (permalink)
Default

Sounds like a cool project, maybe a little much for a beginner. The ADC can read the potentometer. Probably want to stick with 8 bit resolution for 256 colors, and the PWM is 8 bits, bytes are 8 bits. It'll greatly simplify the code, and memory might be an issue. The duty cycle determines the brightness of each of the three LED colors. Using a look-up table would take 3*255 is 765 bytes (guessing if you want black, just hit the power switch).

I use AVR, so don't know the details on the PICs you have, but should be good enough. Coding... might get lucky here. Sounds cool and fairly simple.
HarveyH42 is offline   Reply With Quote
Old 25th June 2007, 09:31 PM   (permalink)
Default

Quote:
Originally Posted by ParkingLotLust
Ive got a couple 16F84A's and one 16F873A in my cabinet, so Id like to use these if at all possible.
The PIC16F84 doesn't have the A/D module, so you can't read the potentiometer. If you use a button, you can increment a variable when it's pressed.
eng1 is offline   Reply With Quote
Old 25th June 2007, 09:38 PM   (permalink)
Default

So since I'd need an ADC, Id probably be more apt to use a 16F88 if I wanted to use a pot to control the LEDs, right?
ParkingLotLust is offline   Reply With Quote
Old 25th June 2007, 09:44 PM   (permalink)
Default

Quote:
Originally Posted by ParkingLotLust
So since I'd need an ADC, Id probably be more apt to use a 16F88 if I wanted to use a pot to control the LEDs, right?
It's simple to do without an A2D (see my tutorials) but the 16F84 shouldn't even be a consideration! - and an A2D does make it slightly simpler.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 26th June 2007, 01:16 AM   (permalink)
Default

I can share a schematic, just to show there isn't much involved, but I'm afraid I don't have finished code (sorry). The prototype uses a rotary encoder with detents and it has a built in push button switch on the shaft.

Good luck with your project. Mike
Attached Images
File Type: jpg RGBX.JPG (100.1 KB, 46 views)
Mike, K8LH is offline   Reply With Quote
Old 26th June 2007, 02:38 AM   (permalink)
Default 2N7000 dead

Mike K8LH,

You are using a 2N7000 as an inverter for RS232 input. I have problems killing the gate input on FETs when connected to another board. You need some kind of protection for the gate of the FET. Try using a digital transistor with two 10k resistors built in. See:
http://www.semicon.panasonic.co.jp/ds2/SJH00039BED.pdf

To scan the switches A, B and S you will need to put 011, 101, and 110 on Q7,Q6,Q5 so the LED can not be 100% on or 100% off.

ron
ronsimpson is offline   Reply With Quote
Old 26th June 2007, 06:06 AM   (permalink)
Default

Hello PLL.
If you aren't dead set on building it yourself, and have $20 to $60, you can buy a PIC on a plugin module loaded with an easy to use BASIC with commands that make things like reading voltages (from pots) and doing PWM easy. These would be the Atom (http://www.basicmicro.com/Category.aspx?CategoryID=1) or the PICAxe (http://www.rev-ed.co.uk/picaxe/). They both have a powerful BASIC, which makes programming fairly simple, though not effortless.

The Atom IC by itself can be had for as little as $20, but you have to supply a crystal or resonator, DC power jack, RS-232 IC... a boatload of stuff, then assemble it all together without mishap. I have these, and other variations.

The PICAxe-18 (an 18 pin IC) can be had for as little as $2.50. It has a few channels of analog inputs and several outputs to drive the LEDs. I'm not as familiar with these chips as the Atom, so you'll want to check these carefully for suitability.

Of course shipping and handling will add to the final cost.
Both have enough current out to drive typical LEDs handilly.

Hope that helped.
kenjj
__________________
All my pencils *used* to have erasers!
kjennejohn is offline   Reply With Quote
Old 26th June 2007, 09:05 AM   (permalink)
Default

Isn't the current limiting resistor needed for the LED? Or it is not needed if the LED is PWM driven?
__________________
Superman returns..
bananasiong is offline   Reply With Quote
Old 26th June 2007, 03:28 PM   (permalink)
Default

Some people say you must always use current limiting resistors with LEDs, and I'm really not qualified to argue the point. From personal experience... If the LED is to stay on steady, then yes it's a good idea, since there would be not chance to cool down. For things that flash, pulse or fade, I seldom bother. Most of the AVR circuits I've done with LED don't have them, and have been working just fine. The outputs will source 25mA, common LEDs are rated for 20 mA, not really abusing the that much.
HarveyH42 is offline   Reply With Quote
Old 26th June 2007, 03:50 PM   (permalink)
Default

Same with PIC's, they will output about 25mA per pin, BUT (and presumably the AVR is the same?) it's NOT really a current limited output, just specified that you shouldn't draw more then 25mA from it. So it's certainly good practice to include a limiting resistor, regardless of PWM or not.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 26th June 2007, 04:20 PM   (permalink)
Default

One can only have PWM or flashing when the controller is running proper code. Can you 100% sure that it will remain that way?

What happens when it hangs upon a power glitch? No more PWM output and your port pin and/or LED will be possibly damaged.

Use a resistor.
__________________
L.Chung
eblc1388 is offline   Reply With Quote
Old 26th June 2007, 11:56 PM   (permalink)
Default

I have burned 2 PICs because I didn't use the resistor..
__________________
Superman returns..
bananasiong is offline   Reply With Quote
Old 27th June 2007, 12:25 AM   (permalink)
Default

As with a lot of engineering, it depends.

To a first approximation, an LED looks like a forward biased diode (with a specified Vf) in series with a resistance. The microcontroller looks like a voltage source (Vcc, Vdd) in series with a resistance.

You can estimate each of these resistances by plotting the V/I curve, from the data sheet, or you may have to measure it. In my experience, the typical 20 mA output from a PIC or AVR is around 10 ohms, give or take. I've seen LEDs from 10 ohms to 100 ohms.

Subtracting the Vf of the LED from the Vdd of the micro, you have the voltage that needs to be dropped across the resistance. In the rare case where the sum of the internal resistances is appropriate, you don't need a separate resistor. In the more common case, a series resistor could save your micro, or your LED. Don't forget to look at the peak rated current if you plan to PWM.

For some applications, a designer or hobbyist will say reliability doesn't matter, at least till something fails.
mneary is offline   Reply With Quote
Old 27th June 2007, 01:16 AM   (permalink)
Default

These past few post are more wastefull than adding components to a design that do nothing:

You cannot burn out a PIC with an LED load, 1/4 watter or 2 watter makes no difference.
You cannot burn out a PIC given the output is tied directly to Ground.

1/2 of my projects use resistors for LEDs, the other 1/2 of the projects do not and the projects are purely LED based. So why do I not use the resistors? Because there is no question in my mind wheither or not I should use them.

If there is any question as to wheither or not to use a resistor, then use a Resistor and use the correct value and wattage resistor. End of that discussion.

Last edited by donniedj; 27th June 2007 at 01:18 AM.
donniedj is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Flashing a LED with Mouse Gayan Soyza Electronic Projects 12 28th March 2007 10:53 PM
Accessing EEPROM Clayton Micro Controllers 15 23rd March 2007 03:00 AM
LED fade controller ooMcLeoDoo Electronic Projects Design/Ideas/Reviews 5 26th February 2007 01:15 PM
Xbox 360 Tilt Controller adamthole Electronic Projects Design/Ideas/Reviews 0 20th January 2007 05:24 PM
closed loop controller that receives set point updates TXRX usacanbiteme Electronic Projects Design/Ideas/Reviews 5 28th September 2005 09:02 PM



All times are GMT. The time now is 11:49 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.