PWM to analog... is this just too Rube Goldberg?

PWM driven led coupled with a 'slow' photocell?

Why not just PWM into an RC filter?

I'm not that good? Would it require much more than a cap or two and resistors?

GoForSmoke:
I'm not that good? Would it require much more than a cap or two and resistors?

One cap, one resistor, but after that it depends on what you are wiring the then true analog voltage too. If it requires any significant current then you need to add a buffering amp or other method to supply the 'load current'.

Lefty

Depending what you are driving, a cap to gnd can be enough to turn pwm into analog.

If you want a true analog though, use a cap and resistor into an op-amp set up for voltage following, this will avoid all feedback errors from the load.

Thanks guys. This is partly an in-general thing and partly there's sound oscillator circuits in an old electronics kit cookbook and I'm thinking of ways to control a resistor (besides a manual pot which is what the old cookbook has) to change the tone.
After that I might want to futz with the cap to see what that effect that might have.

I don't always like square-wave sound. And yeah, for you I'm still taking the wrong train, right?

You are not going to get much audio through a slow photo cell. By that I assume you mean a light dependent resistor.
See this for discussion of filtering a PWM signal:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html

If I can change a resistor then I control the tone of an independently operating sound oscillator circuit.

I was thinking of replacing a resistor with a cadmium cell or like then PWM a led on that. But as you guru's point out, a simple to less simple filter will flatten PWM output better for less.

By doing a Google search I found this interesting article which discusses some solutions:

Because I like burning money and like ladyada too I would probably do something like buy this product from her if it was available. It should be back in stock soon.

or maybe

IIRC vanilla PWM is 490 Hz variable width pulse, or is it closer to 500 Hz?
Couldn't the same low-pass filter work for 0-100 PWM?

GoForSmoke:
IIRC vanilla PWM is 490 Hz variable width pulse, or is it closer to 500 Hz?
Couldn't the same low-pass filter work for 0-100 PWM?

Depends on the -3db corner frequency of the specific R/C filter used. Lowering the switching frequency would normally call for lowering the cornering frequency of the filter. A given low pass filter will contiune to perform as designed as you raise the pwm switching frequency, but might require adjustment as you lower the switching frequency.

Lefty

Yes but vanilla Arduino PWM has a default full cycle that doesn't change the clocks. It should be fast enough.

But as I read, how fast I want to change the PWM -level- (assuming like 10% duty cycle to 90%) is more the deal?

RC = 1/2piF
F = 1/2piRC

Does this frequency limit how smoothly DC output will change as PWM level changes?
If so, that would be the smoothness the audio circuit the filtered PWM could change frequency as well as how fast I could jump from one note to another.

GoForSmoke:
Yes but vanilla Arduino PWM has a default full cycle that doesn't change the clocks. It should be fast enough.

But as I read, how fast I want to change the PWM -level- (assuming like 10% duty cycle to 90%) is more the deal?

RC = 1/2piF
F = 1/2piRC

Does this frequency limit how smoothly DC output will change as PWM level changes?
If so, that would be the smoothness the audio circuit the filtered PWM could change frequency as well as how fast I could jump from one note to another.

Filtering of a pwm output to generate a variable true analog DC voltage level is certainly a viable solution for some applications. But trying to generate variable audio frequencies via PWM output is just not a very practical solution in my mind. And it's not about the ability of filtering out the basic PWM switching frequency, but rather how to encode the audio frequency into PWM duty cycle values that have to change constantly with time even at a fixed audio frequency, it makes my head hurt trying to visualize that coding task. A 8 bit AVR chip is not the best candidate for want of a sine wave DDS generator.

Lefty

retrolefty:
But trying to generate variable audio frequencies via PWM output is just not a very practical solution in my mind.

I don't want to generate the frequencies. I want to influence what frequency an audio generator creates and I'd like to be able to slide the tone up and down quickly, dig?

I'd like to control volume too, ADSR kind of thing.

I play guitar so that helps me understand what you are getting at. You've got some sort of voltage-controlled analog effect box circuit that you'd like to put under digital Arduino control by using PWM and an R/C filter to generate the control voltage for the effect. I've thought of that before, and it would seem to be fine in theory (if your circuit is happy with 0-5V for your analog control, and doesn't take too much current); otherwise as mentioned you'll want an op amp to get a different range.

emdee:
I play guitar so that helps me understand what you are getting at. You've got some sort of voltage-controlled analog effect box circuit that you'd like to put under digital Arduino control by using PWM and an R/C filter to generate the control voltage for the effect. I've thought of that before, and it would seem to be fine in theory (if your circuit is happy with 0-5V for your analog control, and doesn't take too much current); otherwise as mentioned you'll want an op amp to get a different range.

Yes, certainly that is a viable application. And even the 0-5 vdc restriction is easy to overcome with simple op-amp with the gain set to whatever DC voltage range desired after the R/C filtering is done.

Lefty

It's a simple oscillator circuit I have to re-dig-up. It used a resistor and capacitor and a pot to control the tone, could have added volume control. I could replace the pot with a transistor couldn't I? As a valve?

Finished reading the Simple filter piece.

Increase in C lowers both Xc and F,
Increase in F lowers Xc and RC

And I think that making Xc small compared to R is desired.
So that lets low frequencies pass hence the moniker.

Suppose I want to change the duty cycle of the PWM from 10% to 90% smoothly in 1/100th or 1/1000th of a second? Would this filter have trouble following that? Again: the audio frequency is generated on a different circuit, not the PWM frequency being converted to analog DC to control a transistor.

GoForSmoke:
PWM driven led coupled with a 'slow' photocell?

THANK YOU! You made my day!

If you want to use PWM for clean audio, I suggest you reprogram the registers to crank the PWM frequency up. It will make filtering ALOT easier while keeping the audio intact.

TCCR1B = TCCR1B & 0b11111000 | 2;[/quote]
Will bring the PWM frequency on pins 9 and 10 to about 3.9KHz.

smeezekitty:
If you want to use PWM for clean audio, I suggest you reprogram the registers to crank the PWM frequency up. It will make filtering ALOT easier while keeping the audio intact.

TCCR1B = TCCR1B & 0b11111000 | 2;[/quote]

Will bring the PWM frequency on pins 9 and 10 to about 3.9KHz.

I have an AC oscillator making the wave. Not using PWM frequency for the wave. Wanting to use PWM to affect the external sound circuit in two ways, maybe find a third.

It's like being able to control the slide of a trombone when something -else- vibrates the air.
I'm trying to control the slide with PWM, not vibrate the air, move the bow not be the string.
And I wonder how fast I'll be able to move the bow smoothly.