Pages: [1] 2   Go Down
Author Topic: PWM to analog... is this just too Rube Goldberg?  (Read 1108 times)
0 Members and 1 Guest are viewing this topic.
Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PWM driven led coupled with a 'slow' photocell?


Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 538
Posts: 27071
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not just PWM into an RC filter?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

London, England
Offline Offline
Newbie
*
Karma: 1
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34129
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Show Your Work
Offline Offline
Edison Member
*
Karma: 14
Posts: 1098
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://embeddednewbie.blogspot.com/2011/02/review-of-arduino-dac-solutions.html

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.

https://www.adafruit.com/products/935

or maybe

https://www.sparkfun.com/products/8736
Logged

I have only come here seeking knowledge. Things they would not teach me of in college.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Quote
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.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Quote
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
« Last Edit: February 01, 2013, 06:48:44 pm by retrolefty » Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.

« Last Edit: February 01, 2013, 10:11:37 pm by GoForSmoke » Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2   Go Up
Jump to: