Method to determine least-error prescaler and top values for timer1 of Arduino?
You will get the most accurate result by using the smallest prescaler you can.  The only reason you can't always use the smallest prescaler is because then the TOP value won't fit into your 16 bit target register (like OCR1A).  So the general algorithm is:


For each prescaler value N (1, 8, 64, 256, 1024):

Calculate TOP = (f_clk / (N * f_pwm)) - 1
If TOP &lt;= 0xFFFF, you're done.



(You'll want to consider the extremes, too; TOP=0 or TOP=1 probably doesn't actually work for generating PWM, for example.)