Author Message
 hricks
 Posted: Aug 22, 2011 - 04:32 PM
 Joined: May 01, 2007 Posts: 120 Location: Minneasota
 I have a project i am working on at home...... I got a skeleton code from online . One thing that is not provided is how to implement the sineWave function using the DAC,STK timer, Scale formula and look up table. The list of things I have in the file : 1.LookUptable base on 5V is given 2.Formular for calculating the Scale Value using LookUp Tale Provided. 3. I have a DAC module using SPI for DAC What I do not know or is trying to figure out is what are the steps using the lookUp and the timer to generate sine wave . Can someone Bless me with explaining how to go about ? God Bless

 clawson
 Posted: Aug 22, 2011 - 04:35 PM
 Joined: Jul 18, 2005 Posts: 62922 Location: (using avr-gcc in) Finchingfield, Essex, England
 What language? Are you just playing samples of a fixed frequency or are you doing DDS? _________________

 hricks
 Posted: Aug 22, 2011 - 06:02 PM
 Joined: May 01, 2007 Posts: 120 Location: Minneasota
 Language is in C. The goal of this project is to create sine Wave at 5v, 2 V, 1v and 3v Amplitude. The initial frequency is 40hz, initial timing requirement is 500ms

 thygate
 Posted: Aug 22, 2011 - 06:42 PM
 Joined: Sep 19, 2005 Posts: 768 Location: Belgium
 Check out this article on DDS http://www.electricdruid.net/index.php?page=info.dds What do you mean with initial timing requirement ? How many entries in the lookup table ? Is it one full wave or half a wave .. ? What is the samplerate ? DDS explained in one paragraph: Calculate phase increment as follows : Code: phase_inc = freq * phaseaccum_max / samplerate; So to generate a 40Hz wave with a 16 bit phase accumulator and 1kHz samplerate, the phase increment would be Code: phase_inc = 40 * 0xffff / 1000; If you now increment the phase accumulator with the phase increment at the samplerate, it will give you a 16 bit index of where in the waveform the current sample should be. Now, depending on the size of the lookup table, take the MSB's from the phase accumulator and use this as index for your lookup table, and write the sample to the DAC. So for instance if your table is 1024 entries (10bit), you get the sample as follows : Code: i = (phase_accum & 0xffc0) >> 6; current_sample = lut_sine[i]; So to put it all together : Code: // init phase_inc = freq * phaseaccum_max / samplerate; // timer isr running at samplerate phase_accum += phase_inc; current_sample = lut_sine[(phase_accum & 0xffc0) >> 6]; dac_write(current_sample); Last edited by thygate on Aug 22, 2011 - 07:23 PM; edited 3 times in total

 DocJC
 Posted: Aug 22, 2011 - 07:05 PM
 Joined: Dec 11, 2007 Posts: 6980 Location: Cleveland, OH

 hricks
 Posted: Aug 23, 2011 - 02:06 AM
 Joined: May 01, 2007 Posts: 120 Location: Minneasota
 Sampling rate is 100 Hz.

 DocJC
 Posted: Aug 23, 2011 - 04:22 AM
 Joined: Dec 11, 2007 Posts: 6980 Location: Cleveland, OH
 So, if you want 40 Hz then: F = 40 Hz T = 1/40 = 0.025 Sec Period If you sample at 100 Hz, i.e. 100 Samples/Sec, then you have 100 samples in 0.025 Sec. This is the same as taking a sample every 0.25 mSec, or every 250 uSec. It would be easiest if you divided the single period into 100 samples for your table. Make your table go from 0 to 360 degrees in 100 steps, i.e. 3.6 degrees per step. JC

 thygate
 Posted: Aug 24, 2011 - 11:48 AM
 Joined: Sep 19, 2005 Posts: 768 Location: Belgium
 I find it incredible that two people go out of their way to write you a complete explanation of how to approach things, and all you can say is "Sampling rate is 100 Hz.".

 bobgardner
 Posted: Aug 24, 2011 - 01:38 PM
 Joined: Sep 04, 2002 Posts: 21390 Location: Orlando Florida
 That means the explanation was too technical to understand. _________________Imagecraft compiler user

 thygate
 Posted: Aug 24, 2011 - 02:28 PM
 Joined: Sep 19, 2005 Posts: 768 Location: Belgium
 Aren't we all technical people here.. I personally don't think my or Doc's post was too technical to understand. All terms are relevant to the topic of synthesis.

 bobgardner
 Posted: Aug 25, 2011 - 12:42 AM
 Joined: Sep 04, 2002 Posts: 21390 Location: Orlando Florida
 Yeah, but I think the guy that doesnt get the explanation yet is hricks. Hello hricks: Is your sw development system pretty solid? Can you edit, compile, burn and run a c program in your avr? If you tell us what AVR you have, what xtal it has, whether or not it has a uart, I betcha someone would post a sample program that will output a sine wave. _________________Imagecraft compiler user

 joeyAVR
 Posted: Aug 25, 2011 - 01:22 PM
 Joined: Aug 06, 2008 Posts: 365 Location: Rockall
 I can vouch for Jesper's mini-DDS. The code works 'out of the box' and is pretty much portable to any AVR (sinewave only for small parts like tiny13). http://www.myplace.nu/avr/minidds/index.htm Here's the results I got, I was so chuffed I added an AVR to control it (instead of a PC link) using a second tiny 2313. I've since added a buffered output with level and offset controls (as per the CA3140 datasheet). _________________Cheers, Joey

 Display posts from previous:  All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Jump to: Select a forum Forum index|--[AVR (8-bit) Technical Forums]|   |-- AVR forum|   |-- XMEGA forum|   |-- AVR Wireless forum|   |-- AVR GCC forum|   |-- AVR Studio 5 and Atmel Studio 6 forum|   |-- AVR studio 4 forum|   |-- AVRfreaks Academy forum|   |-- AVR Tutorials|--[AVR Software Framework]|   |-- AVR Software Framework|--[AVR32 (32-bit) Technical Forums]|   |-- AVR32 Linux Forum|   |-- AVR32 General (standalone)|   |-- AVR32 Software Tools|   |-- AVR32 Hardware|--[General Electronics Technical Forums]|   |-- General Electronics|   |-- Atmel Security Products|--[Non-technical forums]|   |-- AVRfreaks.net Housekeeping|--[Non-topical forums]|   |-- Off-topic forum|   |-- AVRfreaks Trading Post
All times are GMT + 1 Hour