PWM voltage output tolerance

Hi all,

What is the tolerance for the 5V output we get from the analogwrite() function?

AnalogWrite (PWM) is digital. It switches between ground and supply. What do you mean by "tolerance". Leo..

Wawa: AnalogWrite (PWM) is digital. It switches between ground and supply. What do you mean by "tolerance". Leo..

I know the output is digital. What I meant by tolerance is the (+/-) variation within 5v of the digital signal when it is in the high state.

The output has mosfet switches, so voltage depends on the accuracy of the 5volt rail.

I think the datasheet mentions a ~40ohm internal resistance of the pin. So any "load" will drop the output voltage accordingly. Leo..

What is intriguing is why you want or need to know? It should not be important in any proper design.

From table 30-1 of the ATmega datasheet:

Output low is 0.9V maximum at Vcc = 5V, 20mA, and less than 85 degrees C.

Output high is 4.2V minimum under the same conditions.

That's with 20mA. OP did not say what is connected to the pin. With little or no current draw, voltage will be very close to supply and ground. Leo..

Should be same as other digital output on the pin, refer to the Electrical Characteristics section of the datasheet for numbers and graphs of output voltage vs current draw.

You first have to establish how clean the Vcc 5V supply to the chip is - the outputs when HIGH will be pulled directly to this rail.

What you can say is that for a lightly loaded output pin the PWM ratio will match the ratio of average output voltage to Vcc - in other words its a ratiometric output.

The precise ratio depends on whether the timer driving the PWM pin is in phase-correct or fast mode though - phase-correct mode counts 0,1,2,...,254,255,254,....,2, 1, 0, 1, 2...., whereas fast mode counts 0,1,2,....,254,255,0,1,2,.....

You'd have to doublecheck but I think that means analogWrite (pin, 1) for phase-correct gives 9.8mV for 5V supply but for fast-mode gives 19.5mV. Try using a multimeter to check this?

OP only asked for the voltage on the pin when the PWM pulse was in the "high" state. The Atmel datasheet shows on page 480, Figure 31-308 that it is only 5volt without pin current. Leo..

The OP is probably interested in using analogWrite to generate a low-pass filtered analog signal if enquiring about the analog accuracy of the output pin though...