We have developed MSP430FG437 based sine wave generator using sine table.
// This is the working code
#include <msp430fg437.h>
#include <math.h>
void DAC0_Initial(void);
float sine_value[] = {0.00000, 0.08715, 0.17364, 0.25881,
0.34202, 0.42261, 0.50000, 0.57357,
0.64278, 0.70710, 0.76604, 0.81915,
0.86602, 0.90630, 0.93969, 0.96592,
0.98480, 0.99619, 1.00000, 0.99619,
0.98480, 0.96592, 0.93969, 0.90630,
0.86602, 0.81915, 0.76604, 0.70710,
0.64278, 0.57357, 0.50000, 0.42261,
0.34202, 0.25881, 0.17364, 0.08715,
0.00000, -0.087155, -0.17364, -0.25881,
-0.34202, -0.422618, -0.50000, -0.57357,
-0.64278, -0.707106, -0.76604, -0.81915,
-0.86602, -0.906307, -0.93969, -0.96592,
-0.98480, -0.996194, -1.00000, -0.99619,
-0.98480, -0.965925, -0.93969, -0.90630,
-0.86602, -0.819152, -0.76604, -0.70710,
-0.64278, -0.573576, -0.50000, -0.42261,
-0.34202, -0.258819, -0.17364, -0.08715,
};
void main(void)
{
int j;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DAC0_Initial();
j=0;
while(1)
{
DAC12_0DAT = (int)(2047*sine_value[j++])+ 2048;
j = j%72;
}
}
void DAC0_Initial()
{
ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on
DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Internal ref gain 1
DAC12_0DAT = 0x0800;
}