View previous topic :: View next topic |
Author |
Message |
Einly
Joined: 10 Sep 2003 Posts: 60
|
PIC output pins |
Posted: Sun Dec 26, 2004 9:02 pm |
|
|
DEAR ALL,
I am thinking of controlling the brightness of an LED by using 3 pins of a PIC. Say I am shorting PIN C0, C1 and C2 and connect them to a LED.
1) If PIN C0, C1 and C2 are all 1s, what is the total current to the LEDs? Will it be 3 times the current if I only connect PIN C0 to the LED? Then will the LED be brighter?
2) However, if PIN C0, C1 are 1 and C2 are 0, will the supply shorted? Will it cause any problem?
3) Is my idea possible? _________________ Einly |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Sun Dec 26, 2004 9:35 pm |
|
|
Einly,
Your idea sounds feasible (and neat). There is a maximum current PIC can source/sink (for 18F452 it's 25/25 mA). If you short a pin with output_high to the pin with output_low, your LED will not light up, becasue the pin, which is output_low will sink all current. But you could make the pin an input, therefore high impedance, therefore it will not be sinking current. You can use output_float(PIN_XX) function for that.
e.g. : 1X brightness (assumption: you source current to the LED)
Code: |
output_high(PIN_D0);
output_float(PIN_D1);
output_float(PIN_D2);
|
e.g. : 2X brightness (same assumption
Code: |
output_high(PIN_D0);
output_high(PIN_D1);
output_float(PIN_D2);
|
Have fun,
Nick |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Dec 27, 2004 8:13 am |
|
|
Another way to get Ledīs brightness control is driving them with a square
wave changing itīs duty cycle. You save output PINs with minimum cost.
Humberto |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
Do Not short the Output PINS!!! |
Posted: Mon Dec 27, 2004 8:33 am |
|
|
Shorting ANY PIC pins with "totem pole" outputs will blow the PIC outputs when the pins are in opposing states!!!
This can happen even if you are careful because the PIC powers up in an indeterminate state. All it would take is a fraction of a second and the outputs are toast!
The square wave (PWM) LED drive mentioned by Humberto should do the trick for you and will provide continuously variable output..
You can also use a resistor ladder/divider combination off the three pins to create a variable voltage out if you only need a limited number of preset steps. |
|
|
|