If you are talking about generating sinewaves then you need to look at how audio sampling works. To generate simple square waves, you can go up to 8 MHz as robtillaart says.

From this page:

http://en.wikipedia.org/wiki/Sampling_%28signal_processing%29

The above image shows the general idea. We need to sample the sound we are trying to produce (eg. a sine wave) at at least twice the frequency we desire, see:

http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem

So to get 20 kHz we need 40 kHz samples (CDs BTW sample at 44.1 kHz).

That is, a sample every 25

~~mS.~~ uS.

(edit) Corrected on AWOL's advice.Now looking at the spacing of the dots vertically the samples need to be able to reproduce a range of values, or we are back to having a square wave. Say, 256 different values (as in the linked page you gave). That is in fact only "8-bit sampling". BTW the Wikipedia page says that "Eight-bit audio is generally not used due to prominent and inherent quantization noise". So we really should use more than 8 bits.

But sticking with 8 bits for now, to generate the 256 different voltage levels required, we need to use PWM (pulse width modulation) where a square wave is produced with a variable duty cycle.

See: http://en.wikipedia.org/wiki/Pulse-width_modulation

For example a duty cycle of 128 would be "half voltage" and duty cycle of 64 would be "quarter voltage" and so on (assuming this is out of 256).

Now for the internal timer to do this, it has to count up to 256. And the fastest it can do that is at the clock rate which is 62.5 nS.

`62.5 nS * 256 = 16 uS. `

So how many times can we count up to 16 uS in one second? 1/0.000016 = 62500. Therefore the absolute maximum sampling frequency, with a 16 MHz clock, and 8 bit samples, would be 62.5 kHz.

There is another factor ... for the individual samples to be "in phase" the authors of that sketch have used "phase correct" PWM mode. This mode centers the "on" cycle, rather than having it at one edge. But it takes twice as long to do phase-correct PWM mode, because the timer counts up, and then down again. So we have to divide the figure we got by 2.

`62.5 kHz / 2 = 31.25 kHz.`

So that's why the maximum sample rate is around 32 kHz. Can't argue with the laws of physics.