Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
ConRoY1105
PostPosted: Feb 22, 2012 - 08:43 PM
Newbie


Joined: Feb 22, 2012
Posts: 1


Here's exactly what I need to do:

Write a program in assembly language that will read 256 values of the sine of an angle from zero to ninety degrees and write those values to the DAC (digital to analog converter) for export to a port so that the resulting sine wave can be displayed on an oscilloscope. Create a variable for frequency that will cause the frequency of the resulting sine wave to be varied from 10-1000 Hz.

We're using the ATmega16 board.

I have absolutely NO idea where to start, I need a few pointers to get started.

Thanks.
 
 View user's profile Send private message  
Reply with quote Back to top
dksmall
PostPosted: Feb 22, 2012 - 08:49 PM
Raving lunatic


Joined: Apr 16, 2001
Posts: 3522
Location: Phoenix, Arizona

This looks like a class assignment. What has the instructor given you for pointers, notes, etc?
Have you written AVR assembly before?
When you say "read 256 values", read from what? RAM, ROM base table?
Since an AVR doesn't have a DAC, I'm assuming an external one is being used. Do you have a library for the DAC you can use, or do you need to write the code for that as well?
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Feb 22, 2012 - 08:54 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25921
Location: Wisconsin USA

Quote:

I need a few pointers to get started.


First, let's do some quick calculations...

256 points per quadrant; four quadrants per sine wave cycle. Let's call it 1000 outputs per cycle.
Max output frequency 1000Hz. That means 1 million DAC updates per second. At 16MHz, that gives you 16 AVR cycles per update.

Probably not feasible. However you don't need anywhere near 256 points per quadrant.

Is this a homework assignment? Then you shouldn't read that if you Google "minidds jesper" it is already done for you.

The starting point is to search these forums and the projects section of this site for "dds" and "minidds" and start doing your research.

Lee
 
 View user's profile Send private message  
Reply with quote Back to top
petenz123
PostPosted: Feb 22, 2012 - 08:56 PM
Wannabe


Joined: Mar 20, 2006
Posts: 65
Location: New Zealand

ConRoY1105 wrote:


I have absolutely NO idea where to start, I need a few pointers to get started.

Thanks.


They are supposed to teach you the basics, then give you an assignment like this to test how well you understood it.

They shouldn't be giving you the assignment without teaching you first - it's their job!

If they didn't teach you how to use the software, (AVRStudio etc), and help you through a few simple exercises (blinking LED etc), then you should go to your student support complaints person, and tell them that your teacher is too lazy to teach you anything.
 
 View user's profile Send private message  
Reply with quote Back to top
DocJC
PostPosted: Feb 22, 2012 - 08:58 PM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6849
Location: Cleveland, OH

Welcome to the forum.

Sounds like a fun project, (except for that part about doing it in Assembly Language Wink ).

This sounds like a class assignment, how much time do you have?

Stu_san's Newbie? Start Here! is a great source of info and links.

This Thread has some general thoughts on signal generation.

This Thread discusses using the DDS, Direct Digital Synthesis, approach to signal generation. It includes a link to Jesper's DDS, which will be of interest to you.

These should help get you started.

JC

Edit: Do you have access to Elekto Magazine? AVR Freak Ossi just published an article in the March 2012 edition on using an AVR to construct a DDS signal generator.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Koshchi
PostPosted: Feb 22, 2012 - 09:45 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13845
Location: Vancouver, BC

Quote:
256 points per quadrant
The OP said 256 values. I take that to mean per cycle, not per quadrant (but this should give the OP the hint that you don't need values for the whole cycle).

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
theusch
PostPosted: Feb 22, 2012 - 10:03 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25921
Location: Wisconsin USA

Quote:

The OP said 256 values. I take that to mean per cycle, not per quadrant

You took it that way, eh? Then why did OP say:
Quote:

256 values of the sine of an angle from zero to ninety degrees


Twisted Evil Lee
 
 View user's profile Send private message  
Reply with quote Back to top
DocJC
PostPosted: Feb 23, 2012 - 12:01 AM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6849
Location: Cleveland, OH

Quote:
First, let's do some quick calculations...


Well,
I'm better at calculating i.v. drip rates than Delta Phase Accumulator values, but:

The stated spec did not state that each value in the table is to be used in the generation of the output signal. In fact, that's the hallmark of the DDS approach, you skip over samples in the table as one determines the next value to be stuffed in the DAC on the next occurrence of the DAC stuffing ISR.

So, one could have a table of 1024 entries and still make this work, although as stated above that is a lot more samples than one needs for a generic, low frequency, sin wave.

If one's DAC stuffing ISR rate was 100 K / Second, then the Delta Phase for a 1 KHz sin would be 10.24, giving 100 samples/period in the output waveform.

The Delta Phase for a 10 KHz sin would be 102.4, giving 10 samples/period in the output waveform.

The Delta Phase is equal to the number of samples to advance in the table on each interrupt.

Unfolding the 0-90 degrees table to a full 0-360 degree table would decrease the number of calculations one had to make between each DAC stuffing ISR interrupt.

OP:
I'd start this process, in addition to reading the above links, by writing the program in whatever language you are most familiar with, C or whatever.

After you have done a lot of reading, and made lots of sketches of sin waves on paper, and have an algorithm in your mind, it will be easier to debug your algorithm and get it working.

Then I'd work on taking your known working system and converting it to Assembly Language.

Last suggestion:
I'd go to Analog Devices web page and download the data sheet for several of their DDS chips. They include a description of the DDS technique, which you can then use to help understand the underlying concepts behind the DDS approach. IIRC there is also an Analog Devices Application Note on the DDS technique, which is another resource.

Just my two cents.

JC
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
theusch
PostPosted: Feb 23, 2012 - 01:56 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25921
Location: Wisconsin USA

Quote:

The stated spec did not state that each value in the table is to be used in the generation of the output signal.

No, but it certainly implied it.

And I followed immediately with suggestions to look at DDS.
 
 View user's profile Send private message  
Reply with quote Back to top
dksmall
PostPosted: Feb 23, 2012 - 03:26 PM
Raving lunatic


Joined: Apr 16, 2001
Posts: 3522
Location: Phoenix, Arizona

I think you guys scared off the OP again.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 23, 2012 - 03:43 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21267
Location: Orlando Florida

The moment of learning when you have no idea how to do it, is to have somebody show you how to do it. Being told to read the data sheet and a c book and the wikipedia article on direct digital synthesis is just too academic. How about a compilable example in c?


Last edited by bobgardner on Feb 23, 2012 - 04:57 PM; edited 1 time in total
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
smileymicros
PostPosted: Feb 23, 2012 - 04:51 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

dksmall wrote:
I think you guys scared off the OP again.
More likely they gave him the start he requested and he's off reading suggested materials.

Smiley

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
theusch
PostPosted: Feb 23, 2012 - 05:22 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25921
Location: Wisconsin USA

Quote:

How about a compilable example in c?

Hmmm, interesting.

IF I WERE TO TAKE Jesper's miniDDS and make a C version, the naive version would not be able to get close to those data rates.

If I were to make a "fast" C version, then I'd flip the program around and have it poll the timer flag in a hard loop and do the DDS. When an interrupt occurs (e.g. the "stop" button I wouldn't return to the loop but rather to the "start over" point. This would save several cycles in the DDS loop. Let's say 2 cycles and the loop is 20 cycles long--that would give 10% improvement.

But why bother? If I wanted to do it for real, then I'd make it my first Xmega project and use DMA and get much greater speed. Probably with the real DAC.

But I lost interest totally in the Xmega during the years waiting for solid silicon. Now if I wanted to do it I'd make it a Cortex learning project.
 
 View user's profile Send private message  
Reply with quote Back to top
Simonetta
PostPosted: Feb 23, 2012 - 05:25 PM
Resident


Joined: Mar 12, 2003
Posts: 979
Location: Portland, Oregon USA

The sine of an angle between 0 and 90 degrees is the ratio of the opposite to the hypotenuse. Its value ranges between 0 and 1. Since you are working in assembler, use byte values for simplicity. The sine value for each of the 256 steps is for 0.35 degrees (90/256). This will be an eight bit value. Since your teacher didn't specify how accurate the sine should be, eight bits will do well. So at 0 degrees the first value in the sine table is 0x00 and at 90 degrees the sine value is 0xff. At 45 degrees the sine will be 256*0.707 or 0xb5. There will be a new value for every 0.35 degrees. Many of the values will be the same as the previous value due to the lack of precision resulting from using 8-bit resolution.
When the base256 values for the first quadrant are completed, they can be reflected and complemented for the other three quadrants.
Depending on whether your DAC can output negative voltages, you may need to scale the values by 50% and add an offset of 0.5 DAC max positive voltage.
If you don't know what I'm talking about, then you and your teammates need to all skip a few beers and spend the money on a tutor for a few hours to explain it all in enough detail to get your project on track. It can be done and it is not too difficult once you get a grasp of the basic principals involved.
Best of luck.
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Feb 24, 2012 - 01:13 AM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21267
Location: Orlando Florida

try this

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits