Attached is a simple 8-bit sine wave Direct Digital Synthesizer (DDS) in Propeller assembler. The DDS uses a 256 sample look-up table in cog RAM. The accumulator and tuning word are 24-bits in length. Minimum step size is 0.170Hz. With the propeller clock at 80MHz and no post-DAC filtering, the output is usable through around 150-200kHz. I'm sure you can go higher with filtering, but I haven't tried.
The heavily commented source is prefaced with a bunch of introductory documentation. A linear-weighted 8-bit R2R DAC is used, that is well documented as well. In the documentation there are external references to more information on the subject of the DDS and R2R DAC.
This object is actually quite small once you strip all the documentation out; it has to be in order to be fast. I'm no PASM expert by any means, but I would certainly like to know if anyone can make this run faster (thanks to all contributors for the suggestions so-far).
The archive includes a simple Excel 2003 spreadsheet that shows how tuning words are calculated. The look-up table can be easily modified to produce any waveform. The PASM code can be easily modified to produce square waves, triangles, ramps, etc. without a look-up table.
Perhaps I'll embellish this example with other waveforms later on. Independent I/Q output in multiple cogs is also an interesting target but I have to learn how to launch multiple cogs and keep them somewhat phase coherent.
I post this now because the object has been languishing in my to-do bin and lately someone else in the forum needed an ultrasonic sine wave generator. Any comments or suggestions are most welcome. I'll post the final version in ObEx if anyone thinks it is worth it.
* V1.00, 06 April 2010, first release.
* V1.01, 06 April 2010, Incorporated Kurneko's two excellent suggestions as of post time, the current V1.01 sine DDS loop uses 28 clock cycles, down from 40 cycles. This represents a 48% increase in usable output frequency. Thanks Kurneko! I have verified the number of saved clock cycles by frequency measurement. The Excel 2003 spreadsheet has been updated to allow you to do the calculation for determining number of clock cycles used from measured output frequency.
* V1.02, 06 April 2010, Error in the R2R documentation schematic fixed. The resistor to ground is 2R not R. Thanks to Toby Seckshund for pointing this out.
The attached pictures of the output waveform at 1kHz and 100kHz are for V1.00. These waveforms look about the same for V1.01 but are now at 1.5kHz and 150kHz respectively due to the reduction in clock cycles.
Best Regards, David
Post Edited (Drone) : 4/6/2010 1:45:39 PM GMT