Need Equation for PWM

Hi,

I'm not a math or electronics genius but I was wondering if anyone could provide an equation that gives amplitude (voltage) as a function of time and duty cycle for a square wave:

symbolically:

A (V) = f(t (sec),duty cycle (%))

perhaps also the function would include something about the initial phase (phi)......

A simple equation that just gave back 1 or 0, as a function of time and duty cycle would work good too....I presume any answer would involve a trig function someway....

I have already tried searching the web for the answer and the closest I found was this link:

formatting link
However, I'm not sure exactly how LaPlace transforms figure into it, or if any of these are usable equations for what I'm looking for.

Please help....if you can.

Thank you.

Reply to
jack
Loading thread data ...

Google on "Fourier series" plus "square wave". Here's a nice piece from Addison-Wesley:

formatting link
you're into electronics, you might want to study the use of the Laplace transform in solving second-order ordinary differential equations. It is especially handy when the equation contains a discontinuous "forcing term", which it frequently does in electronics. LH

Reply to
Larry Hammick

I assume you mean: Vave = VpD the average voltage equals the peak voltage times the duty cycle. The duty cycle, D = Ton/(Ton + Toff) = Ton/(period) = f Ton. The RMS voltage is more complicated. Bob

Reply to
Bob Eldred

in article snipped-for-privacy@z14g2000cwz.googlegroups.com, jack at snipped-for-privacy@yahoo.com wrote on 4/11/05 5:40 PM:

I am not quite sure what your question is. The terms *step function* and

*Heavyside function* are sometimes used to represent pulses. Such a function is merely H(t)=1 for t>0 and 0 for t
Reply to
Repeating Rifle

Thank you very much for your reply.....but, it didn't anwser my question....

I did the Google search you suggested and I came on this site:

formatting link
At first glance, this website seems to answer my query but upon further inspection it is not any good.

First, EXCEL has a problem raising negative numbers (in this case -1) to a fractional exponent. So the first equation is no good.

Secondly, it does allow for varied duty cycle.

Thirdly, the other 2 formulas are not conducive to inclusion in EXCEL......

Also, any "Fourier series" solution to my problem is also not conducive to EXCEL since it requires summation of an infinite series.....

Also, I really don't care about the LaPlace transform of the equation I'm looking for, just the actual equation itself.....

Reply to
jack

No...I'm not talking about sine waves but square waves....also, I'm not talking about Vave but Vinst (e.g.. +1 and -1, or Vhi and Vlo or Vhi and 0)...I want to know what Vinst is at any time (time) for a given frequency/period, amplitude and duty cycle.....

see the links I mentioned to get a better idea.

thank you...

Reply to
jack

without using conditional statements (like "IF"), how would you write a formula in EXCEL (or a formula that could be translated into EXCEL) that would give you amplitude (e.g. 1 or -1) at a particular value of x (or time) for a particular frequency/period, and dudty cycle? In other words, a formula showing amplitude as a funtion of time, frequency, and duty cycle....???

Reply to
jack

Jack,

The 'formula' for a PWM square wave is exactly what you think it ought to be; something like:

T=period p=percentage 'on' time t=current time O=output

Set t'=t mod T (this gets the time into the current period) Set O=1 if t'>=p*T else set O=0

Although this notation wouldn't please a mathematician, it can be 'prettied up' such that it if perfectly legitimate. Excel knows the modulus operator and if/then/else operators if you want to implement it.

The stuff about Fourier transforms relates to taking a square wave and expressing it as a sum of some other set of 'fundamental' (aka, 'basis') functions; sines and cosines turn out to be particularly useful in this endeavor, but you can typically express any function as some (often infinite) sum of some other set of basis functions so long as those basis functions have certain special properties (e.g., if you like, you can express sine in terms of bunch of square wave-like functions). There's lot of math behind this that you can dig up if you're so inclined.

Here's a good web page with examples:

formatting link
Note the equation at the bottom of the page -- you could use that summation using, e.g., the first 5 terms and then checking to see if the result is greater than or less than 0, but this is a lot more effort than just using the definition of a PWM square wave directly.

---Joel Kolstad

Reply to
Joel Kolstad

What don't you like about IF/THEN/ELSE?

In your case, you can cheat a little and use various rounding functions such as TRUNC or perhaps CEILING/FLOOR... but realize that all you're doing is shifting the conditional statement to being 'hidden' (Excel does it internally) rather than your doing it explicitly.

There is no finite series closed-form expression in terms of "familiar" functions that I'm aware of for a square wave. Even if you have an infinite number of terms, there's still an error in the approximation of ~9%, if I recall correctly, due to something called the Gibbs phoenomenom. You might be able to remove it with another infinite series that represents an ideal brick wall filter, however, but this is really starting to get silly...

In signals and systems work, it's common to get around most of these functions by _defining_ a function called, e.g., "rect" that defines a single rectangular pulse of a given duration.

---Joel Kolstad

Reply to
Joel Kolstad

Thank you for your response...

Here's my retort:

Hard to explain, but basically I want to do further operations on the equation which makes the use of IF/THEN/ELSE problematic...

"familiar"

See Formula 1 of the following link:

formatting link
Problems with this formula are 1.) that EXCEL will not allow (-1) to be raised to a fractional exponent and 2.) duty cycle is not accounted for...

Reply to
jack

