Other Parts Discussed in Thread: OMAPL138
Tool/software: Code Composer Studio
Hi,
I am using OMAPL138_LCDK with Code Composer Studio 5.5.0 . I am facing a problem with sine wave generation . I have tried using Look Up Table and inbuilt 'sin' function. Neither of them gave proper sine wave. The compiler I am using is C6000. The codes I have used are:
USING LOOK UP TABLE:
#include "L138_LCDK_aic3106_init.h"
#define LOOPLENGTH 100
#define BUFLENGTH 256
int16_t sine_table[LOOPLENGTH] =
{0,63,125,187,249,309,368,426,482,536,588,637,685,729,771,809,844,876,905,930,951,969,982,992,998,1000,998,992,982,969,951,930,905,876,844,809,771,729,685,637,588,536,482,426,368,309,249,187,125,63,0,-63,-125,-187,-249,-309,-368,-426,-482,-536,-588,-637,-685,-729,-771,-809,-844,-876,-905,-930,-951,-969,-982,-992,-998,-1000,-998,-992,-982,-969,-951,-930,-905,-876,-844,-809,-771,-729,-685,-637,-588,-536,-482,-426,-368,-309,-249,-187,-125,-63};
int16_t sine_ptr = 0; // pointer into lookup table
int32_t buffer[BUFLENGTH];
int16_t buf_ptr = 0;
interrupt void interrupt4(void) // interrupt service routine
{
int16_t sample;
sample = sine_table[sine_ptr]; // read sample from table
output_left_sample(sample); // output sample
sine_ptr = (sine_ptr+1) %LOOPLENGTH; // increment table index
buffer[buf_ptr] = (int32_t)(sample); // store sample in buffer
buf_ptr = (buf_ptr+1) %BUFLENGTH; // increment buffer index
return;
}
int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}
USING SIN Function:
#include "L138_LCDK_aic3106_init.h"
#include "math.h"
#define SAMPLING_FREQ 8000
#define PI 3.14159265358979
float frequency = 1000.0;
float amplitude = 20000.0;
float theta_increment;
float theta = 0.0;
interrupt void interrupt4(void) // interrupt service routine
{
theta_increment = 2*PI*frequency/SAMPLING_FREQ;
theta += theta_increment;
if (theta > 2*PI) theta -= 2*PI;
output_left_sample((int16_t)(amplitude*sin(theta)));
return;
}
int main(void)
{
L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}
OUTPUT:
Both the codes are giving the same output. Please help me where I am going wrong because both programs are working fine in MATLAB. Also help me with setting the parameters for the graph tool.
Thank you in advance.