Go Down

Topic: Reading DC rms/average voltage from a pwm signal (Read 14453 times)previous topic - next topic

noobdude

Sep 18, 2014, 12:27 am
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!

polymorph

#1
Sep 18, 2014, 12:43 am
RMS and average voltage are not always the same thing.... in this case, it is.

With a true square wave, Vrms = Vpk x percent/100, or in this case since analogWrite() is 0-255:

Vrms = Vpk x value/255

So you don't need to be able to measure it, as you know what you are sending to analogWrite().

So you don't need to be able to measure it.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

MarkT

#2
Sep 18, 2014, 01:25 am
That's not true if the load isn't resistive.

Try a RC low-pass filter into an analog pin (probably with a voltage divider
too given the voltage).
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

polymorph

#3
Sep 18, 2014, 01:53 am
Actually, if driven by a very low resistance like a saturated MOSFET, that measure of RMS voltage -will- be accurate.

However, the power will not be. And using an RC lowpass filter will only give you the average/RMS voltage for a square wave, not the power.

For the power, you need to know the current. If it is a resistive load, it is a doddle as you now the voltage and so the power is simply V^2 / R.

If it is a capacitive or inductive load, you are going to need a series current sense resistor and a fast ADC to capture a lot of samples during a cycle.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

MarkT

#4
Sep 18, 2014, 02:00 am

Actually, if driven by a very low resistance like a saturated MOSFET, that measure of RMS voltage -will- be accurate.

You might want to reconsider that remark, hint load=capacitor.

[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

noobdude

#5
Sep 18, 2014, 02:19 am
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.

http://forum.arduino.cc/index.php/topic,204036.0.html

Just need to read more.. Not enough time. I really appreciate the replies.

raschemmel

#6
Sep 18, 2014, 04:43 pm
Quote
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!

Quote
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/

polymorph

#7
Sep 18, 2014, 05:15 pm
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/

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

raschemmel

#8
Sep 18, 2014, 07:19 pm
Quote
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 ?

polymorph

#9
Sep 18, 2014, 07:42 pm
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?
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

vffgaston

#10
Sep 18, 2014, 07:52 pm
Quote
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.

raschemmel

#11
Sep 18, 2014, 08:57 pm
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.

polymorph

#12
Sep 18, 2014, 09:01 pm

Quote
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.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

raschemmel

#13
Sep 18, 2014, 09:03 pm
Quote
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.

polymorph

#14
Sep 18, 2014, 09:04 pm

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.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8