Searching \ for 'I need more hardware PWM outputs!!' 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/io/pwm/index.htm?key=pwm
Search entire site for: 'I need more hardware PWM outputs!!'.

Truncated match.
PICList Thread
'I need more hardware PWM outputs!!'
2003\01\30@161143 by Philip Galanter

flavicon
face
My need is to drive an RGB LED which is more or less like driving 3
discreet LEDs.  Since I want to be able to generate an arbitrary
color and brightness, and still have lots of PIC left to do other
things, using a part with 3 hardware PWM outputs seemed like a
natural.

The problem is my work is somewhat constrained (my skills and tools
are at the level of clever (I hope!) hobbyist rather than working
engineer) and it looks like there isn't a part I can work with this
way:

* there are some PIC17xxxx's that have 3 PWMs, but they are not
flash-able...a development problem for me, plus I want the final
product to be field programmable.

* the PIC18F458 and PIC18F448 are DIPs and claim 5 PWMs but my
reading is that they are not fully independent units, but rather
produce related phases for motor control and thus not good for my
need to make arbitrary colors (right?)

* all the other PIC18xxxx's with 3 or more PWMs are in non-DIP
packages like TQFP and so too difficult for me to work with.  (Tried
to find some socket converters...at $50 and more they are as much or
more than my total per-unit parts budget!).

Alternatives I've thought of:

* use 2 PICs which each have 2 PWMs and have them talk to each other
when it's time to change colors

* bit bang 3 pins for independent PWM...but if I do that with enough
resolution (8 bits minimum...10 better) I think I will run out of
cycles...

* ...but if I can almost get that working I could make a dedicated
RGB driver chip with one PIC, and then program a main PIC to do all
the other work and  tell the RGB driver chip what
hue/saturation/brightness it wants with a 3 byte message.

* ...but then I might as well investigate other off-chip DACs...

MY QUESTIONS - any new PICs coming soon that offer 3 or more
independent PWMs in an easy to use DIP package?  Any other
alternatives I've not thought of?

thanks, Phil

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@161527 by Wouter van Ooijen

face picon face
> My need is to drive an RGB LED which is more or less like driving 3
> discreet LEDs.  Since I want to be able to generate an arbitrary
> color and brightness, and still have lots of PIC left to do other
> things, using a part with 3 hardware PWM outputs seemed like a
> natural.

Are you sure you won't have enough CPU left after bit-banging 3 PWMs for
LED driving? If that is realy the case why not use a dedicated small PIC
(12F629) to do the job?

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@162812 by Spehro Pefhany

picon face
At 04:05 PM 1/30/2003 -0500, you wrote:


>* bit bang 3 pins for independent PWM...but if I do that with enough
>resolution (8 bits minimum...10 better) I think I will run out of
>cycles...

This is probably the best solution. If you do 8 bits and
one interrupt every 40 microseconds, so you'd have almost 200
instructions @20MHz to do the three PWMs.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffspamKILLspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@170329 by Josh Koffman

flavicon
face
I was faced with the same problem as you. Well, similar, but more PWM. I
was wary of software PWM, but after some discussion with Scott Dattalo,
I adapted his code at
www.piclist.com/techref/microchip/pwmmult-sd.htm
It really does work! :)

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

Philip Galanter wrote:
>
> My need is to drive an RGB LED which is more or less like driving 3
> discreet LEDs.  Since I want to be able to generate an arbitrary
> color and brightness, and still have lots of PIC left to do other
> things, using a part with 3 hardware PWM outputs seemed like a
> natural.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@172022 by Philip Galanter

flavicon
face
At 10:14 PM +0100 1/30/03, Wouter van Ooijen wrote:
>  > My need is to drive an RGB LED which is more or less like driving 3
>>  discreet LEDs.  Since I want to be able to generate an arbitrary
>>  color and brightness, and still have lots of PIC left to do other
>>  things, using a part with 3 hardware PWM outputs seemed like a
>>  natural.
>
>Are you sure you won't have enough CPU left after bit-banging 3 PWMs for
>LED driving? If that is realy the case why not use a dedicated small PIC
>(12F629) to do the job?
>
>Wouter van Ooijen

yeah, further down I mention that as a possibility...

napkin calculation regarding time needed for bit banging...but
correct me if I am thinking about this the wrong way...I am still
learning...

To ensure no flicker problems lets say the basic cycle is 100hz.

Then if I use 8 bits of resolution for brightness I have to check the
duty cycle (256*100) = 25600 times per second.  At 4 Mhz I get
1000000 instructions per second.  So if the PWM calculation is in an
event loop, I get 1000000/25600  or about 39 instructions per loop.

