# How to choose the value of the output frequency carrier for PWM?

I want to choose a PWM frequency using the formula from this article: How to use fast PWM (Pulse Width Modulation) Mode of AVR microcontroller Timer.

The formula is:

$$\f_{\small PWM} = {\Large{f_{crystal}} \over {\large prescaler \times 510}}\$$

Where does the number 510 come from?

• Most likely that is the maximum value of the PWM framing counter and thus sets the overall period of the output. But questions on stack exchange sites are required to stand on their own; they must not depend on external links for critical detail. Nov 12, 2020 at 19:14
• At present, you don't have much of an answerable question. To get a useful answer and allow the question to survive, you'll need to edit your question to make it independent, to describe your goal (what the PWM signal is for, what frequency you require, and why) and what flexibility constraints you have: can you chose an arbitrary crystal frequency within the range supported by the MCU? Today that would be unusual. Nov 12, 2020 at 19:27

$$\f_{\small PWM} = {\Large{f_{clock}}\over{\large prescaler \times 255}}\$$
This is because the counter has to count to 255 for every period of the PWM, so the PWM frequency is $$\1 \over 255\$$ of the clock frequency (assuming the prescaler is set to 1).