Sum of sines sound wave using microcontroller I need to produce a signal which contains only several frequencies, for example, 17KHz, 17.2 kHz,17.6 kHz. The components I'm using are microcontroller (PIC16F1783 by microchip) which works at 80 kHz frequency, and produces an analog signal, which is then fed into an audio amplifier and then into a speaker. 

First, I'm trying to output a single frequency, say 17 kHz. under timing and low memory constraints my algorithm is as follows:


I have an array of 400 elements which contains samples of a sine wave at constant intervals
Every clock cycle(80,000^-1 sec) I output sine_array[index] to the audio amplifier (and then to the speaker) where index starts at 0 and increased each cycle by: (17,000/80,000)*400=85. 


However, for some reason, besides seeing the pure 17 kHz frequency, I also hear (and see on the oscilloscope) parasitic 5 kHz frequency!
I've also noticed that for frequencies such as 16 kHz (index increased by 80), 8 kHz there are no parasitic frequencies.
So I though it may have something to do with the fact that 400/80 is an integer, whereas 400/85 isn't.

Can anyone please suggest a creative way to sort this issue? The final goal is, as stated, to produce a signal which is composed of several frequencies with a rather small difference (around 200 Hz).
To explain the problem (without solving it):


  However, for some reason, besides seeing the pure 17KHz frequency, I also hear (and see on the oscilloscope) parasitic 5KHz frequency! 


Your sampling rate is 80 kHz, so the Nyquist frequency is 40 kHz.  Your generation method produces a distorted sine wave at 17 kHz, which produces harmonics at:


17×2 = 34 kHz
17×3 = 51 kHz
17×4 = 68 kHz
17×5 = 85 kHz
...


But everything above 40 kHz gets aliased, so 


51 kHz becomes 40-(51-40) = 29 kHz
68 kHz becomes 40-(68-40) = 12 kHz
85 kHz becomes 40-(85-40) = -5 kHz, which then aliases off 0 Hz and becomes 5 kHz
...



  I've also noticed that for frequencies such as 16KHz (index increased by 80) ,8KHz there are no parasitic frequencies.


Now you've got harmonics at 32, 48, 64, 80, ...  These alias to 32 kHz, 32 kHz, 16 kHz, 0 kHz, etc.  So they aren't as obvious, but they're still there unless your wavetable is lining up perfectly with the samples.

If you look at your output using an FFT analyzer, you should be able to see these aliased harmonics more clearly:



http://www.music.mcgill.ca/~gary/307/week4/wavetables.html