I'd rather use 10 bits of brightness resolution.  (This *can* be seen
at low levels of brightness.  I want to be able to ramp up the LED
without "zipper noise" or obvious "steps".  I might be able to use
some kind of nonlinear transfer function so there is more resolution
at low light than bright...).

So for 10 bit resolution 10^6/(2^10*100) = 9 instructions per loop

A 20 Mhz crystal will allow about 45 instructions per loop.  Or 195
instructions at 8 bit resolution.

Given all the other stuff I expect to be doing I don't think that is
enough cycles to do it all on one PIC...frankly I'd like the "cpu" to
be entirely unburdened from PWM generation.

Phil

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@175249 by Philip Galanter

flavicon
face
At 5:09 PM -0600 1/30/03, Josh Koffman wrote:
>I was faced with the same problem as you. Well, similar, but more PWM. I
>was wary of software PWM, but after some discussion with Scott Dattalo,
>I adapted his code at
>www.piclist.com/techref/microchip/pwmmult-sd.htm
>It really does work! :)
>
>Josh

Useful, but I'd have to create the "difficult but not impossible" mod
to allow it to change duty cycle on the fly...but a good place to
start...thanks!

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@180713 by Mike Singer

picon face
Philip Galanter wrote:
...
> Then if I use 8 bits of resolution for brightness I have to check the
> duty cycle (256*100) = 25600 times per second.  At 4 Mhz I get
> 1000000 instructions per second.  So if the PWM calculation is in an
> event loop, I get 1000000/25600  or about 39 instructions per loop.
>
> I'd rather use 10 bits of brightness resolution.  (This *can* be seen
> at low levels of brightness.  I want to be able to ramp up the LED
> without "zipper noise" or obvious "steps".  I might be able to use
> some kind of nonlinear transfer function so there is more resolution
> at low light than bright...).
...

  How about color TV ideas? Human eye can't sense 0.0001
blue when red is 1.0.
  I think, you need one brightness signal and two low-resolution
color-difference signals. Brightness channel should provide
overall current, color-difference channels should divide the current
between LEDs. Heck with PWMing, use PIC outputs and resistors
as DACs.
  Ask List about schematic, I'm sure, you'll get excellent ideas.

  Good luck.
  Mike.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@182425 by Spehro Pefhany

picon face
At 05:15 PM 1/30/2003 -0500, you wrote:

>I'd rather use 10 bits of brightness resolution.  (This *can* be seen
>at low levels of brightness.  I want to be able to ramp up the LED
>without "zipper noise" or obvious "steps".  I might be able to use
>some kind of nonlinear transfer function so there is more resolution
>at low light than bright...).

Do a log PWM. The lower order bits can be done with inline code and
a single interrupt, with the higher order ones you'll be able to
return from the interrupt and go do plenty of other stuff. I don't
see any excuse to involve extra micros. If you you have 50%
throughput left on a 20MHz PIC, that's like just tossing a 10MHz
PIC and any support components into the garbage with every one you
make. Does that make sense to you?

7 or 8 bits are plenty if they are spaced out properly, and you won't
run into all the overhead of dealing with >8bits on an 8-bit machine.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffTakeThisOuTspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@183941 by Josh Koffman

flavicon
face
You can easily change the duty cycle, just reload the counters when the
edge counter overflows. I think (I haven't looked at Scott's comments
recently) the difficult but possible mod was to allow different periods
for each output.

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

Philip Galanter wrote:
> >http://www.piclist.com/techref/microchip/pwmmult-sd.htm
>
> Useful, but I'd have to create the "difficult but not impossible" mod
> to allow it to change duty cycle on the fly...but a good place to
> start...thanks!

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@192418 by Jake Anderson

flavicon
face
instead of running at 100hz could you put a small cap on your output and
average the PWM a little? seems to me you could run it slower then (like the
afterglow on a phosphor screen)
{Original Message removed}

2003\01\30@194212 by Scott Dattalo

face
flavicon
face
On Thu, 30 Jan 2003, Josh Koffman wrote:

> You can easily change the duty cycle, just reload the counters when the
> edge counter overflows. I think (I haven't looked at Scott's comments
> recently) the difficult but possible mod was to allow different periods
> for each output.


Changing the PWM duty cycle on the fly is trivial. I've made the change
and gave Josh a copy. I still haven't put the code on my web page though.
As it stands, the PWM routine takes 23 cycles for 8 outputs. If you only
need three, then that reduces by 10 cycles.

Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email RemoveMElistservspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\01\30@200254 by William Chops Westfield

face picon face
   bit bang 3 pins for independent PWM...but if I do that with enough
   resolution (8 bits minimum,10 better) I think I will run out of cycles.

I don't think you could 1024 useful brightness levels out of a typical
LED.  That's better than most color monitors...  Even If you COULD do
it, I'd question the need to do it...

(does anyone happen to have specs on those roadside "TV" screens that
seem to be made up of LED emitters?  I'm betting fewer than 16 levels
per LED...)

BillW

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservEraseMEspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\01\31@055619 by Wouter van Ooijen

face picon face
> To ensure no flicker problems lets say the basic cycle is 100hz.
> I'd rather use 10 bits of brightness resolution.

That might be possible but not easy.

- use 9 bits?
- use 20 MHz?
- use 6 PWM channels at 8 bits, with two resistors per LED to get better
resolution at low light levels?
- use 50 Hz?
- don't use an event loop, use a timer interrupt
- check 'vertical counters'

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspammitvma.mit.edu>

2003\01\31@061040 by Scott Dattalo

face
flavicon
face
On Thu, 30 Jan 2003, Scott Dattalo wrote:

> On Thu, 30 Jan 2003, Josh Koffman wrote:
>
> > You can easily change the duty cycle, just reload the counters when the
> > edge counter overflows. I think (I haven't looked at Scott's comments
> > recently) the difficult but possible mod was to allow different periods
> > for each output.
>
>
> Changing the PWM duty cycle on the fly is trivial. I've made the change
> and gave Josh a copy. I still haven't put the code on my web page though.
> As it stands, the PWM routine takes 23 cycles for 8 outputs. If you only
> need three, then that reduces by 10 cycles.

See:

http://www.dattalo.com/technical/software/pic/pwm8.asm

for an up-to-date implementation of 8 simultaneous pwms.

Scott

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestEraseMEspamEraseMEmitvma.mit.edu>

2003\01\31@113159 by Philip Galanter

flavicon
face
Thanks for all the useful feedback...for those following along here
are some quick replies, but it looks like I have some things to try
this weekend!

Wouter mentioned "check 'vertical counters'"...sorry, but I don't
know what that means...a bit of a clue would be appreciated...

Regarding log math and whether 8 bits of resolution is enough...

The eye's response is logarithmic and I want the application to be
able to control the brightness in a way that looks linear.  So using
the hardware PWM on a single color LED I made an exponential look-up
table to map 0-255 into a curve that *looks to the eye* like a linear
increase in brightness.  So if I drive the LED through that lookup
table with a simple loop 0 to 255 it gets brighter at an apparently
constant rate.  The problem is that from about 0 to 30 or so the
steps look "quantized"...I can see the LED getting brighter in
(tick-tick-tick) steps.

I could add more intermediate steps from 0 to 30, but it seems to me
the only way to do this is to either (1) lose my nice visually linear
ramp or (2) lose the ability to drive it with a nice linear counter
or (3) sacrifice some of the upper end of the range or (4) increase
the size of the lookup table which means adding more bits of
resolution.

Regarding moding the posted code for duty cycle changes on the fly
and more recent code...thanks!  I'll definitely give it a whirl...

Regarding putting a capacitor on the PWM output...I could do that but
then the optical output has a time constant...I'd like to be able to
do slow ramps *and* instant changes that look "right" visually...

thanks again all...

Phil

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspam_OUTspamKILLspammitvma.mit.edu>


'I need more hardware PWM outputs!!'
2003\02\01@040739 by Wouter van Ooijen
face picon face
> Wouter mentioned "check 'vertical counters'"...sorry, but I don't
> know what that means...a bit of a clue would be appreciated...

http://www.google.com/search?sourceid=navclient&q=vertical+counters

(Scott's page is the first hit, as it should be)

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@054756 by Peter L. Peres

picon face
Use linear interpolation between the lower values in the table. The user
won't notice if the steps are close enough already. Note that a user who
knows what he is looking for can discern 0.5% light changes in certain
ranges (8bit da). Another way to remove the tick-tick-tick is to slow down
the changes, either using external RLC elements or in software.

Peter

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\02\01@080118 by Spehro Pefhany

picon face
At 12:15 PM 2/1/2003 +0200, you wrote:
>Use linear interpolation between the lower values in the table. The user
>won't notice if the steps are close enough already. Note that a user who
>knows what he is looking for can discern 0.5% light changes in certain
>ranges (8bit da). Another way to remove the tick-tick-tick is to slow down
>the changes, either using external RLC elements or in software.

Allowing you to use a higher resolution PWM below the visual CFF frequency.


>Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
RemoveMEspeffTakeThisOuTspamspaminterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

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