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.

Tone generation

I have this sample code to generate a sine wave of 1 KHZ which i received from TI.

I would like to know how to do the hexadecimal calculation to produce a wave of 610HZ.

#include "tonecfg.h"

#include "dsk6713.h"
#include "dsk6713_aic23.h"

/* Length of sine wave table */
#define SINE_TABLE_SIZE 48

/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};

/* Pre-generated sine wave data, 16-bit signed samples */
Int16 sinetable[SINE_TABLE_SIZE] = {
0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};


/*
* main() - Main code routine, initializes BSL and generates tone
*/

void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Int16 msec, sample;

/* Initialize the board support library, must be called first */
DSK6713_init();

/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

/* Generate a 1KHz sine wave for 5 seconds */
for (msec = 0; msec < 5000; msec++)
{
for (sample = 0; sample < SINE_TABLE_SIZE; sample++)
{
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, sinetable[sample]));

/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, sinetable[sample]));
}
}

/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}

  • Hi,

    Thanks for your post.

    I would recommend you to pre-generate a SINE wave data for 610Hz in MATLAB for the SINETABLESIZE of 48 samples and feed it to the sinetable[SINE_TABLE_SIZE] array which initializes the fixed data for 610Hz.

    Also, try to check the "DSK6713_AIC23_SAMPLERATE Sample rate control" to tune the sample rate in the DSK6713_AIC23 codec configuration setttings to have any impact in generating 610Hz.

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.

    -------------------------------------------------------------------------------------------------------

  • HI,
    I did generate the SINETABLESIZE in MATLAB. but the data generated in matlab - not sure what kind format they are in.
    IS there any other way we can generate in CCS. I also used the formula A* sin(2*Pi*F*t), but it gives so much noise .
    Can you tell me how was the sine table values was generated for 1KHZ tone which is provided by TI.
  • /*
     *  Copyright 2002 by Spectrum Digital Incorporated.
     *  All rights reserved. Property of Spectrum Digital Incorporated.
     */
    
    /*
     *  ======== tone.c ========
     *
     *  This example uses the AIC23 codec module of the 6713 DSK Board Support
     *  Library to generate a 1KHz sine wave on the audio outputs for 5 seconds.
     *  The sine wave data is pre-calculated in an array called sinetable.  The
     *  codec operates at 48KHz by default.  Since the sine wave table has 48
     *  entries per period, each pass through the inner loop takes 1 millisecond.
     *  5000 passes through the inner loop takes 5 seconds.
     *
     *  Please see the 6713 DSK help file under Software/Examples for more
     *  detailed information.
     */
    
    /*
     *  DSP/BIOS is configured using the DSP/BIOS configuration tool.  Settings
     *  for this example are stored in a configuration file called tone.cdb.  At
     *  compile time, Code Composer will auto-generate DSP/BIOS related files
     *  based on these settings.  A header file called tonecfg.h contains the
     *  results of the autogeneration and must be included for proper operation.
     *  The name of the file is taken from tone.cdb and adding cfg.h.
     */
    #include "tonecfg.h"
    
    /*
     *  The 6713 DSK Board Support Library is divided into several modules, each
     *  of which has its own include file.  The file dsk6713.h must be included
     *  in every program that uses the BSL.  This example also includes
     *  dsk6713_aic23.h because it uses the AIC23 codec module.
     */
    #include "dsk6713.h"
    #include "dsk6713_aic23.h"
    
    /* Length of sine wave table */
    #define SINE_TABLE_SIZE   48
    
    /* Codec configuration settings */
    DSK6713_AIC23_Config config = { \
        0x0017,  /* 0 DSK6713_AIC23_LEFTINVOL  Left line input channel volume */ \
        0x0017,  /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
        0x00d8,  /* 2 DSK6713_AIC23_LEFTHPVOL  Left channel headphone volume */  \
        0x00d8,  /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
        0x0011,  /* 4 DSK6713_AIC23_ANAPATH    Analog audio path control */      \
        0x0000,  /* 5 DSK6713_AIC23_DIGPATH    Digital audio path control */     \
        0x0000,  /* 6 DSK6713_AIC23_POWERDOWN  Power down control */             \
        0x0043,  /* 7 DSK6713_AIC23_DIGIF      Digital audio interface format */ \
        0x0081,  /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */            \
        0x0001   /* 9 DSK6713_AIC23_DIGACT     Digital interface activation */   \
    };
    
    /* Pre-generated sine wave data, 16-bit signed samples */
    Int16 sinetable[SINE_TABLE_SIZE] = {
        0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
        0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
        0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
        0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
        0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
        0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
    };
    
    
    /*
     *  main() - Main code routine, initializes BSL and generates tone
     */
    
    void main()
    {
        DSK6713_AIC23_CodecHandle hCodec;
        Int16 msec, sample;
    
        /* Initialize the board support library, must be called first */
        DSK6713_init();
    
        /* Start the codec */
        hCodec = DSK6713_AIC23_openCodec(0, &config);
    
        /* Generate a 1KHz sine wave for 5 seconds */
        for (msec = 0; msec < 5000; msec++)
        {
            for (sample = 0; sample < SINE_TABLE_SIZE; sample++)
            {
                /* Send a sample to the left channel */
                while (!DSK6713_AIC23_write(hCodec, sinetable[sample]));
    
                /* Send a sample to the right channel */
                while (!DSK6713_AIC23_write(hCodec, sinetable[sample]));
            }
        }
    
        /* Close the codec */
        DSK6713_AIC23_closeCodec(hCodec);
    }
    
    I generated lookup table using matlab. When i write that to CCS , my device (C6713) is doing a tone of 5 KHZ. Not sure why is this happening.

    The values generated for 606hz is below and have also attached the code for generating the tone. 

    Columns 1 through 9

            0    0.4582    0.8145    0.9898    0.9451    0.6903    0.2820   -0.1889   -0.6179

     Columns 10 through 18

      -0.9095   -0.9989   -0.8663   -0.5411   -0.0957    0.3710    0.7553    0.9716    0.9720

     Columns 19 through 27

       0.7563    0.3725   -0.0941   -0.5398   -0.8655   -0.9988   -0.9101   -0.6191   -0.1905

     Columns 28 through 36

       0.2805    0.6891    0.9445    0.9900    0.8154    0.4596    0.0016   -0.4568   -0.8136

     Columns 37 through 41

      -0.9896   -0.9456   -0.6914   -0.2835    0.1874