What does a voltmeter read on a PWM pin ?

I am still working on understanding how the PWM signal can be measured. I know that I should be able to see it on a scope and there are lots of example pictures of what it should look like depending on the duty cycle.
So, I was thinking that at a 100% duty cycle, I should be able to read the voltage with a VOM and on my Nodemcu board, that is what I am seeing, a voltage of 3.2v, DC.

Then if I change the duty cycle to be 50% is it accurate that the VOM would read 1.6v DC ?
I am still getting various readings so I am not sure it is my understanding, wiring or sketch.

I am trying it with a very simple sketch varying the duty cycle from 0 to 200.

This is my test sketch:

int enA = 5;
int in1 = 6;
int in2 = 7;


void setup()

    pinMode(enA, OUTPUT);
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
  

   
void loop()

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set speed to 200 out of possible range 0~255
analogWrite(enA, 200);

It will depend on the input circuit of your meter.

Unless you rectify* the output and smooth it, the reading would be nonsense due to the response time. An analogue meter may integrate it a little better, but I still wouldn't rely on it.

  • May not need to rectify it as it doesn't go negative of course.

An analog meter will read the average because the coil deflection depends on the average current and the inertia smooths out the movement and it can't respond at the frequency of the PWM. (That's assuming it a regular old-fashion electro-mechanical meter with no active electronics.)

A digital meter will probably give you "jumpy" undefined readings between zero and 5V (assuming 5V PWM) or you might get the average on some meters.

Some meters have a "true RMS" feature.

So, I was thinking that at a 100% duty cycle

Zero and 100% should read accurately. :wink:

A digital multimeter does a (relative low) number of samples per second, and will show you the average of those samples.
If the PWM frequency is moderate or high, and if there is no load to the PWM pin, you will always see the maximum, in your case 3.3 Volts.
This is caused by the nature of a PWM signal; either VCC or GND.
A duty cycle of 25 % means there's 25 % of the times VCC, and 75 % of the times GND.
But because of the way the sampling of a DMM works, energy will be stored in the sampling circuitry of the DMM if the measured PWM output is open.
As soon as you put a load to that output, this stored energy will deplete fast enough to do a decent measurement.
So if here is a load, the DMM should show you a value proportional to the duty cycle of your PWM signal.
If you think your measurement is wrong, put a small load to the output and try again.
Something like a 4K7 resistor or so.

An analogue multimeter (with a coil instrument) will store energy in another way, and it has a very small hardware dampening mechanism (a spring that will return the needle to zero if there's nothing to be shown).
I can't tell you how that would behave, as i've not been using such instrument for over 30 years, long before i became aware of PWM signals.

I would put a low value resistor like 100R to 1K in series between the PWM and the meter. Then put a capacitor say 10uF but it is not critical between your meter input and ground.

This will smooth the voltage so you can read it accurately.

I am still working on understanding how the PWM signal can be measured

What exactly do you want to measure ?

Guys, what DMMs do you have? Both my cheap DMMs have some low pass filtering to remove noise and aliasing. I don't know how it is exactly implemented but the measured value is steady voltage equal to the average voltage of the PWM (=Vcc*duty); no fluctuations, no error (=error well within the DMM precision). I would be very surprised if a more expensive DMM do not have at least the same or better input filter. If the measured voltage is truly fluctuating (the OP is a bit unclear in this topic - they claim 1.6V @ 50% duty which is the expected value) I would suspect some other source of error. Such as the true test sketch - the posted one does not include any curly brackets which does not feel right.

The post of MAS3 demonstrate very poor understanding of the topic.

  1. I don't know why do you think the sampling circuitry stores the peak voltage.
  2. For an ideal output pin your load resistor does nothing. In the real world it will make a voltage divider with the non-negligible output resistance of the pin reducing the measured voltage (it will be less than Vcc*duty).

AJLElectronics:
Unless you rectify* the output and smooth it, the reading would be nonsense due to the response time. An analogue meter may integrate it a little better, but I still wouldn't rely on it.

  • May not need to rectify it as it doesn't go negative of course.

An analog meter should integrate accurately as the mechanicals are designed to be as linear as possible.

Dual-slope integrating ADCs (which many digital meters use) also average accurately as these take a
second or more to integrate the signal direct onto a capacitor.

However a more modern meter design using a rapid sampling approach may give more random
readings as the sample time is not large enough to average out PWM.

UKHeliBob:
What exactly do you want to measure ?

Actually, I am trying to use this simp,e sketch so I can figure out what is wrong with another, far more complicated sketch. It also uses PWM to turn a motor and I can't figure out:
Do I have the correct pin ?
Is the signal on the pin correct ?

I wanted a simple sketch whose actions would be predictable and measurable. I am hoping to be able to get by with just the VOM as my scope skills are rudimentary at best.

“ Do I have the correct pin ?
Is the signal on the pin correct ?”

To use PWM, you need to look up which pins on your Arduino board are capable of PWM.

A simple LED/resistor on the output pin will tell you if the pin is working.

A home made logic probe with pulse detector is nice to have for ‘go no go’ testing.

Do you have a second Arduino ?
If so then that could be used to read and interpret the output of a pin on the first one

Your code sample as written won't load into my Arduino Uno. There are no initializers? Here is the code you posted:

int enA = 5;
int in1 = 6;
int in2 = 7;


void setup()

    pinMode(enA, OUTPUT);
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
 

   
void loop()

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set speed to 200 out of possible range 0~255
analogWrite(enA, 200);

You may want to try this example:

int enA = 5;
int in1 = 6;
int in2 = 7;


void setup() {

    pinMode(enA, OUTPUT);
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
 
}
   
void loop() {

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set speed to 200 out of possible range 0~255
analogWrite(enA, 200);

}

Note the added curly braces.

As written your code will output about an 80% duty cycle on pin 5 which it does. (200 / 255 = .7843 * 100 = 78.43%. That's your duty cycle of your PWM.

On my setup using an Arduino Uno measuring pin 5 I get 3.849 volts. If I take my VCC of 4.86 volts and multiply by .7843 I get 3.811 volts which can be expected since in a perfect world with a VCC of exactly 5.0 volts and keeping in mind the 256 bit resolution each step of quantization will be 5 / 256 = 19.53 mV or about 20 mV. Pin 5 is your PWM, Pin 6 is High and Pin 7 is Low. Exactly per your code.

The numbers only change with your VCC being 3.3 volts verse 5.0 volts. As to the meter used? I used two meters, a very inexpensive (cheap) Omegaette Model HHM93 and a Fluke 87. The HH 93 is an average responding RMS indicating meter and the latter a true RMS meter. Both read about the same, +/- a few millivolts.

Anyway, change your code and try measuring again, as I said, as written it won't even load?

Ron

Stop wasting your time.
Simply put a series 4.7k ohm resistor on the ouput of the pwm pin and a 4.3uF cap from the other end of the resistor to ground and read the analog voltage at the connection of the resistor to the cap .
It's called an RC LPF.
GOOGLE IT

raschemmel:
Stop wasting your time.
Simply put a series 4.7k ohm resistor on the ouput of the pwm pin and a 4.3uF cap from the other end of the resistor to ground and read the analog voltage at the connection of the resistor to the cap .

How exactly adding unnecessary hardware does help to stop wasting time? If most (all?) multimeters include a low pass filter why to add another one?

well then why is tge OP posting if he can read it witha meter ?

It it's so simple why are we at 15 posts for something that could have been resolved in 5 minutes with
two simple cheap components ?

Ron_Blain:
Your code sample as written won't load into my Arduino Uno. There are no initializers?

Thank you Ron, I finally straightened out the code. The Crapola that I originally posted was a result of being in a hurry and a lot of cutting and pasting..
I will give your code a try when I get back as it looks to be exactly what I was looking for.

If you had a proper RC LPF (one resistor and one cap) your analogRead values would match your analogWrite values but the scale would be different. (analogWrite is 0 to 255 whereas analogRead is 0 - 1023 but percentage wise they would match. I've done it a hundred times. 25% duty cycle pwm will read
25% scale analog in. It's simple math. It has to work if the the RC LPF is worth a damn.

I have been trying another sketch in my quest to determine which pin is which.
Here is the link to the example. [Example](ESP8266 NodeMCU PWM with Arduino IDE - Dim LED (Analog Output) | Random Nerd Tutorials

I thought that with the Nodemcu, the pins were called out as were numbered on the board.
IE, D0, D1, D2, etc.
But then when I was reading about the example, I read this
"Start by defining the pin LED is attached to. In this case, LED is attached to GPIO 2 (D4).
Huh ? I thought D4 would be called out as 4 in the sketch.
Nope. So it is still a guessing game to determine the Arduino sketch pin number. How did this dude, Rui Santos, know to use "4" in the sketch, why not 3 or 5 ? Sigh, time for bed.
And here is the example sketch.

/*********
  Rui Santos
  Complete project details at https://randomnerdtutorials.com  
*********/

const int ledPin = 2; 

void setup() {
  
}

void loop() {
  // increase the LED brightness
  for(int dutyCycle = 0; dutyCycle < 1023; dutyCycle++){   
    // changing the LED brightness with PWM
    analogWrite(ledPin, dutyCycle);
    delay(1);
  }

  // decrease the LED brightness
  for(int dutyCycle = 1023; dutyCycle > 0; dutyCycle--){
    // changing the LED brightness with PWM
    analogWrite(ledPin, dutyCycle);
    delay(1);
  }
}

Maybe he read this

Look at the PINOUT

"D4" is GPIO-2 (go figure)