code: making a sine wave from an 8051

Status
Not open for further replies.

bajgik

New Member
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
 
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.
 
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:
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.
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…