PWM toggle time

Does anyone know how long Arduino takes to toggle between states when using pwm? What are the rise and fall times for the Arduino pwm?

"Arduino" is a lot a very different boards with different controllers. Try to be more specific.
The rise and fail times should be described in dynamic characteristics section of the datasheet. This times will be the same for single state change and for pwm.

Ah, I didn't realize that the Arduino boards are so different. I'm using a Mega2560. The datasheet I downloaded from the Arduino website does not have any dynamic characteristics section.

The default PWM frequency is 480 or 690Hz depending on the pin (chart).

I couldn't find anything about the rise & fall times. I scanned-through the ATmega datasheet and I only found information for the clock and SPI pins... Nothing for regular/PWM output pins. It might be there... The datasheet (the version I have) is over 600 pages long.

According to users measurings it is in the range below 10-50ns

Simple answer: maximum allowed rise and fall times are given for inputs only.
The behavior of outputs depends heavily on the connected circuitry, wire impedance and length...

1 Like

Thank you!

If using analogWrite() function, then the frequency of the PWM is fixed in UNO/

NANO/MEGA. It is either 490 Hz or 980 Hz.

Honesty speaking, it is not true. You can change the frequency by changing the settings of the timer - and still able to use the analorWrite() command with a new PWM frequency

From user point of view, we need to know --

Function name
Its return value (if any)
Argument (s) it takes

The function: analogWriye(arg1, arg2); asks for two arguments --

arg1 for the DPin and 
arg2 for the 8-bit dutyCycle.

Arduino Reference manual says --

DPPin-6, 5 deliver 980 Hz PWM signal
DPin- 9, 10, 11, 3 deliver 490 Hz PWM signal

To operate the above-mentioned PWM pins at some other customoized frequency, I would go with the following WaVe Form Generation Table (Fig-1) and load the relevant registers with values as needed:


Figure-1:

Right, the frequency can be changed at any time, affecting all output channels of that timer. But if the frequency change requires a change of the timer TOP then the duty cycle mapping changes as well. The 100% value always equals the actual TOP value in OCRAx or ICRx of timer x.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.