[solved] PWM and capacitor charge concept .

so in class we were going through the differential equations for capacitors , so that got me thinking about the way PWM signals turn into voltage when passed though a capacitor and a resistor (RC) .

so the concept seems to be based on the fact that the charge of the capacitor evolves following an exponential function , so the voltage of the capacitor on charge is U=E(1-e^(-t/RC)) with U being the voltage , t time , R for the resistor and the capacity C , and for discharge E/R (e^(-t/RC)) .

the thing is the discharge is almost always faster than the discharge in the small time intervals of PWM . so at some point when you set the PWM , the voltage would slowly elevate over time to a point where the charge and discharge times are nearly equal then you get a steady voltage over time , the thing is , the elevation of voltage over time is relatively slow , and when you send a byte 0->255 to PWM it is difficult to approximate the exact voltage you are getting , and since the charge and discharge processes follow an exponential pattern not a line the values must not also be proportional , so if you give 20 then 40 , 40 should not give you anything around double the voltage you cannot pretty much know .

so why not get the signal on the pin straight to 5v and then calculate the needed time for the capacitor to get to the needed voltage , and then give a high frequency that should just maintain the voltage at that level ?? and can this even be done ? ?

thank you

Can you try that again with proper punctuation? Hard to follow one big long run on sentence.

CrossRoads:
Can you try that again with proper punctuation? Hard to follow one big long run on sentence.

what about now

amine2:
so why not get the signal on the pin straight to 5v and then calculate the needed time for the capacitor to get to the needed voltage

Because, for one thing, you don't know what voltage exists on the capacitor at the beginning. You would have to set it to zero. How would you do that?

aarg:
Because, for one thing, you don't know what voltage exists on the capacitor at the beginning. You would have to set it to zero. How would you do that?

drain it :slight_smile: at first , set the pin low and wait for a small amount of time , it should discharge to 0 . and when you charge it to a certain voltage record the current voltage , then when you calculate the time in the next phase use the current voltage in the calculations .

the thing is the discharge is almost always faster than the discharge in the small time intervals of PWM .

The charge & discharge times are the same (your math should confirm that) unless there is a diode* or unless the drive circuit is not symmetrical (these are things things can change the effective resistance depending on current direction).

If you have a large RC time constant (if either the resistance and/or the the capacitance is large enough) so the voltage changes slowly relative to the PWM frequency) you should get a DC voltage across the capacitor that's EXACTLY equal to the average PWM voltage.

If the PWM is not sufficiently filtered (if the RC time constant is too small), a digital multimeter may not measure the average voltage accurately, but the average is the same with or without the RC circuit.

  • A power supply is an example of that. Rectified AC charges a filter capacitor to approximately the peak voltage with very low source resistance. The higher resistance load discharges the capacitor more slowly than it charges and you get a DC voltage approximately 1.4 times AC RMS voltage.

the charge and discharge rates are not the same :slight_smile: , the time of a full charge or a time of a full discharge are the same though approx 5*RC , when i said the discharge is faster i ment that it's faster in the small periods of the PWM , you will not get a full charge of discharge there but you will get a charge by some amount and a discharge by an other RC must be relatively high though , you should not have a Cap that would fully charge or discharge in a single clock time .

the dischrage or charge rate that is dU/dt with U being the voltage of the capacitor decreases over time for both the discharge and charge process , so if the voltage is higher the rate of charge decreases though the rate of the discharge increases .

I don't know how to tell you this but this a "General Electronics" Topic, not a class in Differential Equations. If you have questions like that , I suggest you do what any other normal student would do and stay after class and ask your professor. Please don't clutter up this topic with an inane discussion about something that has absolutely nothing to do with anything any one else is doing and in general is a distraction, not a plus for the forum.
If you want a dc steady state voltage, get a DAC. That is the proper way to do that. RC LPFs are fine when the circuit requirements are not that stringent. Trying to get DAC performance out of an RC LPF is not the purpose of this topic.

Please don't clutter up this topic with an inane discussion about something that has absolutely nothing to do with anything any one else is doing and in general is a distraction

Differential equations are an enormous part of engineering, very very important

To say it has nothing to do with anything is ignorance, have a look at a software filter for example its a first order differential equation in its most simple form and the number of applications of differential equations is staggering

It must be nice working in the world of pure Ohms law, the real world is much more complicated and the OP is showing an interest in a very important area, an area that can put you up a level or two if you get a handle on it, it really opens doors and makes lots of things drop into place, shame on you for trying to limit discussions because its above you (is what you said yourself)

To the OP

A simple filter fed by PWM requires a fourier transform to decompose the pulses into its individual components, the filter attenuates the frequencies according to the bode plot and you sum up the attenuated voltages hence its quite involved and you would use Matlab or whatever

shame on you for trying to limit discussions because its above you (is what you said yourself)

And this has what to do with General Electronics ? You understand the meaning of the word "General" ? Does Differential Equations sound like "General Electronics" or does it sound more like
Engineering ?

As I said, the OP should be asking his professor, not a General Electronics forum on an arduino website. I don't see any benefit in this discussion. If you do, then answer the OP's question and post your math. Otherwise, I don't see how it helps anyone else on this forum. If you do, show how this post can benefit others. I can't wait.

A simple filter fed by PWM requires a fourier transform to decompose the pulses into its individual components, the filter attenuates the frequencies according to the bode plot and you sum up the attenuated voltages hence its quite involved and you would use Matlab or whatever

Is this a theoretical discussion ?

Maybe you should look at this link.

Do you see any other threads in this topic about Differential Equations ?

and can this even be done ? ?

or is it a post requesting help to obtain a DAC quality voltage from a PWM'd RC LPF ?

Get a DAC and stop wasting our time.

raschemmel:
And this has what to do with General Electronics ? You understand the meaning of the word "General" ? Does Differential Equations sound like "General Electronics" or does it sound more like
Engineering ?

In my view this is general electronics. It would probably be taught in the first term of an electronics or electronic engineering degree course.

Nobody would suggest that Ohm's law calculation for resistors should be excluded from this forum, so why attempt to ban calculations involving capacitors?

Using equations derived from differential equations are very relevant to the PWM output from an Arduino. For a particular CR time constant, you can work out the peak-to-peak 'ripple' and work out (or at least estimate) how quickly the output voltage will change after a change in PWM mark-space-ratio. That enables you to choose a CR time constant suitable for your application or points towards the need for a higher order filter or use of a digital-to-analogue convertor (DAC).

The issue here is in the original post:

amine2:
. . . . . . so the concept seems to be based on the fact that the charge of the capacitor evolves following an exponential function , so the voltage of the capacitor on charge is U=E(1-e^(-t/RC)) with U being the voltage , t time , R for the resistor and the capacity C , and for discharge E/R (e^(-t/RC)) .

E/R (e^(-t/RC)) is an expression for the current in the capacitor-resistor circuit, not the discharge voltage.

In my view this is general electronics. It would probably be taught in the first term of an electronics or electronic engineering degree course.

I think it was the second year at DeVry Institute BS Electronics Engineering Technology course I took (and passed). I think Laplace Transforms was also the second year.

Ok fine. Let the calculations begin. So far , I haven't seen any and this post isn't proceeding toward that end yet. You are the first to get the ball rolling. Let's see how far it goes to achieving the OP's objective.
I withhold any further comment.

Hi,
amine2, good to see a student who doesn't put the books away till the next class.
What you are extrapolating to is the concept of a Switch Mode Power Supply.

Tom..... :slight_smile:

raschemmel:
And this has what to do with General Electronics ? You understand the meaning of the word "General" ? Does Differential Equations sound like "General Electronics" or does it sound more like
Engineering ?

What on earth are you wittering on about? Electronics is all about differential equations and their
properties, any circuit with a C, and L or a filter in it is the embodiment of differential equations.

This is absolutely an on-topic posting - please stop being nasty to people.

I'm not being nasty. I've never seen any differential equations in this topic. Despite all the hype and protesting there is not one equation or calculation added to this thread since the original post. My point is that there is nothing to be gained by a lot of bru ha ha about the right to post differential equations if no one is going to actually do it. What have we accomplished so far in this post ? What progress have we made toward answering the OP's post ? So maybe everyone feels good about bashing me for complaining but "you guys" are all talk and no action. I would love to learn how to design a switch-mode power supply . Really I would. But I don't see that happening here and all the "wittering" is being done complaining about me and not delivering anything useful to the OP or the forum. If Differential Equations are so great , prove it. Post some that solves the OP's post. Bashing me without delivering results is pointless. Teach me Differential Equations. I said this post was a waste of time. So far it has been. Prove me wrong.

Let the calculations begin ...

