Darren
The basic technique is to quantize and store the waveform in a table. This is how I do it.
Write a small program in any language of your choice and print out a table of values that define a sine wave. You specify the number of steps in the waveform(time slices) and you specify the maximum value the quantum can have(in your case 16).
Once you have this table, all you have to do is to setup a timer to interrupt you at a fixed rate (timeslice) and you put out one element of the table at each slice. In this way, you will be able to approximate the waveform you created in memory.
To change the frequency of this waveform, all you have to do is change the timeslice interval. Smaller intervals will give you a higher frequency. However, be warned, code takes a finite time to execute and you will need to be sure you can generate the 300Hz that you need. I am pretty sure the PIC can do upto around 4KHz with its internal 4MHz oscillator.
This is just one technique of creating the sine wave. There are other techniques like phase accumulator and Direct Digital Synthesis which you may like to read up.
Bookmarks