Wow! How nice I am...I didn't realize I provided the calculation for tones on the article page.
When I explained before:
0xFFFF - 0xED56 = 0x12A9 (or 4777)....divide by 2 = 2388.5 <- because of 1:2 prescalar
Now...we are using a 20 MHz clock....1/(20 MHz / 4) * 2388 = 0.0004776 Seconds
Finally:1/0.0004776 Seconds = 2093.8 Hz which is approximately C7 on a piano.
I forgot to multiply by 2, which represents 1/2 the tone or 1/2 the tone's frequency since a 50/50 -- on/off PWM signal is sent to the speaker. The signal is +5v for 1/2 the frequency length and +0v for half the frequency length. And I also made a mistake...the prescalar acts as a multiplier not divider when working our way backwards....Re-doing the calculation:
0xFFFF - 0xED56 = 0x12A9 (or 4777)....multiply by 2 = 9555 <- because of 1/2 Tone
9555 * 2 = 19110 --- multiply by 2 because of 1:2 prescalar
Now...we are using a 20 MHz clock....1/(20 MHz / 4) * 19110 = 0.003822 Seconds
Finally:1/0.003822 Seconds = 261 Hz which is approximately C4 on a piano.
When the timer reaches 0xFFFF, the timer sets a Flag (or 1 bit) that tells the microcontroller an interrupt has occured. Then special interrupt code runs to tell the speaker output whether it should be +5v or +0v. Really, the code is just switching the output back and forth between +0v and +5v at the current timer0_val setting.
You can connect the speaker output signal to an oscilloscope and change the timer0_val value to see the effect first hand.