PWM I am not able to fine tune it

Here is my code, it works, I can get a frequncy output that is stable. However I can not tune the frequency to my precise value. I have tried changing the analogwrite function from 128 to 255 with no change.
Can any body advise if this can be done.

void setup()
TCCR1B = TCCR1B & 0b11111000 | 0x01; //0-7 for the last number

pinMode(9, OUTPUT); // enable the PWM output (you now have a PWM signal on digital pin 10)


void loop()
analogWrite(9,128); // set the PWM to 50% duty cycle


It appears you’ve seen this playground page

as you have this in your code, with replaced with 0x01
TCCR1B = TCCR1B & 0b11111000 | ;

Your frequency choices are limited as shown - the 128 in (9,128) only changes the width of the pulse that occurs at the frequency selected.

Pins 9 and 10: controlled by timer 1
Setting Divisor Frequency
0x01 1 31250
0x02 8 3906.25
0x03 64 488.28125
0x04 256 122.0703125
0x05 1024 30.517578125

Yep your right, I got that page info pointed to me from another post.

I am curious though about why doesn't the change in the width of the pulse change the frequency. Or does it flip the off time with the width of the on time.

Because the frequency is the reciprocal of the high time plus the low time of a pulse. All you are doing is altering the ratio of each but the total remains the same.