# Reading DC rms/average voltage from a pwm signal

Hi, in one part of my project, I'm switching an N channel mosfet via digital pin PWM. It's adjusting power from two 3.7v batteries in series to a load. I need to be able to read the average voltage on the load side, but it's pulsing. I'm trying to figure out what the best way to achieve this is. Thanks!

Try a RC low-pass filter into an analog pin (probably with a voltage divider too given the voltage).

R= 4.7 k ohm C = 2.2uF

http://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/

Frack! Brain fart.

For a square wave, Vavg and Vrms are NOT the same thing. Calculating average voltage is as simple as duty cycle times peak voltage. So 5V pulses at 50% dutycycle is 0.50*5 = 2.5Vavg. Vavg = Vpk*dutycycle/255

However, power is equal to V^2/R, and Vrms specifically is the equivalent DC voltage that would cause the same power to be consumed. So for 5V pulses at 50% dutycycle:

5V^2/1 = 25W 2.5V^2/1 = 6.25W 0.50*5V^2/1 = 12.5W Obviously not the same as 2.5V

(dutycycle/255)(Vpk^2)/R = P = Vrms^2/R (dutycycle/255)(Vpk^2)/R = Vrms^2/R (dutycycle/255)(Vpk^2) = Vrms^2 cancel R from both sides sqrt(%*Vpk^2) = Vrms square root of both sides Assuming Vpk is 5V: Vrms = ((dutycycle/255)(5^2))^0.5 Vrms = 5*(dutycycle/255)^0.5 separate out the square root of 5 squared

Someone correct me if I'm wrong.

I cross checked my answer with this website: http://masteringelectronicsdesign.com/how-to-derive-the-rms-value-of-pulse-and-square-waveforms/

Hi, in one part of my project, I'm switching an N channel mosfet via digital pin PWM. It's adjusting power from two 3.7v batteries in series to a load. I need to be able to read the average voltage on the load side, but it's pulsing. I'm trying to figure out what the best way to achieve this is. Thanks!

Maybe I am oversimplifying it but it seems to me that if you output a 50% duty cycle PWM and adjust the R & C values of the RC filter until you get 2.5V , then you have a perfect PWM to analog converter that should output a voltage that correlates to the duty cycle. ie: 25% duty cycle => 5V/4= 1.25 V 75% duty cycle = (2.5 +1.25=3.75 V

Even if you couldn't find R & C values to give you this relationship can do the correction in SW. Why isn't it that simple ?

That is fine for the average voltage, but not RMS. Of course, you can correlate that to the RMS voltage.

But why do all that if you already know the duty cycle?

RMS and average voltage are not always the same thing.... in this case, it is.

I've read your latter posts. Any case: What would be the "average voltage" definition (if any) for a PWM signal?

Regards.

The OP never said anything about RMS . He specifically said "average" , which is exactly what an RC low pass filter does if the values are chosen correctly. I've done it myself before and was able to get 2.5 V for 50% duty cycle.

vffgaston:

RMS and average voltage are not always the same thing.... in this case, it is.

I've read your latter posts. Any case: What would be the "average voltage" definition (if any) for a PWM signal?

Regards.

My apologies, RMS and average are -not- the same thing here.

Average voltage is just.. an average of the voltage. If 5V is On 25% of the time, the average voltage is 1.25V. Whereas the RMS voltage would be 5*(0.25^0.5) = 2.5Vrms. IE, the voltage that would cause the same power dissipation in the load as 5V that is on 25% of the time.

Average voltage is just.. an average of the voltage. If 5V is On 25% of the time, the average voltage is 1.25V. Whereas the RMS voltage would be 5*(0.25^0.5) = 2.5Vrms. IE, the voltage that would cause the same power dissipation in the load as 5V that is on 25% of the time.

I think that is very useful info to know , regardless if it applies to this post.

raschemmel: The OP never said anything about RMS . He specifically said "average" , which is exactly what an RC low pass filter does if the values are chosen correctly. I've done it myself before and was able to get 2.5 V for 50% duty cycle.

He specifically said "Reading DC rms/average voltage from a pwm signal" in the title of the thread, so there is some question as to which he wants. He's not said yet.

Yes, I know, an RC filter will get you the average voltage. But you already have the duty cycle and the voltage. Why add parts and use an analog input? You can calculate it in the program.

This is what he said. Show me where it says "rms".

Hi, in one part of my project, I'm switching an N channel mosfet via digital pin PWM. It's adjusting power from two 3.7v batteries in series to a load. I need to be able to read the average voltage on the load side, but it's pulsing. I'm trying to figure out what the best way to achieve this is. Thanks!

It's a resistive load being powered by batteries. I'd really like to get the actual voltage somehow, since battery sag/voltage drop will play an issue. I found more info here.

The above are the OPs only two posts. I don't see anything about rms

I agree it is in his post title but he never said anything about it after that when asked for clarification. I don't think he knows the difference and thought they were the same. The fact that he lumped two different parameters together suggest that because if he was interested in one , he would not be interested in the other and vice versa.

Oh, come on! It is in the title. He typed the title.

Yes, if he doesn’t know the difference, isn’t it important to educate him about that difference? Perhaps he says average in his message, but really wants to know the RMS, but doesn’t know until he finds out what RMS voltage is.

Again, please tell me why it is necessary to waste extra parts and an extra pin just to find out what you can find with one equation. I’m just not getting it.

Yes, if he doesn't know the difference, isn't it important to educate him about that difference? Perhaps he says average in his message, but really wants to know the RMS, but doesn't know until he finds out what RMS voltage is.

Now we're getting somewhere.

Now we just have to find our which parameter he really needs. I think you already showed him how to convert from one to the other.

I maintain that by adding the RC LP filter and using an analog pin, he can measure the value. In defense of my point , I submit that the OP's words indicate he is looking for a measurement and not a calculation:

I need to be able to read the average voltage on the load side,

You point is he should just add a line of code. (which I submit is not a measurement)

I think that about sums it up.

My apologies, RMS and average are -not- the same thing here.

Average voltage is just.. an average of the voltage. If 5V is On 25% of the time, the average voltage is 1.25V. Whereas the RMS voltage would be 5*(0.25^0.5) = 2.5Vrms. IE, the voltage that would cause the same power dissipation in the load as 5V that is on 25% of the time.

You shoudnt apologise: We are here just to interchange ideas (and/or certainties; nevertheless I would prefere doubting on everything :cold_sweat:).

The product of the high voltage by the duty cicle has physical significance, as long as it is the DC value that a RC low pass filter will show: Is it correct to call it "average" (I wonder: belive me, I'm honest)?.

Regards

As long as the drive to the RC filter is symmetrical in nature and a square wave, then the smoothed DC output will be the average voltage

What do I mean by "the drive ... is symmetrical in nature"?

I mean that it must charge and discharge it equally well.

So let's say you had a single-ended drive, maybe a low side driver such as a MOSFET with an On resistance of 50mOhms. But the load is only 1k. You then have a 3.3k resistor and a 100uF capacitor RC filter.

When the MOSFET is On, the total resistance discharging the capacitor is through the MOSFET. 3.3k + 50mOhm = 3.30005K.

When the MOSFET is Off, the total resistance charging the capacitor is through the load resistance. 3.3k + 1k = 4.3k.

So the voltage across the capacitor will NOT be the average voltage. It will be quite a bit lower.

But let's make the ratio between the smoothing resistance and the other resistances much greater.

MOSFET 50mOhm Load 10 Ohm RC 100k and 3.3uF (same time constant as above)

Now the discharging resistance is 100.010K, charging resistance 100.00005k. Very little difference, so the smoothed voltage will only be very slightly lower than the actual average voltage.

Again, this is only true for a square wave.

Well, to be clearer, it -will- work for a pulsed sine wave or other waveform, but ONLY with symmetrical drive. In other words, the waveform must be coming from something like an Op Amp that can source and sink to maintain the waveform.

Clearly, a power supply with a transformer and rectifier diodes is not averaging the voltage with its capacitor. It is smoothing to the peaks, because the diode only sources current.

Still, if the PWM is coming from the same Arduino that is "measuring" the average voltage on the load, why not just calculate it from the PWM?

I don't think your calculations are correct . Are talking about the arduino PWM output pin that is connected to the input of the RC LP filter ?

The average of a 25% duty cycle PWM is 25% of the Vcc voltage which in this case is 5V. If you are trying to correlate the average of the PWM pin using the LP filter to the average of the H-Bridge which always has two devices on, I think the conclusion is the same. I think the averaging of the PWM pin using the LP filter accurately reflects the averaging of the power applied to the motor load. I don't have any calculations to prove that but that is my conclusion.

I think the averaging of the PWM pin using the LP filter accurately reflects the averaging of the power applied to the motor load.

Unless the “thing” connected to the PWM (with or without a H bridge) sinks constant DC current (i.e. not dependant on the DC voltage) the power is not proportional to the voltage (so the term “average” is misleading).

Regards

The "thing" the RC LP filter would be connected to is the PWM pin and when it is LOW it sinks current. When it is HIGH it sources current. In the case of the H-Bridge , connected to a motor load, when the signal is HIGH, the motor current passes through one transistor or mosfet to get to the motor and then through the motor and then through another transistor or mosfet to get to ground. When it is LOW, both devices are OFF and there is no path to ground and the voltage ACROSS the motor goes to zero.

The Arduino pin should be a symmetrical drive, and so should not be a problem.

I have seen people here try to generate something like a 0-10Vdc signal by using a high side PNP switch with an RC network after to smooth it out. It never quite works because of the effects of assymetrical drive currents.

If it is the output of an H-bridge, that should also work as it is a symmetrical drive.

vffgaston is right, power is not proportional to voltage. Hence all my futzing about to calculate RMS voltage.

But the original poster has still not told us if he's figured out yet if he means RMS voltage, or average voltage.

vffgaston is right, power is not proportional to voltage. Hence all my futzing about to calculate RMS voltage.

Thanks: I was questioning my basics :roll_eyes:.

Regards