I've read everybodies repy and your answers to them and clearly you don't know what you are asking for and neither do we. If you don't know what you are asking, why are you asking it? PWM signals are used to drive motors, vary voltages, powers or currents in power supplies, class D amplifiers, motor controllers and the like. The relationships I gave you above are what you need if you are working on a power supply or amplifier and want to relate the output to the duty cycle. You responded with some quip about sine waves? Clearly you don't understand what I told you and I have no clue what you are asking. Instead of chasing URL's, try to state your problem in english, maybe we can help. The URL you refer to is highly mathematical and forms the underlying basis for harmonic cancellation to suppress harmonics from PWM signals.Is this what you want to put into practice? It seems like a big jump from your original question. Bob

Reply to
Bob Eldred

O.K., fair enough....let me respond by point:

Simply stated, I want a mathematical equation which shows voltage/amplitude of a square wave (+1 or -1) as a function of time, frequency/period, and duty cycle. However, this equation must be "neat" - no conditional statements (like "IF"), or piecewise statements (like Heaviside), or infinite series (like Fourier). The desire for a "neat" equation is for easy incorporating and manipulating in EXCEL.

If this is not clear enough, then please let me know.

My "quip" about sine waves was in response to your misinterpreting my question as referring to RMS/sine waves as opposed to square waves. You had stated:

Here is my "quip" back to you, making it clear I was talking about square waves, not sine waves...I was not confounding the issue, just clearing it up:

I think I do on both accounts. You had responded to me using the concepts of RMS, sine waves, and Vave, whereas I am interested in square waves and Vinst. I think the record shows your reply was off-target, albeit well-intentioned.

See above.

Here is the URL again:

formatting link
I agree this URL eventually becomes "highly mathematical" but Eaquation

1 is not. Do you believe Equation 1 is "highly mathematical"? If so, how so? As previously stated, the formula would work great if 1.) EXCEL allowed rasing a negative number to a fractional exponent and 2.) duty cycle was included.
Reply to
jack

Hi Jack,

OK...

OK, equation (1) is certainly simple enough. :-) Equation (2) is probably your best bet for implementation in Excel; it has the "signum" functin (SIGN).

With equation (2), let's see... you could account for duty cycling by subtracting two sine waves that are out of phase with one another and taking the SIGN of the result. The amount that they're out of phase will determine the duty cycle (albeit non-linearly) -- 0 degrees out of phase is 0% PWM,

180 degrees out of phase is 100% PWM.

---Joel

Reply to
Joel Kolstad

Thank you for your response.

You're right that equation 2 will "work" in EXCEL although it is still not really mathematically "pure" or very "elegant".

However, I challenge you to try to get Equation 1 to work in EXCEL. Raising a negative number to a fractional exponent causes an error in EXCEL. Try it. I agree Equation 1 would be great if it worked in EXCEL. :-(

Reply to
jack

Think this may be what you are after:-

Vinst=INT((duty cycle)/((Freq x time-INT(freq x time))))

duty cycle is as a fraction. time is from phase angle of 0 degrees assuming cycle starts as a '1'

This seems to work ok in excel.

Tom

Reply to
Tom R

I read in sci.electronics.design that jack wrote (in ) about 'Need Equation for PWM', on Tue, 12 Apr 2005:

A negative number to a fractional exponent is a complex number. Excel

2003 understands them, but I've never used that feature. Earlier versions (e.g. Excel 97) didn't understand them.

I think it is irresponsible to allow accountants to use a spreadsheet that can cope with imaginary numbers. (;-)

Reply to
John Woodgate

Hi Jack,

I suppose that's in the eye of the beholder?

Yeah, I see that you're right. This isn't too surprising, though, in that typically raising negative numbers to fractional exponents ends up with an imaginary result, and Excel doesn't support complex numbers 'natively' (it can be done with them with the Analysis ToolPak, but it's still a little clunky). In fact, looking at equation (1) on the MathWorld site, I believe you have to look strictly at the real part of the result to get the output (the square wave) that you're after (and just discard the imaginary part).

The Windows calculator, regular scientific calculators without native complex number support, and many other applications that you might try to use with eqn (1) will fail... those guys over at MathWorld aren't bothered by this because their product, Mathematica, pretty much never fails. :-) (Mathematica will produce results from expressions that almost any 'everyday' calculator like Excel will barf at, since Mathematica 'knows' many extensions of 'familiar' functions that make them 'work' in uncommon domains that high-powered math guys are familiar with... for instance, the factorial function can be extended to produce results even when its argument is negative or fractional, even though for the vast majority of people this is unexpected behavior.)

An implementation using equation (2) is going to be a lot more efficient than one using eqn (1). An implementation using a boring 'if/then/else' approach is going to be the most efficient of all. Often the most 'elegant' mathematical expressions are the most inefficient if you perform the 'straightforward' implementation; this is understandable in that by 'elegant' one oftens means they're trying to hide lots of ugly details in a few nice, all-powerful functions -- which are inherently slow to evaluate.

---Joel

Reply to
Joel Kolstad

John Woodgate wrote: Snip

Thanks for the laugh.

-- Tom H

Reply to
HorneTD

Do you even know what a "square wave" is?

Do you have any idea at all why asking for an "equation that gives voltage" is stupider than a joke?

You'd better ask your teacher for remedial instruction on the difference between "pressure" and "flow". Or maybe the difference between "measuring" and "fantasizing".

Good Luck! Rich

Reply to
Rich Grise

This is the problem. Your problem statement doesn't make any sense.

There Is NO Equation that can give you voltage based on any of those other parameters.

You cannot write an equation that derives height from speed. They're orthogonal.

You really need to go back to your fundamentals and learn the difference between things like voltage, resistance, power, frequency, and so on.

Good Luck! Rich

Reply to
Rich Grise

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.