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.

TMS320C5505: TMS320C5505 USB Stick

Part Number: TMS320C5505

How to generate 1mv sine wave on TMS320C5505 USB Stick.

What changes should i do in the files below to generate 1mv sine wave signal.

/*****************************************************************************/
/*                                                                           */
/* FILENAME                                                                  */
/*   sinewaves.c                                                             */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   Sinewave generation for the TMS320C5505 USB Stick.                      */
/*                                                                           */
/*   Generates two sinewaves of adjustable frequency using sine() function   */
/*   in 55xdsph.lib                                                          */
/*                                                                           */
/*   The frequency of range of the sine wave is 10 Hz to 8000 Hz.            */
/*                                                                           */
/* REVISION                                                                  */
/*   Revision: 1.00                                                          */
/*   Author  : Richard Sikora                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* HISTORY                                                                   */
/*                                                                           */
/*   Revision 1.00                                                           */
/*   20th December 2009. Created by Richard Sikora from TMS320C5510 code.    */
/*                                                                           */
/*****************************************************************************/
/*
 *
 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 
 * 
 * 
 *  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.
 *
*/

#include "tms320.h"
#include "dsplib.h"

/*****************************************************************************/
/* generate_sinewave_1()                                                     */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* Generate a sinewave. Based on sampling rate of 48000 Hz.                  */
/*                                                                           */
/*                                                                           */
/* PARAMETER 1: The frequency of the sinewave between 10 Hz and 16000 Hz.    */ 
/* PARAMETER 2: The maximum amplitude of the sinewave between 1 to 32767.    */
/*                                                                           */
/*****************************************************************************/

signed int generate_sinewave_1( signed short int frequency, 
                                signed short int amplitude)
{
 short int sinusoid;
 signed long result;
 static short int count = 0;
 
 /* Multiply frequency by scaling factor of 32767 / 48000 */
 
 result = ( (long)frequency * 22368 ) >> 14 ;
 
 if ( result > 32767)
   {
     result = 32767; /* Maximum value for highest frequency */
   }
 else if ( 0 == result)  
   {
     result = 1;     /* Minimum value for lowest fequency */
   }
 else if ( result < -32767)
   {
     result = -32767;
   }  
 
 count += (short int) result; 
 
 /* Obtain sine of input */

 sine ( &count, &sinusoid, 1);

 if ( amplitude > 32767 )
   {
     amplitude = 32767; /* Range limit amplitude */
   } 

 /* Scale sine wave to have maximum value set by amplitude */

 result =  ( (long) sinusoid * amplitude ) >> 15;
 
 return ( (signed int ) result );
}

/*****************************************************************************/
/* generate_sinewave_2()                                                     */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* Generate a second sinewave.                                               */
/*                                                                           */
/*                                                                           */
/* PARAMETER 1: The frequency of the sinewave between 10 Hz and 16000 Hz.    */ 
/* PARAMETER 2: The maximum amplitude of the sinewave between 1 to 32767.    */
/*                                                                           */
/*****************************************************************************/

signed int generate_sinewave_2( signed short int frequency, 
                                signed short int amplitude)
{
 short int sinusoid;
 signed long result;
 static short int count = 0;
 
 /* Multiply frequency by scaling factor of ratio 32767 / 48000 */
 
 result = ( (long) frequency * 22368 ) >> 14 ;
 
 if ( result > 32767)
   {
     result = 32767; /* Maximum value for highest frequency */
   }
 else if ( 0 == result)  
   {
     result = 1;     /* Minimum value for lowest fequency */
   }
 else if ( result < -32767)
   {
     result = -32767;
   }  
 
 count += (signed int) result; 
 
 /* Obtain sine of input */

 sine ( &count, &sinusoid, 1);

 if ( amplitude > 32767 )
   {
     amplitude = 32767; /* Range limit amplitude */
   } 

 /* Scale sine wave to have maximum value set by amplitude */

 result =  ( (long) sinusoid * amplitude ) >> 15;
 
 return ( (signed int ) result );
}

/******************************************************************************/
/* End of sinewaves.c                                                         */
/******************************************************************************/

