Author Topic: Correcting LED PWM brightness curve using analog stuffs (no programming)  (Read 1803 times)

0 Members and 1 Guest are viewing this topic.

Offline K3mHtHTopic starter

  • Regular Contributor
  • *
  • Posts: 91
  • Country: ca
Hey guys,

I have a circuit where I'm using an LED to detect audio clipping. It's just a simple op-amp comparator set for my maximum Vpp level, and when that goes high it powers my clipping LED. So basically, the LED sees a PWM power signal at a frequency of the input that goes from 0% to 50% duty cycle representing no clipping to full-blown clipping.

The circuit "works", but the LED appears pretty much "full on" from about 10% PWM and up. I was really hoping the brightness of the LED would indicate how much clipping is happening and grow brighter accordingly.

If I was controlling this with a microcontroller, I know I could scale the PWM % accordingly to make the brightness appear linear.. but I want to do this just with old school analog stuffs.  I was thinking maybe this problem has been solved a bunch of times already in the last 30 years... anyone have any recommendations?


 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #1 on: February 04, 2020, 09:24:02 am »
You'd probably need to low pass filter the comparator output to get an analog control voltage, then run it through an OPAMP logarithmic anti-log amplifier, then convert back to PWM if you want to drive a high intensity LED, or even simply use an OPAMP voltage controlled current source to drive a relatively low current LED directly.   You may also want to add a pulse stretching circuit to increase the weighting of HF clipping in the LED response.

Although its almost certainly a well-solved problem, cheap MCUs with ADCs and PWM have been around for long enough for the analog domain solutions  to be very obsolete, so if you *MUST* go down the analog road, its probably going to be simplest to design and simulate an implementation from first principles that can actually be constructed from 'jellybean' parts in current production, rather than trying to obtain $$EXPEN$IVE$$ *Genuine* N.O.S. chips to implement some 'textbook' design or appnote from circa forty years ago.

Why anti-logarithmic? Well it approximates the inverse of the response of the human eye over a reasonable brightness range. See Fechner's law at: https://www.telescope-optics.net/eye_intensity_response.htm

Edit: Log amp corrected to antilog amp!
« Last Edit: February 06, 2020, 03:04:33 am by Ian.M »
 
The following users thanked this post: K3mHtH

Offline imacgreg

  • Contributor
  • Posts: 12
  • Country: us
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #2 on: February 04, 2020, 04:00:34 pm »
Forgive me if I am misinterpreting your post, but your description of "the LED sees a PWM power signal at a frequency of the input that goes from 0% to 50% duty cycle representing no clipping to full-blown clipping" is not what your circuit as described is doing.

Your circuit appears to be indicating on a every other waveform-cycle basis (assuming no full-wave rectification) the digital expression of isClipping or notClipping. There is no useful information regarding degree or amount of clipping. it is either above the comparator threshold or it isn't. Since low frequencies can tend to dominate audio amplitude, and perception of the human eye blurs on/off events faster than 20-30Hz, this can appear as if some kind of PWM/brightness modulation is happening.

To get any kind of controlled gradient, you need something more complex than a single comparator. In this case, a handful of comparators setup along a multiple resistor voltage divider string can be used to generate the various trip points for multiple LEDs.

For a single LED to accurately represent this by varying brightness, true PWM is one way to go. To perform this without a MCU is possible. If it were me, I'd full-wave rectify (and filter) the audio to get a DC representation of the level, then feed a traditional comparator with a triangle wave reference (classic PWM method). Here's a very basic description: https://www.quora.com/Why-do-we-use-a-comparator-in-PWM - from there, you can use the PWM (now modulated per peak audio level) to control LED brightness.

The above method ignores the logarithmic nature of audio/human hearing, but it could be sufficient for a clip indicator that gives a bit of a warning before full on clipping.
 
The following users thanked this post: K3mHtH

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7392
  • Country: nl
  • Current job: ATEX product design
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #3 on: February 04, 2020, 04:08:39 pm »

Human eye is weirdly wonderful.  And this changes with color.
 
