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.

TLV320AIC3120: Test TLV320AIC3120 Output with sinus wave issue

Part Number: TLV320AIC3120


Hello,

We are trying to test the TLV320AIC3120. We have decided to test firstly the output with a sinus wave digitally created.

The TLV320AIC3120 receive a MCLK at 11.294118MHz and we use the PLL with the following configuration : J = 6, D = 9870, P = R = 1 and NDAC = 5 and MDAC = 3 in order to have fs = 44.1kHz.

We configure the DAC, like it is showed in 7.3.12.15 page 65 of the datasheet (with our PLL configuration obviously). We have done some little modifications : 

  • HPOUT muted and power-down (we use SPKP & SPKM outputs),
  • Class-D driver output stage gain = 6dB (instead of 18),
  • Class-D output analog volume = -20 dB (instead of -9)

The beep generator mode seems to work very well and we don't reach to produce the same sound with digital values send in I2S to the codec.

We don't know if it is the way we produce or the way we send the digital data or if it the configuration of the TLV320AIC3120. 

Here how we produce and send the data : 

#define PI 3.14159265358979323846
#define TAU (2.0 * PI)
[...]
u8 signal[65536];
u32 nsamples = 65536;
f64 t = 0;
s16 sin_value = 0;
u32 i = 0;
[...]
while(i < nsamples) {
    t = ((((f64)i) / 4.0)) / (44100);
    sin_value = 32767*sin(400 * TAU * t);
    signal[i] = (sin_value >> 8) & 0xFF; // left msb
    signal[i+1] = sin_value & 0xFF; // left lsb
    signal[i+2] = signal[i]; // right msb
    signal[i+3] = signal[i+1]; // right lsb
    i += 4;
}
[...]
HAL_SAI_Transmit(&hsai_BlockA1, signal, nsamples/2, HAL_MAX_DELAY);

Thanks in advance.

Regards,

Malo

  • Hi Malo,

    If I am reading your code correctly, are you trying to have 2 bit datapoints? In this config, we expect 16 bit data, this means that the MSB to LSB of the left channel will come first taking up signal[0:15], then MSB to LSB of right channel in signal[16:31], etc. Another thing to note is that the data must be sent at the same time as the BCLK, which is assumed to be in slave mode if you followed the registers in page 65, so you will want to make sure that the BCLK and the audio data are being sent at the same time. If you can share a scope shot of what is going into your DIN pin (and BCLK/WCLK) this will help you and I check the data and clocks to make sure it makes sense for this application.

    Another thing to note is that your signal array size will allow for 0.046 seconds of signal, so keep this in mind it will be very quick.

    Best,
    Mir

  • Hello Mir,

    The HAL_SAI_Transmit function takes table of 8 bits data, so we put sin_value[15:8] in signal[i] and sin_value[7:0] in signal[i+1]. The SAI block is configured to sent 16 bits of data using I2S protocol. We copy the data signal on the following 16 bits (signal[i+2] and signal[i+3]) in order to be as it is showed on figure 7-44 page 76.

    Here is a scope shot of the WCLK (D0), BCLK (D1) and DIN (D2) signals:

    The WCLK frequency is measured to 44.189 kHz and 1.412 MHz for the BCLK signal.

    Can you explain how you find the 0.046 seconds of signal please ?

    The HAL_SAI_Transmit function is in an infinite loop.

    Regards,

    Malo

  • Hi,

    I see, sorry about that I didn't fully understand your code. It looks to be correct, you have 16 bit clocks and data coming through. Is your issue that the signal is not loud enough? Or can you not hear at all? Can you attach your I2C commands or a register dump? I know you used the example as a base but let's look at what is happening on your specific solution.

    Best,
    Mir

  • Hi,

    I resolve one of the issue, my data was not set in my table in the right order : I should enter the LSB before the MSB. Now I can hear something else than some crackling. But I don't think my issue is resolved. It seems I don't have the right output sound frequency at DAC output.

    The code now:

    [...]
    uint16_t signal[65535];
    u32 nsamples = 65535;
    f64 t = 0;
    int16_t sin_value = 0;
    f64 sin_value_f64 = 0.0;
    [...]
    u32 i = 0;
    u16 BeepFrequency = 2000;
    while(i < nsamples) {
        t = ((f64)i) / 2.0;
        sin_value_f64 = sin(((2.0 * M_PI * BeepFrequency) / tlv320.sample_rate) * t);
        sin_value = (int16_t)(32767 * sin_value_f64);
        signal[i] = sin_value; // left
        signal[i+1] = sin_value; // right
        i += 2;
    }
    [...]
    HAL_SAI_Transmit(&hsai_BlockA1, (uint8_t *)signal, nsamples/2, HAL_MAX_DELAY);

    Here a sound spectrum shot (from my phone) when I use the beep generator feature to produce a 2000 Hz sine wave at the Class-D Speaker output:

    We can see a peak at approximately 2000Hz with -46dB power.

    When we send data of a sinus at 2000Hz to the DAC using I2S protocol:

    We can see a peak at approximately 1000Hz with -51dB power.

    Here is the I2C commands, I use to configure the DAC to play the data it received in I2S:

    W 00 00
    W 01 01
    (Delay 1 ms)
    W 04 03
    W 06 06
    W 07 26
    W 08 8E
    W 05 91
    (Delay 10 ms)
    W 0B 85
    W 0C 83
    W 0D 00
    W 0E 80
    W 1B 00
    W 3C 10
    W 00 08
    W 01 04
    W 00 00
    W 00 01
    W 1F 04
    W 21 4E
    W 35 40
    W 28 06
    W 2A 04
    W 1F 82
    W 20 86
    W 24 92
    W 26 A8
    W 00 00
    W 3F 94
    W 41 D4
    W 40 04

    Best regards,

    Malo

  • Hi Malo,

    Your code looks fine, besides the register "W 30 40" where you write to register 0x35 which is reserved for page 1, I am not sure what you meant there.

    As for your data sending, I2S signals have a 1 bit shift after WCLK, and they send MSB first, followed by all bits in order until LSB. This diagram shows that shift. Maybe it is a bit shift that is messing up your output?

    Best,
    Mir

  • Hi,

    Yes sorry it should be "W 23 40" (0x23 = 35 in decimal).  

    I resolve my problem, I should'nt set the same data in signal[i] and signal[i+1]. Now It works well.

    Thank you.

    Best regards,

    Malo