/*****************************************************************************/
/*                                                                           */
/* PROJECT                                                                   */
/*   Sinewaves                                                               */
/*                                                                           */
/* FILENAME                                                                  */
/* 	 main.c                                                                  */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   TMS320C5505 USB Stick Application 4. Generating sine waves.             */
/*   Generating sinewaves of variable frequency using DSPLIB.                */
/*                                                                           */
/* REVISION                                                                  */
/*   Revision: 1.00	                                                         */
/*   Author  : Richard Sikora                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* HISTORY                                                                   */
/*                                                                           */
/*   Revision 1.00                                                           */
/*   1st March 2010. Original template code Spectrum Digital.                */
/*                                                                           */
/*   Revision 1.01                                                           */
/*   5th August 2010. Converted to use CSL.                                  */
/*                                                                           */
/*****************************************************************************/
/*
 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 
 * 
 * 
 *  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.
 *
*/

#include "stdio.h"
#include "usbstk5505.h"
#include "aic3204.h"
#include "PLL.h"
#include "sinewaves.h"


Int16 left_input;
Int16 right_input;
Int16 left_output;
Int16 right_output;


#define SAMPLES_PER_SECOND 48000
#define GAIN_IN_dB         0

unsigned long int i = 0;


/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  main( )                                                                 *
 *                                                                          *
 * ------------------------------------------------------------------------ */
void main( void ) 
{
    /* Initialize BSL */
    USBSTK5505_init( );
    
    /* Initialize the Phase Locked Loop in EEPROM */
    pll_frequency_setup(100);

    /* Initialise hardware interface and I2C for code */
    aic3204_hardware_init();
    
    /* Initialise the AIC3204 codec */
	aic3204_init(); 

 
	/* Set sampling frequency in Hz and ADC gain in dB */
    set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);

    printf("\nRunning Sinewaves Project\n\n");
    printf( "Sinewave 250Hz on left HP output, 1000Hz on right HP output\n\n" );
	
    asm(" bclr XF");
   
 	for ( i = 0  ; i < SAMPLES_PER_SECOND * 600L  ;i++  )
 	{

     aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.
   
     left_output = generate_sinewave_1(250, 10000);   // Sinewave 1 is 250 Hz. 
     right_output = generate_sinewave_2(1000, 10000); // Sinewave 2 is 1000 Hz. 
    
     aic3204_codec_write(left_output, right_output);
 	}

   /* Disable I2S and put codec into reset */ 
    aic3204_disable();

    printf( "\n***Program has Terminated***\n" );
    SW_BREAKPOINT;
}

/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  End of main.c                                                           *
 *                                                                          *
 * ------------------------------------------------------------------------ */












  • Hi Parash,

    I am no expert of the AIC3204. Based on my limited knowledge about audio processing, I think you should be able to adjust the output voltage by adjust the values in left_output, right_output, like scale down by divide or logarithm. If you want to achieve this set up the AIC304, then may have to consult AIC3204 expert. 

    Best regards,

    Ming

  • Hi Ming,
    Thank you for your help. 
    I have tried to lower the value of second parameter i.e. Amplitude  in left_output.
    But in  "left_output = generate_sinewave_1(250, 10000);"  when i put 100 instead of 10000 I am not getting sine wave, I am only getting noise.

  • Hi Paresh,

    If you plot the left_output with CCS graph tool, you should see a sine wave with amplitude peak at 100. It means the generate_sinewave_1 is working properly. You still hear noise from the headphone, it may be caused by the AIC3204, due to the low amplitude in left_output. I am not sure the AIC3204 can go as low as 1mv.

    Best regards,

    Ming

  • Hey Ming,
    Can you please tell me what values should i give in the following terms to plot graph:

    • Acquisition Buffer Size 
    • Dsp Data Type(options are 16-bit and 32-bit signed and unsigned integer)
    • Start Address 
    • Display data size
  • Hi Paresh,

    • Acquisition Buffer Size: sample number*2
    • Dsp Data Type(options are 16-bit and 32-bit signed and unsigned integer): signed 16-bit integer
    • Start Address: left_output
    • Display data size: sample number*2