The following users thanked this post: K3mHtH, Ian.M, tooki, schmitt trigger

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 2223
  • Country: mx
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #4 on: February 04, 2020, 04:41:50 pm »
An acquaintance of mine did something similar to what you are asking with a LM3916.

He clustered the LEDs in the smallest area possible, and placed a pair of light diffusers on top.
The apparent brightness change with sound level was readily noticeable.
 
The following users thanked this post: K3mHtH

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16621
  • Country: us
  • DavidH
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #5 on: February 04, 2020, 06:22:12 pm »
I might try simultaneously scaling the drive current with the duty cycle to create a correcting quadratic response.
 
The following users thanked this post: K3mHtH

Offline K3mHtHTopic starter

  • Regular Contributor
  • *
  • Posts: 91
  • Country: ca
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #6 on: February 04, 2020, 07:57:37 pm »
Forgive me if I am misinterpreting your post, but your description of "the LED sees a PWM power signal at a frequency of the input that goes from 0% to 50% duty cycle representing no clipping to full-blown clipping" is not what your circuit as described is doing.

Your circuit appears to be indicating on a every other waveform-cycle basis (assuming no full-wave rectification) the digital expression of isClipping or notClipping. There is no useful information regarding degree or amount of clipping. it is either above the comparator threshold or it isn't. Since low frequencies can tend to dominate audio amplitude, and perception of the human eye blurs on/off events faster than 20-30Hz, this can appear as if some kind of PWM/brightness modulation is happening.


You're totally right that the amount of clipping isn't being conveyed when a square wave is being driven into clipping, the LED will get 50% duty cycle right away and stay that way. But if the waveforms being clipped are triangles or sines, etc, then the duty cycle % out of the comparator increases with the clipping. But you're right, it's nothing reliable..


To get any kind of controlled gradient, you need something more complex than a single comparator. In this case, a handful of comparators setup along a multiple resistor voltage divider string can be used to generate the various trip points for multiple LEDs.

For a single LED to accurately represent this by varying brightness, true PWM is one way to go. To perform this without a MCU is possible. If it were me, I'd full-wave rectify (and filter) the audio to get a DC representation of the level, then feed a traditional comparator with a triangle wave reference (classic PWM method). Here's a very basic description: https://www.quora.com/Why-do-we-use-a-comparator-in-PWM - from there, you can use the PWM (now modulated per peak audio level) to control LED brightness.

The above method ignores the logarithmic nature of audio/human hearing, but it could be sufficient for a clip indicator that gives a bit of a warning before full on clipping.


Thank you, some good ideas to try there. The simplest seems to be adding a few more LED's at different trip points, will try that first. These are going to be small SMT LED's that are going under a light pipe, so I'd probably be able to fit 2 or even 4 LED's under it.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #7 on: February 06, 2020, 03:13:26 am »
I've put together a LTspice sim roughly based on my proposal from reply#1, with a peak detector and linear thresholding circuit instead of the comparator.  Its a mess of seven OPAMPs and 30 passives & diodes, but might be worth breadboarding to have a play with.  All the BAT54 diodes are to minmize the headroom required for low voltage operation with RRIO OPAMPS - you can use ordinary 1N4148 diodes and ordinary OPAMPs if you use min. +/-9V supplies, but will need to tweak R18 to set the max LED current with the anti-log amplifier (U6) railed.

The complexity gets worse if you need single supply operation or if you need to limit the max. LED current before the anti-log amplifier rails, and *MUCH* worse if you need PWM output.
« Last Edit: February 06, 2020, 04:39:42 am by Ian.M »
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #8 on: February 06, 2020, 04:08:36 am »
I played around with some ideas in the simulator as well.  Here's the best that I could come up with.  It would require just one IC (an open-collector comparator) and a handful of passives.

The LED would have only 4 discrete intensity levels so it isn't a analog response but may still look okay.  The resister values on the divider as well as the outputs could be tweaked to taste.  (I pretty much just made up their values.)

I generalized about the PWM voltage level and system voltage level.  (I just used 5V for each.)  How you would filter the PWM would depend on currently unknown factors but may be as simple as using a first-order filter.  (A resistor and a cap.)
 
The following users thanked this post: K3mHtH

Offline StuartA

  • Regular Contributor
  • *
  • Posts: 96
  • Country: gb
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #9 on: February 06, 2020, 07:28:33 am »
Something to be aware of is that the Velleman company do two kits for what they call LED VU-meters and I wonder if those could be used, probably with some level of modification, to explore your needs. The kit I have experience of costs just ~$8 https://www.velleman.eu/support/downloads/?code=MK115 the circuit is shown in the assembly manual. That has 5 LEDS, which are either off or full on depending on the sound level going in. Without knowing what your pulse duration or frequency is, it's hard to know how that would work with PWM signal.

Stu
« Last Edit: February 06, 2020, 07:39:56 am by StuartA »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #10 on: February 06, 2020, 03:41:41 pm »
And now a LTspice sim of a 5V single supply version of my clipping indicator.  It hasn't got a *LOT* more complex as I was able to kludge a -2.5V level shift into the anti-log amplifier stage.  I've also tweaked the response a bit to get a visible clipping indication closer to threshold.

Get single supply 5V capable quad true RRIO OPAMPs, and the eighth OPAMP can be used for the rail splitter.  Up to U5 output, signals are best plotted with respect to Com, rather than ground.
 
The following users thanked this post: K3mHtH

Offline K3mHtHTopic starter

  • Regular Contributor
  • *
  • Posts: 91
  • Country: ca
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #11 on: February 06, 2020, 06:19:50 pm »
I played around with some ideas in the simulator as well.  Here's the best that I could come up with.  It would require just one IC (an open-collector comparator) and a handful of passives.

The LED would have only 4 discrete intensity levels so it isn't a analog response but may still look okay.  The resister values on the divider as well as the outputs could be tweaked to taste.  (I pretty much just made up their values.)

I generalized about the PWM voltage level and system voltage level.  (I just used 5V for each.)  How you would filter the PWM would depend on currently unknown factors but may be as simple as using a first-order filter.  (A resistor and a cap.)

Thanks Jack, I tried something very similar actually but didn't like it in the end - since one LED shows the "onset of clipping" which makes sense, but the other 3 are just arbitrarily set so when they turn on they don't really indicate anything specific - just "and now a certain amount more clipping is happening". The original intention of the continuously variable brightness LED was just to roughly show how much clipping was happening, but showing it in discrete multiple stages didn't make sense in practice since the stages don't correspond to anything. I appreciate the schematic though, interesting that we both came up with similar ideas, and apologies if I'm being very picky about the behavior of an LED.

I did manage to get something I'm happy with by tweaking the value of the LED current limiting resistor at the op-amp output so that the changes to the PWM duty cycle make more noticeable brightness changes.
 
The following users thanked this post: TerminalJack505

Offline K3mHtHTopic starter

  • Regular Contributor
  • *
  • Posts: 91
  • Country: ca
Re: Correcting LED PWM brightness curve using analog stuffs (no programming)
« Reply #12 on: February 06, 2020, 06:26:02 pm »
And now a LTspice sim of a 5V single supply version of my clipping indicator.  It hasn't got a *LOT* more complex as I was able to kludge a -2.5V level shift into the anti-log amplifier stage.  I've also tweaked the response a bit to get a visible clipping indication closer to threshold.

Get single supply 5V capable quad true RRIO OPAMPs, and the eighth OPAMP can be used for the rail splitter.  Up to U5 output, signals are best plotted with respect to Com, rather than ground.

Wow thanks Ian, that's a very thorough solution! I'd like to breadboard it just to see how it behaves, but I think the parts count might be too high for my application and space requirements. I was initially hoping my problem would be solved by things like "oh, just put a cap across x" or "change the resistor to y" type things.

As I mentioned to Jack above, I ended up increasing the resistance of the LED current limiting resistor until the duty cycle made perceptible brightness changes. It's not the greatest, but seems to work. Thanks for your schematic and LTspice file though, lots for me to learn from it - especially that anti-log inverting amp - I didn't know about that configuration before!

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf