Say that you want to generate a 400hz sine wave. Store that information in a 256 array.
Set up a timer that trips every 1/(400*256) = 10us. In the isr, increment an accumulator and output the value in the array indexed by that accumulator.
You are done.
I see what you did there. Getting back to the question posed by the OP, with a specific value of 440Hz (standard concert pitch A, for tuning) rather than 400 Hz (which gives 10 ?s, albeit with a 2.4% error) you would set up a timer that trips every 8.877841 ?s.
Using the
formulacompare match register = [ 16,000,000Hz/ (prescaler * desired interrupt frequency) ] - 1
with a prescaler of 1, this gives
compare match register = 16,000,000 / ( 440 * 256 ) - 1 = 141.045454545454545 = 141, as an 8-bit integer.
The error from integer roundoff is a pretty reasonable 0.03%.
I'm not sure what the allowable error is in the 16MHz Arduino clock oscillator (pointer, anyone)?
But that looks as if it would be suitable for tuning an instrument.