I stand by my original statement that the appropriate venue for the OP's question is the Professor's class or office. That's where the question began. That's where it should end.

Thank you very much Resinator , thanks alot Archibald :slight_smile: , TOM thank you very much sir :slight_smile: , and thank you Mark , raschemmel i appreciate the attention thank you .

so i did do some more research on this and yes it is possible when you would be running at a very high clock speed . now if you want to know the exact voltage you are getting out of your PWM signal running through the filter , after some time i got to this interesting formula . it looks long and nasty , but you can use any online solver and it will give you the result right away just put the values you are using .

here is it :

T = - RCln((1-(e^(-d/RC)))/(1-(e^((-d-b)/RC))))

with T being the imaginary charging time , so the approximate voltage that you will get should be if i did
not miss calculate anything in the formula : Uout = E(1-(e^(-T/RC)))
Uout = around approximate output voltage (V unit)

with R = resistance of the resistor (Ohm)
C = capacity of the capacitor (Farad)
d = low period of PWM (in seconds)
b = high period of PWM (in seconds)
E = 5v = 5

here , you can get a better view of it :

i might've done a miss calculation though , please alert me if i did .
and yes , this can be done with the right programming . i will attempt to do this and i will post it in the forum for a general benefit .

thank you guys very much :slight_smile:
(SOLVED)

Please show your work.

if you want to know the exact voltage you are getting out of your PWM signal running through the filter

Can you post a solved example (ie: with actual voltage @ some frequency) ?
(With the numbers )
After all that, it would be nice to see the actual value for some frequency/duty cycle

I'm not being nasty

You really don't know your doing it do you?, its not just this thread dude

If you think its has nothing to do with anything then I don't understand why you feel the need to post in the thread at all?

Despite all the hype and protesting there is not one equation or calculation added to this thread since the original post

You really don't know what differential equations are!, it takes pen and paper time and hard work, you don't read the solution on the net and thats that you actually have to solve it yourself so that you experience it

I find that maths is like a game, its like the ultimate game with lots of ruules and challenges and you have to play the game to learn because spectating doesn't cover it like it does for many other things

The major thing about differential equations is learning to recognise them to see which technique you can apply, it requires pen and paper time

What have we accomplished so far in this post ? What progress have we made toward answering the OP's post

The OP is clearly very enthusiastic who is thinking about stuff!, this is an excellent trait. I think you should reread the thread, we have established that fourier series (calculus) would be required to decompose the supply voltage into its components and the bodeplot can be used to calculate the attenuation and the components summed (superposition, ie calculus) and that this is an exercise for a computer, Matlab, excel even a C program are ideal

I would love to learn how to design a switch-mode power supply . Really I would. But I don't see that happening here

I have built a number of inverters over the last few years, AC output is my area of interest and with my bare hands from scratch. I have built maybe 10 mains powered versions, 230VAC output and it all started here with an Arduino for my low voltage version

To build a mains powered inverter takes some doing and it took me a long time to get there. I had to go with an ARM when my programming skills were limited but I like AVR's and I have done all sorts, 20kHz switchinng with LCD displays, SPI and analogue inputs is a lot to ask of an ATMega328 clocked at 8MHz!

I must be honest Rasch but your attitude on the boards hasn't been very good for quite some time and its put me off posting on these boards because it was as if it went unchecked and no one cared. IMO it brought the forum down

To learn how to build switching converters requires you to learn how to make well designed PCB's otherwise you are wasting your time, the parasitics kill you

This simple thing with having to learn some software package puts lots of people off and I think its disgraceful how many electrical engineers have never etched a PCB, its a good skill to have

Designing a PCB to minimise parasitics is challenging when you only have two layers but its doable

With an attitude of writing off whole branches of knowledge you won't ever get anywhere the amount of times that I have seen you bash someone about upping their game and yet you don't seem to want to up your own, electronics is an enormous subject and no one knows everything I honestly know the skills you need to gain in order to achieve what you claim you would LOVE to do but I think you wouldn't want to hear it

Teach me Differential Equations

You have to teach yourself but if you really mean that I can show you the water you need to drink, if you look at the OP's solution then would you really want to know how to arrive there? (without Laplace)

Its about one page of A4 paper, maybe two

Integration is the mathematical term for solving your problem.

There are lots of solutions for your problem when you google " OPAMP integration".

Combine such a circuit with an ADC (analog to digital converter) and you will have what you need.