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.

TLV320DAC3120: Tone Generator Issue

Part Number: TLV320DAC3120

Hi, I am using TLV320DAC3120 and trying to use the beep generator (PRB_P25) to generate pure sinewaves for chosen frequencies (parameter FHz), I have other modes where I send I2S from PIC32 (It works great with Fs=48Khz configured on the board using internal PLL) but on this mode I would like to generate sinewaves using the audio board and repeat to make it continuously playing until one of the parameters change.

I followed instructions on Datasheet for my calculations and config, I also checked values sent to registers and compared them to fixed examples and it seems correct :

    uint8_t MATCH_Config[10][2]; //{Register address, Register value}
    appData.MATCH.sine = floor(sin((2 * M_PI * FHz) / (48000))*(pow(2, 15)));
    appData.MATCH.cosine = floor(cos(2 * M_PI * FHz / (48000))*(pow(2, 15)));
    appData.MATCH.beepLength = floor((48000) * 1000 / FHz); //1000 cycles

    MATCH_Config[0][0] = 0x00; //Select page 0
    MATCH_Config[0][1] = 0x00;

    MATCH_Config[1][0] = 0x49;
    MATCH_Config[1][1] = (int) ((appData.MATCH.beepLength) & 0xff); //Reg 73
    MATCH_Config[2][0] = 0x4A;
    MATCH_Config[2][1] = (int) (((appData.MATCH.beepLength) >> 8) & 0xff); //Reg 74
    MATCH_Config[3][0] = 0x4B;
    MATCH_Config[3][1] = (int) (((appData.MATCH.beepLength) >> 16) & 0xff); //Reg 75
    MATCH_Config[4][0] = 0x4C;
    MATCH_Config[4][1] = (int) (((appData.MATCH.sine) >> 8)); //Reg 76 - SINE MSB
    MATCH_Config[5][0] = 0x4D;
    MATCH_Config[5][1] = (int) (((appData.MATCH.sine)) & 0xff); //Reg 77 - SINE LSB
    MATCH_Config[6][0] = 0x4E;
    MATCH_Config[6][1] = (int) (((appData.MATCH.cosine) >> 8)); //Reg 78 - COSINE MSB
    MATCH_Config[7][0] = 0x4F;
    MATCH_Config[7][1] = (int) (((appData.MATCH.cosine)) & 0xff); //Reg 79 - COSINE LSB

    //volume as described in Datasheet to make correspondance with binary value table (page 68 REG 65) 
    MATCH_Config[8][0] = 0x41;
    MATCH_Config[8][1] = 0x00; //appData.MATCH.volume; Page 0 Reg 65
    MATCH_Config[9][0] = 0x47;
    MATCH_Config[9][1] = 0x80; //Page 0 Reg 71 0x80 (max volume for beepr)

    /* Sending via I2C */
    I2C_Transmit((sizeof (MATCH_Config) / 2), MATCH_Config);

When I probe the result (with FHz=200Hz for example) I get a square wave of 320Hz and not a sinewave:

Any ideas on why I get this false result? using PurePath Studio I output using "ToneGenerator" block and probe and I get perfect sinewaves.

Best Regards,

