Author Topic: How would an LDR handle a PWM-driven LED?  (Read 7758 times)

David

How would an LDR handle a PWM-driven LED?
« on: July 09, 2007, 10:24:25 AM »
Here's one I don't think has come up here before...

I've been reading up on volume pedals, digital pots and the issues associated with them.  I've also been reading up on how to read a pot value from a microcontroller and changing the brightness of an LED using PWM.

What has not been answered to my satisfaction is this:  I'd like to digitally emulate the operation of a voltage-divider type pot.  I've figured out that you would do this with LED/LDR combos by brightening one LED and darkening the other LED by the same amount.  It appears this process is called "complementary PWM".  OK, I think I can figure out how to do this.  Will an LDR respond to a PWM-driven LED the same way it does to one being driven by an "analog" voltage?  Supposedly one of the advantages of using an LED/LDR combo in a compressor is the LDRs "lag" in response.  Would that work to make the LDR sort of "not see" the periods of LED darkness?

David

Re: How would an LDR handle a PWM-driven LED?
« Reply #1 on: July 09, 2007, 10:35:11 AM »
To add a little more fuel to the fire, you might ask, "why on earth would someone want to do this digitally?"

Here's why:  1)  No more pot scratch noise.  2)  No mixing of digital and audio signals  3)  Very few components

And finally, the number 1 reason:  Because I want to implement being able to push a button and have the microcontroller record the current value of the pot in its EEPROM and save it until the next time the button is pressed.  This value would then be used as a "reference" by the microcontroller for your "basic" volume level.  If you go below this reference, an LED goes out.  When you hit the reference, the LED lights.  If you had some pedal travel left over, you could get some volume "boost" by going above the "reference" value.  The pedal would thus remember where you had your volume set at practice so you wouldn't have to remember at the gig.

The Tone God

Re: How would an LDR handle a PWM-driven LED?
« Reply #2 on: July 09, 2007, 01:36:20 PM »
Will an LDR respond to a PWM-driven LED the same way it does to one being driven by an "analog" voltage?  Supposedly one of the advantages of using an LED/LDR combo in a compressor is the LDRs "lag" in response.  Would that work to make the LDR sort of "not see" the periods of LED darkness?

Yes an LDR will responded to a LED driven by a PWM signal. Some caveats include making sure you use the proper current limiting resistor, not sinking/sourcing more current then the I/O pin is rated for, and selecting an appropriate PWM frequency among other things.

You could use the slow response time of the LDR to cover up the PWM gaps depending in the frequency you chose but really all you need is a simple filter on each PWM output to smoothen out the voltage thus making this a non-issue to begin with. The filter could also do current limiting for the LED thus keeping part count down.

Andrew

David

Re: How would an LDR handle a PWM-driven LED?
« Reply #3 on: July 09, 2007, 02:30:52 PM »
Oh, TTG the Great and Terrible:   :icon_mrgreen:

Thank you for your response to my abject plea!  You, in your infinite wisdom, are the one who gave me this idea.  It's a feeble attempt to automate your Rock'n'Control and give it some memory.  GAAAK!  Am I a toad, or what ?!?!?!?

OK, Andrew, I'm going to come straight to the point.  I need a reliable, noise-free volume pedal, and it would be sweet indeed if I could electronically enhance it to record and remember my chosen "peak" volume.  If I didn't want the peak thing, I would have just built the RnC.  Your suggestions have been excellent and will be taken into account.  Have you ever tried any programmable "complementary PWM" project, or know of any?  I searched through Google and the Pic list for "complementary PWM", "volume control" and various other things before I posted here.

The Tone God

Re: How would an LDR handle a PWM-driven LED?
« Reply #4 on: July 09, 2007, 04:40:35 PM »
Have you ever tried any programmable "complementary PWM" project, or know of any?  I searched through Google and the Pic list for "complementary PWM", "volume control" and various other things before I posted here.

Yep. Its actually fairly easy. I'm an AVR guy and many of the newer AVRs have built in complementary PWM outputs so all you have to do is maintain one value and the hardware does the rest. They are often used as outputs to motor speed controllers. You could try to use two timers or even bit bang the outputs but really for the cost it is easier to grab a uC with the functions you need built in. For AVRs and size of the project the Tiny13 has these features.

As for the memory portion you can save the output in the on board EEPROM memory. It will stay there even when powered down. So a basic summary would be read pot value, update PWM output value based on pot value, when button is pushed save PWM value in EEPROM memory. How you want to retrieve it can also be decided meaning on power up or when a button is pushed.

Andrew

David

I smell a new project...
« Reply #5 on: July 12, 2007, 02:17:54 PM »
...  like I need something else to work on!   :icon_eek:

It occurs to me that I could simplify this tiger real quick if I dump the complementary PWM idea and just use one LED to regulate the resistance of an LDR.  That LDR will be part of the feedback loop in an inverting buffer or buffer/amp with a slight gain.  I could then put a second inverting buffer in front to ensure the signal is phased correctly when it comes out of the pedal.

Transmogrifox, this reminds me of something you might have been working on last year.  If you completed it, I don't want to steal your thunder or credit.  Heck, I'd prefer to leverage what you've done.  If you didn't complete it and my idea interests you, please PM me.  I'd be interested in your opinion.


The Tone God

Re: How would an LDR handle a PWM-driven LED?
« Reply #6 on: July 12, 2007, 03:34:01 PM »
Well the complimentary PWM is not that difficult to use if you using a uC that has the outputs already set up in hardware. You just deal with changing one number.

Heres another thought, if you only have one PWM output and the output can source and sink current then you can put a pair of LEDs in series with the uC output feeding the centre connection. If done properly the LEDs will remain in direct proportion to the duty cycle.

Andrew

David

Re: How would an LDR handle a PWM-driven LED?
« Reply #7 on: July 12, 2007, 04:17:02 PM »
Well the complimentary PWM is not that difficult to use if you using a uC that has the outputs already set up in hardware. You just deal with changing one number.

Heres another thought, if you only have one PWM output and the output can source and sink current then you can put a pair of LEDs in series with the uC output feeding the centre connection. If done properly the LEDs will remain in direct proportion to the duty cycle.

Andrew

Really?  Tell me more.  The examples I've seen force the LED pin low to turn it on.  OK, I get that.  But how can I source as well?

The Tone God

Re: How would an LDR handle a PWM-driven LED?
« Reply #8 on: July 12, 2007, 07:25:11 PM »
Really?  Tell me more.  The examples I've seen force the LED pin low to turn it on.  OK, I get that.  But how can I source as well?

I should have mentioned that you can use a PNP/NPN pair of transistors to drive each LED using the output to drive the transistors. I was little unclear with that.

Andrew

Kon_fución

Re: How would an LDR handle a PWM-driven LED?
« Reply #9 on: July 13, 2007, 11:17:44 AM »
I'm sorry for driving you guys out of your fun, but you seem to know about LDR's.
Maybe you can help me out telling me if this would work:
http://www.diystompboxes.com/smfforum/index.php?topic=59008.0
That's all,
Thanks.

David

Re: How would an LDR handle a PWM-driven LED?
« Reply #10 on: July 13, 2007, 01:57:30 PM »
I'm sorry for driving you guys out of your fun, but you seem to know about LDR's.
Maybe you can help me out telling me if this would work:
http://www.diystompboxes.com/smfforum/index.php?topic=59008.0
That's all,
Thanks.

Kon:

It looks like you just reinvented a Morley volume pedal.  Search here and on Google for Morley.
No DSP required.

A.S.P.

Re: How would an LDR handle a PWM-driven LED?
« Reply #11 on: July 13, 2007, 04:25:20 PM »
Well the complimentary PWM is not that difficult to use if you using a uC that has the outputs already set up in hardware. You just deal with changing one number.

Heres another thought, if you only have one PWM output and the output can source and sink current then you can put a pair of LEDs in series with the uC output feeding the centre connection. If done properly the LEDs will remain in direct proportion to the duty cycle.

Andrew

Really?  Tell me more.  The examples I've seen force the LED pin low to turn it on.  OK, I get that.  But how can I source as well?

http://www.diystompboxes.com/smfforum/index.php?topic=29374 ?
Analogue Signal Processing

David

Re: How would an LDR handle a PWM-driven LED?
« Reply #12 on: July 16, 2007, 08:42:38 AM »
Well the complimentary PWM is not that difficult to use if you using a uC that has the outputs already set up in hardware. You just deal with changing one number.

Heres another thought, if you only have one PWM output and the output can source and sink current then you can put a pair of LEDs in series with the uC output feeding the centre connection. If done properly the LEDs will remain in direct proportion to the duty cycle.

Andrew

Really?  Tell me more.  The examples I've seen force the LED pin low to turn it on.  OK, I get that.  But how can I source as well?

http://www.diystompboxes.com/smfforum/index.php?topic=29374 ?

That is EXTREMELY interesting!!  And I take it that you're saying I can just substitute my PWM output for the LFO?  That would be excellent.  What about the driver transistors?

The Tone God

Re: How would an LDR handle a PWM-driven LED?
« Reply #13 on: July 16, 2007, 01:46:51 PM »
To be honest the idea puretube posted was what I was thinking of when I posted the initial single pin suggestion but I worked away from it for a few reasons the major one being current limitations. Some older uCs cannot sink and source current so this would not work. Older uCs often can't handle much current usually between 5-10mA. Even most modern uC only handle 20mA which is on the edge of what many high brightness LEDs typical require. The transistor driver, which is basically the three pole RnC circuit replacing the pot with the uC, resolves these issue as most typical transistors people use around here can handle 100mA comfortably. That should suit most needs.

It is becoming harder to suggest a circuit design without more information on your part specifications. The transistor driver is a more "universal" solution IMHO.

Andrew

David

Re: How would an LDR handle a PWM-driven LED?
« Reply #14 on: July 16, 2007, 02:09:26 PM »
Got it.  Thank you.  I have the infrastructure set up to use PICs, so I need to stay with those for a while.  I'm familiar with the 16F628 and the 16F877.  I'm thinking the 877 is probably overkill for this application.  It appears that the 628 might be problematic as well since it looks like it can't do both ADC input and PWM output at the same time.  I've found, however, that the 16F88 appears to be able to do both those things, so I think I'll give that one a shot.  This is something I want to do for the experience, and because it might put a few more coding tools into the toolbox.  Many thanks for the RnC-based hardware suggestions.

BTW, this is something I'm doing only for me.  I don't plan to sell it.  I doubt anyone would want something so harebrained anyway.