Part Number: TMS320C6748
Other Parts Discussed in Thread: OMAP-L138
Hi Expert,
I am posting this on behalf of the customer. Here is the inquiry below.
I am unable to get the expected result. I am actually trying to get a sinewave output at the Lineout port of LCDKC6748 using the Aic31 codec and represent the data in the oscilloscope. I am attaching my code here. Could you please help me with the code and whether I need to change anything or not to get the output?
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include "lcdkC6748.h"
#include "aic31.h"
#include "Aic31_.h"
#define SAMPLE_RATE 48000
#define PI 3.14159265358979323846
#define Aic31_AC_IOCTL_REG_WRITE
uint32_t i;
void generateSineWave(float *buffer, uint32_t length, float frequency, float amplitude) {
float deltaPhase = 2.0 * PI * frequency / SAMPLE_RATE;
float phase = 0.0;
for (i = 0; i < length; i++) {
buffer[i] = sinf(phase) * amplitude;
phase += deltaPhase;
}
}
void storeArrayInRegister(float *array, uint32_t length) {
/* Assuming we have a 32-bit register available */
volatile uint32_t *registerPtr = (volatile uint32_t *)0xc0000000; // Replace 'address' with the actual register address
for (i = 0; i < length; i++) {
float value = array[i];
*registerPtr = *(uint32_t *)&value; // Store the array value in the register
registerPtr++; // Move to the next register location
}
}
int main() {
// initiating variables
unsigned int baseAdd=0xc0000000;
unsigned int mode=0xFFu;
/* Initialize the LCDK board
void BSP_Init(void);
/* Initialize the AIC31 codec */
AIC31DACInit(baseAdd);
AIC31ADCInit(baseAdd);
/* Configure the AIC31 codec */
AIC31Reset(baseAdd);
AIC31SampleRateConfig(baseAdd,mode,SAMPLE_RATE);
/* Generate a sine wave with a frequency of 1kHz and amplitude of 0.5 */
uint32_t numSamples = 24000; // 1 second at 48kHz sample rate
float audioBuffer[numSamples];
generateSineWave(audioBuffer, numSamples, 1000.0, 0.5);
storeArrayInRegister(audioBuffer, numSamples);
/* Output the sine wave to the AIC31 codec */
while (1) {
for (i = 0; i < numSamples; i++) {
while (!Aic31_AC_IOCTL_REG_WRITE(audioBuffer[i])); // Wait for AIC31 codec to be ready
}
}
}
Thank you in advance!
Best regards,
Jonathan