HIGH PWM Frequency

I see here Arduino Playground - TimerPWMCheatsheet That i can make pins 5 and 6 go to 62.5kHz. Is 100kHz possible?

Thank You, John

I see here Arduino Playground - HomePage That I can make pins 5 and 6 go to 62.5kHz. Is 100kHz possible?

Yes, but...

Pins 5 and 6 are output pins for Timer 0 on the ATmega328. You can get pwm output faster than 62.5 khz by setting the timer to a mode which does not have the cycle length of a count to 255, but rather to a lower value contained in the outputA compare register used by pin 6. Therefore, you can only get the 100khz pwm outputB on pin5.

You will also not be able to get the full 8 bit resolution (0-255) on the duty cycle of the pwm output. There are two pwm modes available (fast and phase correct) and to get 100khz you will have pwm output resolution to either 160 counts(fast) or 80 counts (phase correct) with no prescaler.

Getting the 100khz pwm from timer0 will also affect the millis() function because you will be changing the prescaler on that timer.

Do you need both pins 5 and 6? What are you trying to accomplish?

No I do not and going up past default is really playing with things that I've coded up for time evenvts. like counting seconds that a button has been pressed for example. So, I'll be looking for a work around for that next.

I only need to PWM from one pin. Any pin really that I'm not using for the OLED would be just fine. I'm using pin 6 for a button but that can easily be changed.

Thank You, John

Guess I was pretty excited to see a response so soon. I am driving a mosfet which is driving an inductor with a 1mHz limit. 100kHz is the speed that I'm looking for with a duty cycle of 28% or so.

Presently I'm using A4, A5, and D4 for an OLED. I have some buttons which can all be rearranged. Your guidance on driving the mosfet at 100kHz is greatly appreciated.

Thanks again, John

No I do not and going up past default is really playing with things that I've coded up for time evenvts. like counting seconds that a button has been pressed for example. So, I'll be looking for a work around for that next.

You can use timer 1 or timer 2 and avoid changing the default values for timer 0 which runs the millis function. The prescaler settings are timer specific.

You can use pins D9 and D10 on timer 1 or pin D3 on timer 2. Timer 2 is like timer 0 in that a cycle time faster than 62.5 khz will be limited to one output pinB.

There is some code for 100khz on timer 2 in this thread
http://forum.arduino.cc/index.php?topic=310753.0

For a 28% duty cycle you can use an OCR2B value of 44. Counts are zero referenced, so 45/160 = 28.15%.

You can search the forum or google "100khz timer 1" if you need pins 9 or 10.

You are on a path which is leading away from basic Arduino functions, and it will be advised to head for the ATmega328 data sheet and read all about timers. http://www.atmel.com/Images/doc8161.pdf