This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TLV320AIC3206: AIC 3206 high performance output not working

Part Number: TLV320AIC3206

Tool/software: Code Composer Studio

hi,

i'm trying to configure my aic3206 codec on c5545booster pack for high power high performance output mode, as per the TI example attached below. also added my code. I don't hear any output at all when i run the loopback. I want to run on 8khz sample rate

/*
 * Copyright (c) 2016, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*! \file audio_line_in_loopback_test.c
*
*   \brief Functions that configure the audio codec regsiters for the audio
*          line in loopback operation.
*
*/


#include "audio_line_in_loopback_test.h"
#include "audio_common.h"
#include "../../../build/boostC5545/audio_line_in_loopback_test/coeff"
#include <stdio.h>
#include <stdint.h>
#include <math.h>

extern TEST_STATUS AIC3206_loop_linein(void *testArgs);

/**
 *
 * \brief This function configures all audio codec registers for
 *        line in loopback test
 *
 * \param    testArgs   [IN]   Test arguments
 *
 * \return
 * \n      TEST_PASS  - Test Passed
 * \n      TEST_FAIL  - Test Failed
 *
 */
TEST_STATUS AIC3206_loop_linein(void *testArgs)
{
	    Int16 sec, msec;
	    Int16 sample;
	    Int16 data1, data2;
	    Int16 output1,output2;

	    /* Configure AIC3206 */
	    	    AIC3206_write( 0,  0x00 );  // Select page 0
	    	    AIC3206_write( 1,  0x01 );  // Reset codec
	    	    C55x_delay_msec(1);  		// Wait 1ms after reset
	    	    AIC3206_write( 0,  0x01 );  // Select page 1
	    	    AIC3206_write( 1,  0x0a );  // Disable crude AVDD generation from DVDD
	    	    AIC3206_write( 2,  0x00 );  // Enable Analog Blocks, use LDO power
	    	    AIC3206_write( 123,0x05 );  // Force reference to power up in 40ms
	    	    C55x_delay_msec(40); 		// Wait at least 40ms
	    	    AIC3206_write( 0,  0x00 );  // Select page 0

	    	    /* PLL and Clocks config and Power Up  */
	    	    AIC3206_write( 27, 0x0d );  // BCLK and WCLK are set as o/p; AIC3206(Master)
	    	    AIC3206_write( 28, 0x00 );  // Data ofset = 0
	    	    AIC3206_write( 4,  0x03 );  // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL CLK
	    	    AIC3206_write( 6,  0x07 );  // PLL setting: J=7
	    	    AIC3206_write( 7,  0x06 );  // PLL setting: HI_BYTE(D=1680)
	    	    AIC3206_write( 8,  0x90 );  // PLL setting: LO_BYTE(D=1680)
	    	    AIC3206_write( 30, 0xb0 );  // For 32 bit clocks per frame in Master mode ONLY
	    	                               	// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
	    	    AIC3206_write( 5,  0x91 );  // PLL setting: Power up PLL, P=1 and R=1
	    		C55x_delay_msec(1); 		// Wait for PLL to come up
	    		AIC3206_write( 13, 0x00 );  // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC oversamppling
	    		AIC3206_write( 14, 0x80 );  // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
	    		AIC3206_write( 20, 0x80 );  // AOSR for AOSR = 128 decimal or 0x0080 for decimation filters 1 to 6
	    		AIC3206_write( 11, 0x87 ); // Power up NDAC and set NDAC value to 7
	    		AIC3206_write( 12, 0x83 ); // Power up MDAC and set MDAC value to 12
	    		AIC3206_write( 18, 0x87 ); // Power up NADC and set NADC value to 7
	    		AIC3206_write( 19, 0x8C ); // Power up MADC and set MADC value to 12

	    		AIC3206_write( 60, 0x08 );
	    		AIC3206_write( 61, 0x01 );
	    		AIC3206_write( 63, 0xd6 );

	    	    /* DAC ROUTING and Power Up */
	    	    AIC3206_write( 0,  0x01 );  // Select page 1
	    	    AIC3206_write( 12, 0x08 );  // LDAC AFIR routed to HPL
	    	    AIC3206_write( 13, 0x08 );  // RDAC AFIR routed to HPR
	    	    AIC3206_write( 0,  0x00 );  // Select page 0
	    	    AIC3206_write( 64, 0x02 );  // Left vol=right vol
	    	    AIC3206_write( 65, 0x20 );  // Left DAC gain to 0dB VOL; Right tracks Left
	    	    AIC3206_write( 63, 0xd4 );  // Power up left,right data paths and set channel
	    	    AIC3206_write( 0,  0x01 );  // Select page 1
	    	    AIC3206_write( 16, 0x00 );  // Unmute HPL , 0dB gain
	    	    AIC3206_write( 17, 0x00 );  // Unmute HPR , 0dB gain
	    	    AIC3206_write( 9 , 0x30 );  // Power up HPL,HPR

	    		AIC3206_write( 124, 0x06 );
	    		AIC3206_write( 61, 0x00 );
	    		AIC3206_write( 71, 0x32 );
	    		AIC3206_write( 123, 0x05 );
	    		AIC3206_write( 125, 0x12 );


	    	    C55x_delay_msec(1 );        // Wait 1 msec

	    	    /* ADC ROUTING and Power Up */
	    	    AIC3206_write( 0,  0x01 );  // Select page 1
	    	    AIC3206_write( 52, 0x40 );  // STEREO 1 Jack
	    	                               	// IN2_L to LADC_P through 40 kohm
	    	    AIC3206_write( 55, 0x40 );  // IN2_R to RADC_P through 40 kohmm
	    	    AIC3206_write( 54, 0x03 );  // CM_1 (common mode) to LADC_M through 40 kohm
	    	    AIC3206_write( 57, 0x03 );  // CM_1 (common mode) to RADC_M through 40 kohm
	    	    //AIC3206_write( 59, 0x00 );  // MIC_PGA_L unmute
	    	   // AIC3206_write( 60, 0x00 );  // MIC_PGA_R unmute
	    		//AIC3206_write( 51, 0x00 );      // SetMICBIAS

	    	    AIC3206_write( 0,  0x00 );  // Select page 0
	    	    AIC3206_write( 81, 0xc0 );  // Powerup Left and Right ADC
	    	    AIC3206_write( 82, 0x00 );  // Unmute Left and Right ADc
	    	    AIC3206_write( 83, 0x00 );  // Unmute Left and Right ADC
				AIC3206_write( 84, 0x00 );  // Unmute Left and Right ADC
//				AIC3206_write( 86, 0x80 );  // L-AGC configuration
//				AIC3206_write( 94, 0x80 );  // R-AGC configuration

	    	    C55x_delay_msec(1 );        // Wait 1 msec

	    /* Initialize I2S */
	    initialise_i2s_interface();
	    gpio_interrupt_initiliastion();

	    /*Circular Buffer FIR Implementation*/
	    int AUDIO_FRAME_LEN=80000;
	    Int32 OutFrame[8000];
	    Int32 OutCircBuf[8000];
        #define fs 8000
	    int N=135;
	    int i;
	    int index1=0;
	    int index2=N;
	    Int16 x[2*135];
	    Int16 z[2*135];
	    long y1new,y2new;
	    int k=0;
	    I2S_writeLeft(0);
		I2S_writeRight(0);
		/*for(n=0;n<N;n++){
			coeff1[n]=round(coeff[n]*32);
		}*/
		 // Create audio buffer
		    static Int16 buf[80000]; // buffer
		    int n=0;
		    int a=0;                // buffer index
        	FILE *pipeout;
			pipeout=fopen("output.pcm","wb");

	           //for ( sec = 0 ; sec < 600 ; sec++ )
		       while(1)
	    	    {
	    	        for ( msec = 0 ; msec < 1000 ; msec++ )
	    	        {
	    	            for ( sample = 0 ; sample < 8 ; sample++ )
	    	            {
	    	                // Read 16-bit left channel Data
	    	            	I2S_readLeft(&data1);

	    	                // Read 16-bit right channel Data
	    	                I2S_readRight(&data2);


	    	                // As a new sample is received put it in two places
	    	                x[index1] = data1;
	    	                x[index2] = data1;
	    	                z[index1] = data2;
	    	                z[index2] = data2;
	    	                y1new=0;
	    	                y2new=0;
	    	                for(i=0;i<N;i++){
	    	                y1new = y1new + (long)coeff[i]*x[index2-i];
	    	                y2new = y2new + (long)coeff[i]*z[index2-i];
	    	                }

	    	                index1 = (index1+1)%N;
	    	                index2 = index1+N;

                            output1=y1new>>15;
                            output2=y2new>>15;

                            if(a<AUDIO_FRAME_LEN){
                            	OutFrame[a]=output1;
                            }

                           /*if(n<80000){
                            buf[n]=output2;
                            n=n+1;
                           }*/

	    	                // Write 16-bit left channel Data
	    	                I2S_writeLeft(data1);

	    	                // Write 16-bit right channel Data
	    	                I2S_writeRight(data2);
	    	            }
	    	            if(sw3Pressed == TRUE)
	    	            {
	    	            	/*FILE *pipeout;
	    	            	    //pipeout = popen("ffmpeg -y -f s16le -ar 8000 -ac 1 -i - test.wav", "w");
	    	            	pipeout=fopen("output.pcm","w");
	    	            	    fwrite(buf, 2, 1, pipeout);
	    	            	    fclose(pipeout);*/
	    	            	break;
	    	            }

	    	        }
	                if(sw3Pressed == TRUE)
	                {

	                	break;
	                }

	    	    }
				//fwrite(buf, 2, 80000, pipeout);
		       for (i=0; i<AUDIO_FRAME_LEN; i++)
		       {
		       OutCircBuf[AUDIO_FRAME_LEN+i] = OutFrame[i];
		       }
	           fclose(pipeout);
	    /* Play Loop for 5 seconds */

	  /*  for ( sec = 0 ; sec < 500 ; sec++ )
	    {
	        for ( msec = 0 ; msec < 1000 ; msec++ )
	        {
	            for ( sample = 0 ; sample < 16 ; sample++ )
	            {
	                 Read 16-bit left channel Data
	            	I2S_readLeft(&data1);
	                 Read 16-bit right channel Data
	                I2S_readRight(&data2);

	                 Write 16-bit left channel Data
	                I2S_writeLeft(data1);

	                 Write 16-bit right channel Data
	                I2S_writeRight(data2);
	            }
	            if(sw3Pressed == TRUE)
	            {
	            	break;
	            }

	        }
            if(sw3Pressed == TRUE)
            {
            	break;
            }

	    }*/
	    I2S_close(hI2s);    // Disble I2S
	    AIC3206_write( 1, 0x01 );  // Reset codec

	    return 0;
}

