sin wave output

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sin wave output

286 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by volter on Sat Jan 08 11:38:17 MST 2011
Can I output sin wave in some pin using clock or something at 256KHz?

LPC1343 expresso
0 Kudos
Reply
1 Reply

249 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jimgi on Sun Jan 09 08:49:41 MST 2011
You can use a lookup table, and output the result to a port and use a D/A converter - or use an internal D/A converter.
The following is a software implementation of a Numerically Controlled Oscillator (NCO)
Changing the value of the Phase Increment will alter the frequency of the sine wave output.  Not sure if you can get >200Khz though...
You will also need to put a low-pass filter on the output.


// Global variables.
unsigned char Phase_Acc=0;
unsigned char Phase_Inc=0x0f;
unsigned char Output=0;

// Sine lookup table

const char sine_table[256]={
0x80,0x83,0x86,0x89,0x8C,0x90,0x93,0x96,
0x99,0x9C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,
0xB1,0xB4,0xB7,0xB9,0xBC,0xBF,0xC2,0xC4,
0xC7,0xC9,0xCC,0xCE,0xD1,0xD3,0xD6,0xD8,
0xDA,0xDC,0xDE,0xE1,0xE3,0xE5,0xE6,0xE8,
0xEA,0xEC,0xED,0xEF,0xF0,0xF2,0xF3,0xF5,
0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFC,
0xFD,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,
0xFD,0xFC,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,
0xF6,0xF5,0xF3,0xF2,0xF0,0xEF,0xED,0xEC,
0xEA,0xE8,0xE6,0xE5,0xE3,0xE1,0xDE,0xDC,
0xDA,0xD8,0xD6,0xD3,0xD1,0xCE,0xCC,0xC9,
0xC7,0xC4,0xC2,0xBF,0xBC,0xB9,0xB7,0xB4,
0xB1,0xAE,0xAB,0xA8,0xA5,0xA2,0x9F,0x9C,
0x99,0x96,0x93,0x90,0x8C,0x89,0x86,0x83,
0x80,0x7D,0x7A,0x77,0x74,0x70,0x6D,0x6A,
0x67,0x64,0x61,0x5E,0x5B,0x58,0x55,0x52,
0x4F,0x4C,0x49,0x47,0x44,0x41,0x3E,0x3C,
0x39,0x37,0x34,0x32,0x2F,0x2D,0x2A,0x28,
0x26,0x24,0x22,0x1F,0x1D,0x1B,0x1A,0x18,
0x16,0x14,0x13,0x11,0x10,0x0E,0x0D,0x0B,
0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x04,
0x03,0x02,0x02,0x01,0x01,0x01,0x01,0x01,
0x00,0x01,0x01,0x01,0x01,0x01,0x02,0x02,
0x03,0x04,0x04,0x05,0x06,0x07,0x08,0x09,
0x0A,0x0B,0x0D,0x0E,0x10,0x11,0x13,0x14,
0x16,0x18,0x1A,0x1B,0x1D,0x1F,0x22,0x24,
0x26,0x28,0x2A,0x2D,0x2F,0x32,0x34,0x37,
0x39,0x3C,0x3E,0x41,0x44,0x47,0x49,0x4C,
0x4F,0x52,0x55,0x58,0x5B,0x5E,0x61,0x64,
0x67,0x6A,0x6D,0x70,0x74,0x77,0x7A,0x7D
};

char *LUT_Add;

/*****************************************************************************/
/*                          Main Program Start                               */
/*****************************************************************************/

// Hardware intialisation section.

void main()
{
// Hardware intialisation section.
// PortB in this case is an 8-bit output port (another MPU example)

// Set up required port here...

// Infinite NCO loop - increment the phase register and output.

while (1)
{
Phase_Acc+=Phase_Inc;
LUT_Add=&sine_table[Phase_Acc];
PORTB=*LUT_Add;
}


}    // End of Main.

I hope that this is in line with what you need...or are you looking for something more exotic?
jimgi
0 Kudos
Reply