How to create pwm with arduino uno r3

Can I fix Frequency at 45khz ,when I change duty cycle my frequency on oscilloscope will be change to another Frequency. I dunno to fix it (I need 50per 70per and 90per)

Post your program so we can see what you are trying to do.

The Atmega 328 datasheet has all the details.

It would also help if you explain why you need particular frequencies.


You need 2 compare registers (OCRA, OCRB), one for the frequency (reset of the timer on a match), and one for the duty cycle (toggle output pin).

45kHz = 45 times per millisecond = 1 time per 22.22...microseconds Within the range of delay microseconds but might have to do port manipulation to cut out library function time.