Searching \ for '[PIC]: LED brightness control thru PIC...' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/displays.htm?key=led
Search entire site for: 'LED brightness control thru PIC...'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: LED brightness control thru PIC...'
2002\02\27@030705 by Pic Dude

flavicon
face
I would like to control the brightness of some LEDs (directly attached to
a port on a PIC) thru code.  Each LED would be at full bright or dim -- just
2 intensities.  Here's what I thought...

Assume as some point in the code, I want to set the output to
'ooBoDDBo' where 'o' is Off, 'B' is Bright, and 'D' is Dim.

Let V1 = value of port for dim LED's.  In this case V1 = '00001100'
Let V2 = value of port for bright LED's.  In this case V2 = '00100010'

Then set V3 1 = V1 OR V2 = 00101110'

Now in my code, every time I come around in the main loop, I would
alternate the output between V1 and V3.  Bright LEDs would get set
all the time (both times), and dim LED's would get set only on alternate
cycles -- sort of like a pulse-width dimmer.

Perhaps I may need to have 3 cycles with V1, V1, V3 depending on relative brightness level, etc.

Is this reasonable?  Is there an easier/better way to do this?  I'll be
using a 16F84 or 16F872 for this.

Thanks,
-Neil.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@032530 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

Neil,

Check the recent thread "Ultra fast low res PWM".  There are several code
examples for minimal software PWM routines that take only a few cycles.

Regards

Mike

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@040435 by Vasile Surducan

flavicon
face
On Wed, 27 Feb 2002, Michael Rigby-Jones wrote:

> Neil,
>
> Check the recent thread "Ultra fast low res PWM".  There are several code
> examples for minimal software PWM routines that take only a few cycles.
>
 or if you haven't enough patience for that, try software pwm in Jal for
16F84, or hardware pwm for 16F87x.

include 16f84_4
include jpic
include jdelay

var bit led is pin_b7
pin_b7_direction = output
var byte pulse = 1

forever loop
 delay_100us ( pulse )
 led = high
 pulse = pulse + 1
 delay_100us ( 255 - pulse )
 led = low
end loop

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@081955 by Olin Lathrop

face picon face
> I would like to control the brightness of some LEDs (directly attached to
> a port on a PIC) thru code.

You only need one line per LED, then use PWM to control the brightness.
(This might be what you said in the rest of the post.  I got a bit confused,
but it may have been a long winded say to say "PWM").  Anything over 100Hz
should be fine, which means you can easily control a number of LEDs using
software PWM from a timer interrupt.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olinspamKILLspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@143855 by uter van ooijen & floortje hanneman

picon face
Now in my code, every time I come around in the main loop, I would
alternate the output between V1 and V3.  Bright LEDs would get set
all the time (both times), and dim LED's would get set only on alternate
cycles -- sort of like a pulse-width dimmer.
--------
Seems OK, assuming that there is no even pattern in your main loop cycle
times. BTW an 872 has PWM hardware....

Wouter van Ooijen
--
Van Ooijen Technische Informatica: http://www.voti.nl
Jal compiler, Wisp programmer, WLoader bootloader, PICs kopen

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2002\02\27@163017 by Paul Harris

flavicon
face
Another method would be to use the rrf function and a number of constant
values.

if you were to use the code

rlf Led1
btfsc LED1,0
bsf PORT.....
btfss LED1,0
bcf PORT.....

and just load Led1 with different values for different brightness

01010101 would be 50%
01000100 would be 25%
11111111 would be 100% and so on.

Paul Harris
{Original Message removed}

2002\02\28@021754 by Pic Dude

flavicon
face
Seems like PWM is the way to go.  I was not aware of PWM (as
it relates to PIC's) or how to use it, but I'll do some reading...

Thanks!



{Original Message removed}

2002\02\28@080044 by Olin Lathrop

face picon face
> Seems like PWM is the way to go.  I was not aware of PWM (as
> it relates to PIC's) or how to use it, but I'll do some reading...

PWM is a form of dithering.  It uses a single digital output line as an
analog output by varying its duty cycle (fraction of the time the line is
high).  If the line is dithered between high and low faster than whatever is
out there can react, then the attached device will "see" the average voltage
instead of the successive high and low levels.  You can help this along by
adding an analog low pass filter to the output.

My HAL project uses the PWM output of a 16F876 to produce audio, see
http://www.embedinc.com/pic/hal.htm.

You don't need the PIC PWM hardware to do PWM, although you won't get the
same combination of resolution and frequency.  However, you don't need much
for adjusting the brightness of an LED.  100Hz is fast enough so that humans
will see the average brightness instead of the individual pulses.  You
could, for example, take an interrupt every 1mS to adjust as many PWM
outputs as you want.  This would give you 11 different brightness levels and
take one interrupt every 5000 instructions if the PIC is running at 20MHz.
Of course, this could just as well be 6 levels at 200Hz, etc., etc.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam.....embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...