Arduino Uno: PWM Output to DC Conversion Query

Thread Starter

rahulpsharma

Joined Sep 5, 2010
38
Hello,
I am looking forward to do the following:

1) Run a loop from 0 - 255 counts
2) Write each count value to an Analog Output Port of Arduino
3) Wait some time T before the next scan
4) Convert the PWM Analog Output to 'Smoother' DC Output using some RC Filter

Question:
I went thru an interesting article at http://www.thebox.myzen.co.uk/Tutorial/PWM.html

However, I have a query here regarding the filter design...!!

The design considers the frequency with which I am updating my output Analog PIN at Arduino (the scan time)...!! And the entire Filter Design is based on that info alone... Like how frequently, I wanna update the my output (Scan time T) and based on that the filter wud be made...!!

But my question is that apart from the frequency of updating the Analog Output pin of Arduino, there is ALSO the frequency of PWM itself...!! So does the frequency of PWM not play any role in considering the filter components?

Thanks in adv and regards
Rahul
 

trebla

Joined Jun 29, 2019
396
As i understood, in this article the filter design is targeting for smoothing the PWM pulse frequency, not the PWM duty changing frequency.
 

KeithWalker

Joined Jul 10, 2017
1,857
But my question is that apart from the frequency of updating the Analog Output pin of Arduino, there is ALSO the frequency of PWM itself...!! So does the frequency of PWM not play any role in considering the filter components?
In your loop you must be careful that the time between changing the value of the output pin is not short enough to interfere with the period of the PWM signal.
In answer to your question, the frequency of a PWM signal is the main factor to consider when designing a smoothing filter for it.
In your case, the time between your stepped ramps will not be a factor in the design of the filter.
 

BobTPH

Joined Jun 5, 2013
3,506
I don’t know about Arduino, but on PIC the duty cycle is double buffered and when you write to it, the new value takes effect only after the current cycle us finished.

Bob
 

KeithWalker

Joined Jul 10, 2017
1,857
I don’t know about Arduino, but on PIC the duty cycle is double buffered and when you write to it, the new value takes effect only after the current cycle us finished.

Bob
The arduino handles the pwm value update in a similar way. If it is changed too rapidly, values will be ignored. In the case being discussed, the ramp will then become irregular and non-linear.
 

crutschow

Joined Mar 14, 2008
27,472
Yes, you need to consider the PWM frequency and how often the duty-cycle is changed.

So what is the PWM frequency, and how long between the changing of the PWM duty-cycle?
How much ripple in the DC output can you tolerate?
 

Thread Starter

rahulpsharma

Joined Sep 5, 2010
38
As i understood, in this article the filter design is targeting for smoothing the PWM pulse frequency, not the PWM duty changing frequency.
I am so glad I asked...!! Just didn't know I was completely adrift in my understanding...!!

I took cue from the following statement in the second Para on 'Simple Filter Design' in the above article ( PWM (myzen.co.uk) ) which said:
"So in practice, one way to design a filter is to decide on how rapidly you want to change the analogue output, then set the cut off frequency to be four times this rate."

That was the basis for my assumption that the filter design proposed in the article is for the frequency of updating my Analog Output and NOT the PWM freq. per se...!! And hence the original question...!!

I am tempted to dwell a little further on this and submit that I chose 100K and 10nF capacitor values... Did not consider PWM freq. at all...!! Just considered that the Microprocessor code would be scanning the loop 4 times a second...!! And hence updating the output pin (Input to the RC Filter) four times a second...!! With a hope of getting a cut off freq. around 16 Hz...!! Also, simultaneously hoping to convert the PWM to 'smoother' DC in the process...!!

This 'smoothened' DC is fed to a unity gain buffer and finally a Voltage to Current Converter Ckt. that feeds 4 - 20mA to an I/P Converter (Current to Pneumatic Converter) which in turn opens and closes a Control Valve...!!

So in this scheme of things, I just wanted to know if my filter ckt is doing the job it was chosen to do OR its just working cos the values chosen 'accidentally' somehow meets the requirements...!!

Thank you all and regards
Rahul
 

BobTPH

Joined Jun 5, 2013
3,506
That is the correct frequency to use to get the a nice smooth ramp.

The cutoff frequency is a tradeoff between response tine and ripple. The frequency should be high enough to allow the signal to just settle between changes and low enough to not have be jerked around by each PWM cycle.

Bob
 

Thread Starter

rahulpsharma

Joined Sep 5, 2010
38
That is the correct frequency to use to get the a nice smooth ramp.

The cutoff frequency is a tradeoff between response tine and ripple. The frequency should be high enough to allow the signal to just settle between changes and low enough to not have be jerked around by each PWM cycle.

Bob
I was just wondering what is the maximum scan rate I can, therefore, choose for my loop...!! Currently its 250ms and everything seems working well...!!

But shud I wish to increase the scan rate (loop around faster and faster), at what value would I eventually hit a roadblock...!!

The RC Filter has values 100K & 10pF respectively...!!

Default PWM Freq is 490 Hz...

Thanks and Regards
Rahul
 

KeithWalker

Joined Jul 10, 2017
1,857
I was just wondering what is the maximum scan rate I can, therefore, choose for my loop...!! Currently its 250ms and everything seems working well...!!

But shud I wish to increase the scan rate (loop around faster and faster), at what value would I eventually hit a roadblock...!!

The RC Filter has values 100K & 10pF respectively...!!

Default PWM Freq is 490 Hz...

Thanks and Regards
Rahul
With a PWM frequency of 490Hz, each modulated pulse is a little longer than 2mS (wavelength = 1/frequency). To get a smooth ramp-up with full resolution, the maximum rate you can update the PWM value is once every pulse length plus a very small safety margin.
You can change the frequency of the PWM by changing values in the PWM register. If you do, you must change the smoothing filter to match the new frequency.
https://www.electronicwings.com/use...frequency-changing-of-pwm-pins-of-arduino-uno
 

BobTPH

Joined Jun 5, 2013
3,506
I took the TS’s word that 100K and 10 nF is a cutoff if 16Hz, turns out he is off by a factor if 10.

A 160 Hz cutoff will not be optimal for a 4Hz update rate. Unless a staircase with a lot of ripple is what he wants.

Bob
 
Top