![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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? |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
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?
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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! |
|
|
|
|
|
|
(permalink) |
|
Isn't the current limiting resistor needed for the LED? Or it is not needed if the LED is PWM driven?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
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.
|
|
|
|
|
|
|
(permalink) |
|
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.
|
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
I have burned 2 PICs because I didn't use the resistor..
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |