I am trying to generate from 1Hz to 1MHz PWM signal using an ATMega2560 but I am affraid it is not possible due to prescaler and MPU clock limitations. Does anybody know the low and high PWM frequency is possible using ATMega2560 at 16MHz clock ? Thanks

The frequencies depend on the desired duty cycle granulation. E.g. 1MHz PWM from a 16MHz clock can be achieved with a 1:1 prescaler and TOP=16 in fast PWM mode, leaving 16 steps for the duty cycle.

The 1:1024 prescaler suggests TOP=16M/1024 about 16k for 1Hz.

The 16-bit timers can get down to about 8.4 seconds per cycle (0.12 Hz).

16000000 / 65536 = 244.140625

Maximum prescale is 1024 so:

244.140625 / 1024 = 0.238418579101563 Hz

If you use Phase Correct PWM it counts both ways so you get half the frequency:

0.119209289550781 Hz

The maximum frequency is determined by the number of bits of resolution that you need. For a clock rate of N, and Y bits of resolution, the max frequency will be N/(2^{Y})

If you want the full 8bits of resolution provided by analogWrite(), the max frequency would be 16e6/256 = 62.5kHz. To get 1MHz, you'd need to live with 4 bits of resolution.

Thank you all. Very helpfull answers !!!

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