CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

software DDS

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
geolover



Joined: 08 Feb 2011
Posts: 18

View user's profile Send private message

software DDS
PostPosted: Mon Mar 14, 2011 2:35 pm     Reply with quote

Hello!

I want to implement a software DDS with a PIC and a DAC chip.

I know the standard procedure involves generate phase first then put phase into a sin function.

However, when trying to generate a 480 points sine wave look up table of 500Hz, I began to experiencing problem: I found a lot of numbers in the sine wave table are repeative and therefore useless!

This is the following equation I used to generate the sine wave table:

Phase=2*pi*f0*i/N;
f0 = 500;
i= from 0 to 479;

N=480

sample = 2^14+(2^14 - 1)*sin(phase);

because the DAC is 16-bit and its largest positive representation is 0x7FFF.

Also, could anyone explains to me about the relation of digital output rate, number of points in the look up table, and the frequency of synthesized waveform ?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 3:52 pm     Reply with quote

If the 480 points is over one sine wave, you really only need to calculate 120 points( first 90*)...
it's a 'cheat' I found on the web called 'magic sinewaves'.....years ago...
geolover



Joined: 08 Feb 2011
Posts: 18

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 4:50 pm     Reply with quote

temtronic wrote:
If the 480 points is over one sine wave, you really only need to calculate 120 points( first 90*)...
it's a 'cheat' I found on the web called 'magic sinewaves'.....years ago...

Well, I got enough program memory on my PIC so wouldn't mind to put extra 16-bit integers on it at all thanks to modern flash memory technology Laughing

However, could you tell me how to create sine waves by a look up table...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 4:59 pm     Reply with quote

The following CCS example files use a lookup table to create a sine wave:
Quote:

c:\program files\picc\examples\ex_dtmf.c
c:\program files\picc\examples\ex_sine.c

Forum posts:
http://www.ccsinfo.com/forum/viewtopic.php?t=33020
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 5:00 pm     Reply with quote

geolover wrote:
However, could you tell me how to create sine waves by a look up table...


As an example, let's say that you set aside 91 LUT values, corresponding to sin(0), sin(1), ...., up to sin (90). To "play" a complete sine wave through the DDS, you need to set up a stable timer "tick" which then dictates how often you send a new value to your DDS. You start by sending LUT index 0, then LUT index 1 on the next tick, and so on up to index 90. Then you reverse direction and send LUT index 89, LUT index 88, and so on down to index 0. Then you reverse direction yet again but now you send the inverse (* -1) of each LUT index. I'm sure you can figure out the rest for yourself.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 5:26 pm     Reply with quote

With any DDS work I have done the number of points in a full cycle is always a power of 2, generally 256 for crude 8-bit stuff, or 2^16 for fine (but slow)16-bit stuff. It is basically the length of the phase register. That way when the phase register rolls over you simply start on the next cycle. The resulting frequency is therefore the DDS clock speed * phase increment / phase register size.
_________________
The search for better is endless. Instead simply find very good and get the job done.
geolover



Joined: 08 Feb 2011
Posts: 18

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 5:54 pm     Reply with quote

SherpaDoug wrote:
With any DDS work I have done the number of points in a full cycle is always a power of 2, generally 256 for crude 8-bit stuff, or 2^16 for fine (but slow)16-bit stuff. It is basically the length of the phase register. That way when the phase register rolls over you simply start on the next cycle. The resulting frequency is therefore the DDS clock speed * phase increment / phase register size.

Thank you so much!

Does this means if I want to get a 500Hz sine wave at the output of a 16-bit DAC, a 2^16 size register is required, while the PIC write data to DAC every 2ms? By increasing the phase increment, I will be able to get 1000Hz, 1500Hz, etc. sine wave?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 6:20 pm     Reply with quote

If you only update the phase register every 2ms, the output state will only change 500 times each second. Frequencies over 500 Hz are clearly not possible. Actually Nyquist sampling tells you you can only get a theoretical maximum of 250Hz with a 2ms update cycle.

I generally start with the max frequency I need to generate. I need my DDS cycle to be 2.5 or 3 times that fast. Then I see how wide a phase register I can update at that speed. The DDS work I have done has all been square wave output. But you need to see if you get the sine amplitude resolution you need with the width of phase register you can update.
_________________
The search for better is endless. Instead simply find very good and get the job done.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Mar 14, 2011 6:59 pm     Reply with quote

Here is another way to look at it. Your sine wave is going to be built of little stair step blocks. Decide how long, in time, each of these blocks can be. That is how long you have to update your phase register, do your sine lookup, and load your DAC.

If you only have 20 blocks in a full cycle, that is 5 steps up and 5 down for each half cycle, and each cycle is 10ms (100Hz), you need to run your DDS loop every 0.5ms. If you can only loop your software every 2ms you either limit yourself to 25Hz output, or you make your blocks bigger and your sine wave gets really ragged.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group