EE student.

  • Hi Amine,

    I would like to understand some things from your settings:
    - Sine and Cosine operators must return its result in radians. I think your code do it like this, just want to make sure.
    - You must write Hex values into device registers. (int) is taking data into hex 16bit values?
    - On these lines you're not masking:
    MATCH_Config[4][1] = (int) (((appData.MATCH.sine) >> 8)); //Reg 76 - SINE MSB
    MATCH_Config[6][1] = (int) (((appData.MATCH.cosine) >> 8)); //Reg 78 - COSINE MSB
    Don't you need to mask here too?

    Is there a chance that you could read back these registers to verify the data you write?

    Best regards,
    -Ivan Salazar
    Audio Applications Engineer - Low Power Audio & Actuators
  • Hi Ivan,

    Thank You for your response!

    I checked everything it seems fine, I fixed one of the problem which was not having a sine wave, it was due to the fact that I was choosing maximum volume, now that I control the volume it's working fine.

    The issue that I still have is that the frequencies on the scope are wrong, I checked the values in I2C registers and they are calculated right and match the values and formulas in Datasheet, I even used values given in Datasheet (Table 5-18 page 37) for a 1Khz example but I get 1.7Khz, I have the same Fs=48Khz.

    I configured Fs using values given in Table 5-23 page 47 of Datasheet for PLL_CLCKIN=2.048Mhz : {Register,Value}

            {0x04, 0x03}, //03 for internal generation using PPL_CLK 
            {0x05, 0x93}, // To configure PLL_CLK and sampling frequency see pages 46/47 of TLV320DAC3120 Datasheet
            {0x06, 0x0E},
            {0x07, 0x00},
            {0x08, 0x00},
            {0x0B, 0x82},
            {0x0C, 0x87},
            {0x0D, 0x00},
            {0x0E, 0x80}

     This is my code for beep generation, I used FFFFFF to have maximum beep length :

        uint8_t MATCH_Config[9][2]; //{Register address, Register value}
        appData.MATCH.sine = sinf((2 * M_PI * FHz) / (48000))*(pow(2, 15));
        appData.MATCH.cosine = (cosf(2 * M_PI * FHz / (48000))*(pow(2, 15)));
        /*
         * If a defined length for the matching beeps need to be defined use this
        appData.MATCH.cyclesNb = 349 * FHz;
        appData.MATCH.beepLength = (48000 * appData.MATCH.cyclesNb) / FHz;
         */
        appData.MATCH.volume = abs((volume * 0.63 - 63)); //Volume in DB for BEEP REG
        //appData.MATCH.volume = abs(((volume * 0.875 - 63.5)*2) - 48); // DAC VOLUME - 0 for test
    
        MATCH_Config[0][0] = 0x00; //Select page 0
        MATCH_Config[0][1] = 0x00;
    
        MATCH_Config[1][0] = 0x49;
        MATCH_Config[1][1] = 0xFF; //(((appData.MATCH.beepLength) >> 16) & 0xff) //Reg 73 - FOR DEFINED BEEPLENGTH
        MATCH_Config[2][0] = 0x4A;
        MATCH_Config[2][1] = 0xFF; //(((appData.MATCH.beepLength) >> 8) & 0xff); //Reg 74 - FOR DEFINED BEEPLENGTH
        MATCH_Config[3][0] = 0x4B;
        MATCH_Config[3][1] = 0xFF; //((appData.MATCH.beepLength) & 0xff); //Reg 75 - FOR DEFINED BEEPLENGTH
        MATCH_Config[4][0] = 0x4C;
        MATCH_Config[4][1] = ((appData.MATCH.sine) >> 8) & 0xff; //Reg 76 - SINE MSB
        MATCH_Config[5][0] = 0x4D;
        MATCH_Config[5][1] = (((appData.MATCH.sine)) & 0xff); //Reg 77 - SINE LSB
        MATCH_Config[6][0] = 0x4E;
        MATCH_Config[6][1] = (((appData.MATCH.cosine) >> 8)& 0xff); //Reg 78 - COSINE MSB
        MATCH_Config[7][0] = 0x4F;
        MATCH_Config[7][1] = (((appData.MATCH.cosine)) & 0xff); //Reg 79 - COSINE LSB
    
        //volume as described in Datasheet to make correspondance with binary value table (page 68 REG 65) 
        //MATCH_Config[8][0] = 0x41;
        //MATCH_Config[8][1] = appData.MATCH.volume; //Page 0 Reg 65
        MATCH_Config[8][0] = 0x47;
        MATCH_Config[8][1] = 0x80 + appData.MATCH.volume; //Page 0 Reg 71 0x80 (max volume for beep/volume of DAC controlled by slider)
    
        I2C_Transmit((sizeof (MATCH_Config) / 2), MATCH_Config);

    Is there anything I am missing and that would make frequencies wrong?

    Thank You !

    Amine.

  • Amine,

    I tried your beep settings with this script on a evaluation board:
    w 30 49 00 09 60 10 b5 7e e7
    w 30 41 00
    w 30 47 80

    I can see a correct waveform on my output.
    Are you using the same overall settings for audio playback and beep? Audio playback is working fine?
    Could you share the rest of your register settings to take a look?

    Best regards,
    -Ivan Salazar
    Audio Applications Engineer - Low Power Audio & Actuators
  • Hi Ivan,

    the wave form is fine but the sine wave's frequency doesn't seem to be correct.

    Yes I keep the same overall settings to execute the beep code, I don't know what you mean by audio playback, you'll find the on-boot configuration here : https://codeshare.io/5XKeKz

    Thank You!

  • Amine,

    Clock setting registers seem to be fine for MCLK = 2.048MHz and Fs = 48kHz
    The values from data sheet table 5-18 are not accurate for 1kHz tone.
    The values you write are as follows?:
    0x4C - 0x10
    0x4D - 0xB5
    0x4E - 0x7E
    0x4F - 0xE8

    A change in tone frequency should be related to the values you write into register 0x4C through 0x4F or the sampling frequency Fs.

    Best regards,
    -Ivan Salazar
    Audio Applications Engineer - Low Power Audio & Actuators
  • Yes my code outputs those exact HEX values for 1Khz (sine/cosine), but the resulting sinewave is 1.58Khz instead of 1Khz, other frequencies are wrong too.

    Is there anything wrong in my overall configuration? (that playback you were talking about?)

    Using those values, do you get a 1Khz sinwave using TLV320DAC3120?

    Thank You very much!

  • By playback I mean when you send audio to the I2S input of the device.
    I have inspected your register settings and I couldn't find errors so far.
    Yes, when I use 0x4C - 0x10, 0x4D - 0xB5, 0x4E - 0x7E, 0x4F - 0xE8 I get a 1kHz sine wave.
    2.048MHz clock signal is coming into pin 8?
    I'll keep trying to help you debug this issue.

    Best regards,
    -Ivan Salazar
    Audio Applications Engineer - Low Power Audio & Actuators
  • Hi Ivan,

    Thank you for your responses.

    I checked the configuration and I can't see anything that would impact the beep generator's output frequency. I also tried with different board so it's not hardware.

    I did take some measurements (ratio between real and expected frequency) and I get approximately the right frequency on the scope after including this factor before calculations:

    Do you have any idea on what could be wrong here?

    Thank You!