/**
 *
 * \brief This function used to initialise i2c interface and run
 *        audio line in loopback test
 *
 * \param    testArgs   [IN]   Test arguments
 *
 * \return
 * \n      TEST_PASS  - Test Passed
 * \n      TEST_FAIL  - Test Failed
 *
 */
static TEST_STATUS run_audio_line_in_loopback_test(void *testArgs)
{
	 Int16 retVal;
	 Uint8  c = 0;

	 /* Enable clocks to all peripherals */
	 CSL_SYSCTRL_REGS->PCGCR1 = 0x0000;
	 CSL_SYSCTRL_REGS->PCGCR2 = 0x0000;

	 retVal =  SYS_setEBSR(CSL_EBSR_FIELD_PPMODE,
			               CSL_EBSR_PPMODE_1);    // Configure Parallel Port for I2S2
	 retVal |= SYS_setEBSR(CSL_EBSR_FIELD_SP1MODE,
	                          CSL_EBSR_SP1MODE_1);  // Serial Port mode 1 (I2S1 and GP[11:10]).

	 retVal = initialise_i2c_interface(testArgs);
	 if(retVal != 0)
	 {
		 C55x_msgWrite("I2C initialisation failed\n\r");
		 return (TEST_FAIL);
	 }

	 C55x_msgWrite( "Test Receives audio samples from LINE IN and output the same\n\r"
			        "on HEADPHONE port\n\n\r");

	 C55x_msgWrite("Connect headset to the HEADPHONE port of the BoosterPack\n\n\r");
	 C55x_msgWrite("Connect a LINE-IN cable between the audio port of the\n\r"
			       "Test PC and LINE IN of the BoosterPack\n\n\r");

	 C55x_msgWrite("Play any audio file from the Test PC and Check \n\r"
			       "Audio from the headset connected to BoosterPack\n\n\r");

	 retVal = AIC3206_loop_linein(testArgs);
	 if(retVal != 0)
	 {
		 return (TEST_FAIL);
	 }

#ifdef USE_USER_INPUT

	 C55x_msgWrite("Press Y/y if the Audio stream from LINE IN is\n\r"
			       "observed at the headset connected to HEADPHONE port,\n\r"
			       "any other key for failure:\n\r");

	 C55x_msgRead(&c, 1);
	 if((c != 'y') && (c != 'Y'))
	 {
		 C55x_msgWrite("Audio Loopback from LINE IN to the HEADPHONE port\n\r"
				       "is not proper\n\r");
		 return (TEST_FAIL);
	 }
#endif

	 return (TEST_PASS);

}

/**
 *
 * \brief This function performs audio line in loopback test
 *
 * \param    testArgs   [IN]   Test arguments
 *
 * \return
 * \n      TEST_PASS  - Test Passed
 * \n      TEST_FAIL  - Test Failed
 *
 */
 TEST_STATUS audioLineInLoopbackTest(void *testArgs)
 {
     TEST_STATUS testStatus;

     C55x_msgWrite("\n*******************************************\n\r");
     C55x_msgWrite(  "        AUDIO LINE IN LOOPBACK TEST    \n\r");
     C55x_msgWrite(  "*******************************************\n\r");

     testStatus = run_audio_line_in_loopback_test(testArgs);
     if(testStatus != TEST_PASS)
     {
     	C55x_msgWrite("\nAudio LINE IN Loopback Test Failed!\n\r");
     	return (TEST_FAIL);
     }
     else
     {
     	C55x_msgWrite("\nAudio LINE IN Loopback Test Passed!\n\r");
     }

     C55x_msgWrite("\nAudio LINE IN Loopback Test Completed!!\n\r");

     return testStatus;

 }

8322.Playback-Recording(8KHz).cfg

note:- don't follow the comments in my code, they were default comments and i didn't change according to my settings.

  • Hi can someone look into my code and correct the configuration settings to use the aic3206 at high power high performance setting with 8khz sample rate. Also i want to enable the charge pump to get that extra output gain. Thanks

  • Hi, V Pot,

    The script you mention is the same I sent before, right?. It should work properly with the device as I have tested it on my end before, so the issue should not be related to that code unless the clocks have changed or there is another routing configuration on the end-system.

    What is the process you follow and register settings for the loopback test?, it seems to be a routine on the code, but it is no clear which registers are being programmed. Also, there is no change or setting done to the loopback control register of the device. 

    Best Regards,

      -Diego Meléndez López
       Audio Applications Engineer

  • Hi diego,

    1) yes that’s the code you provided me. What do you mean the clocks are changed?  I just used the values from your code. Also in your code i saw a bug, look for AOSR and DOSR settings both have same register number which can’t be

    2) as shown your code is in assembly hex format for register, its value. In my code the format is aic3206(register number in decimal, register value in hex), that is how the loopback test.c file is written by default in Ti demos.

    3) i dont know how to use .cfg directly with the .c file. If you can instruct that would be great.

    4) also looks like your code is for recording right? I want the settings for loopback

    5) does your code also enable that charge pump to get that extra 0.5mw gain in output?

  • Hi diego,
    Did you get my above concerns?
  • Hi, V Pot,

    Thanks for the feedback.

    I think we need to clarify the test you are performing. the AIC3206 has a loopback feature which can be seen in two ways, one is a direct connection between ADC and DAC and the other is a loopback between DIN and OUT. I am not familiar with the code you are sharing or the loopback test you are trying to do,but looking at the code it seems the AIC3206 should be configured for the ADC-DAC loopback. for this, you need to set bit D4 of Page 0 / Register 29 as '1'.  

    The script I provided was for playback and recording, and it actually has the charge pump enabled.

    Best Regards,

      -Diego Meléndez López
       Audio Applications Engineer

  • Diego,

    -The loopback test I’m performing, takes input from line in jack meaning ADC and output is heard from headphone jack meaning DAC i guess.

    -what about the bug I mentioned in the code setting you provided, in my above post for AOSr dosr having same register number

  • V Pot,

    Thanks for the feedback. If the loopback is as you mention, it is required to configure the register I pointed out in my previous response. Regarding the AOSR and DOSR issue, you are right, I may have fixed it in the GUI while doing the test but didn't updated the script, sorry for that.

    Regards,

    -Diego Meléndez López
    Audio Applications Engineer

  • Hi diego,

    -so just the register you said should be changed and rest in place?

    -also can you please provide right aosr dosr register numbers and their values again.

    Thanks

  • HI, V Pot,

    Assuming the loopback test function only requires the ADC to be connected to the DAC and hear audio from the source through the headphone outputs, yes, the register i mention should be programmed and he test should work. As mentioned before, I am not familiar with the test from the code you are using; as it seems to be used with a booster pack, it is possible that my colleagues of the C5545 group know more about this.  

    The right AOSR and DOSR settings based on the code I shared before should be:


    ###############################################
    # Clock Settings (Master mode, 24-bit data)
    # ---------------------------------------------
    # The codec receives: MCLK = 12MHz
    # Generates: BLCK = 256KHz = 32×Fs, WCLK = 8kHz
    ###############################################
    #
    # Select Page 0
    w 30 00 00
    #
    # AOSR = 128
    w 30 14 00 80
    #
    # DOSR = 512
    w 30 0d 02 00
    #
    ###############################################

    Best Regards,

      -Diego Meléndez López
       Audio Applications Engineer

  • diego,

    as you suggested i tried

    AIC3206_write( 29,  0x01 ); and it didn't work.

    can you loop c5545booster pack guys in to convert your hex code to the c code i'm using. when i contacted c5545 team in first place they suggested to talk to you guys regarding the chargepump and noise issues.

    please escalate this issue as it is not resolved for so long now. tag c5545 guys to this thread as i've already converted your code to the c format that i need, they can debug if there is any issue. thanks

    please make it happen asap