# Understanding the Fast PWM output frequency

I am using an Arduino NANO. and am trying to understand the frequency range that fast PWM is outputting

So this sets the 16Mhz clock to 2Mhz

// Set Timer 1 (16-bit) to fast PWM mode 15, x8 prescaling - 2Mhz Output TCCR1A = _BV(COM1A0) | _BV(WGM11) | _BV(WGM10); TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11);

the spreadsheet that comes with it, states that a value from 300 to 30,000 is sent to the Timer output (keep in mind that it is a 16 bit input.

void setTimer1(uint16_t val) {

OCR1AH = val >> 8; // +store 8 MSB of val to OCR1AH OCR1AL = val; // +store 8 LSB of val in OCR1AL

So I am guessing that between 300 and 30,000 are sent to val. my question is:

what frequency will the PWM output at 300? what frequency will be outputted at 30,000?

Jakk89: So this sets the 16Mhz clock to 2Mhz

// Set Timer 1 (16-bit) to fast PWM mode 15, x8 prescaling - 2Mhz Output TCCR1A = _BV(COM1A0) | _BV(WGM11) | _BV(WGM10); TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11);

the spreadsheet that comes with it, states that a value from 300 to 30,000 is sent to the Timer output (keep in mind that it is a 16 bit input.

Nope. That is impossible. There cannot be 300 to 30,000 steps with a base clock of 16 MHz and an output of 2 MHz. Let's do the division... 16 MHz / 2 MHz = 8. Eight steps. That is the maximum number based on the description / comments you have provided.

``````  OCR1AH = val >> 8;  // +store 8 MSB of val to OCR1AH
OCR1AL = val;           // +store 8 LSB of val in OCR1AL
``````

...is a terrible way to set the OCR register.

This (and the datasheet) should be your reference...

http://www.gammon.com.au/timers

Finally, when asking programming questions you are far more likely to get help and far more likely to get correct answers if you post a complete sketch.