Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
LinkBack Thread Tools Display Modes
Old 3rd May 2006, 08:50 PM   (permalink)
Smile code: making a sine wave from an 8051

hi all,

can you please help me how to make a sine wave from a micro controller, 8051 using! If it is a problem to make the negative cycle, can you tell me how to make at least the Positive sine wave cycle. any codes are welcomed
bajgik is offline  
Old 3rd May 2006, 09:06 PM   (permalink)
Default

Perhapps this should've been posted microcontrollers section.

What programming language are you using?

It should be fairly easy using basic or C.

Does this micro have a FPU?

If not then you'll need an emulator or a library, which might be too slow to generate a sinewave of any usable frequency, but there again there are tricks like look-up tables but I'm no professional programmer, I only know BASIC.
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.
Hero999 is offline  
Old 3rd May 2006, 09:59 PM   (permalink)
Default

Use Excel to compute the sin function and scale the floating point values to the nearest integer to create a table of values. Export the data as a .CSV file. If you are clever with the setup of the spreadsheet you can paste the .CSV output right into your source file and have the compiler generate the table.

Pick a time increment, fetch a value from the table and write the output to a DAC or a PWM. However long it takes to run through the table will determine the frequency of the output.

Last edited by Papabravo; 4th May 2006 at 01:16 AM.
Papabravo is offline  
Old 3rd May 2006, 10:09 PM   (permalink)
Default

The answer is to use a lookup table, which is what Papabravo actually explained, there's no need for anything difficult on the micro-controller, generate the table on a PC and the micro just reads it.

As suggested, you could use Excel, but even a DOS BASIC does it easily.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 3rd May 2006, 10:55 PM   (permalink)
Default

Good idea.

Or try OpenOffice Calc.
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.
Hero999 is offline  
Old 4th May 2006, 02:44 AM   (permalink)
Default

and with a small amount of cleverness, you can keep the table to 1/4 of the cycle.

this is where a micro with DMA and a DAC can come in handy.

by the way, the technique is called direct digital synthesis (DDS). googling "DDS PIC" gets lots of hits.
philba is offline  
Old 4th May 2006, 05:54 AM   (permalink)
Default

You can have a -ve cycle by having a capacitor to block the DC levels at the output od your DAc.
__________________
Bharath Bhushan Lohray.
M.Sc. Electronics.
lord loh. is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 09:45 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

eXTReMe Tracker