Timer interrupts - Frequency, PWM and Duty Cycle

I have been reading many tutorials and posts on timers , but am still a little confused.

I want to produce a square wave where I have control of both frequency and duty cycle of a square wave.

I understand the prescaler etc. but the OCR1A etc. seems to be used for duty cycle and for adjusting to the exact frequency from the prescaler values.

Could someone explain how this is done. I would appreciate a snippet of code if possible.

Thanks

Have you read the Atmega datasheet for whatever processor you are using? - the Uno uses the Atmega328. It contains a lot of information.

You might also look at the Arduino code for analogWrite(). Presumably you can do what you want by modifying that code.

...R