Page 1 of 1

How to determine LRCLK clock frequency

Posted: Wed Apr 04, 2018 9:11 am
by susanyin0501
where set LRCLK clock frequency in source code?

In deliver( )
{

#ifndef CODEC_MASTER
/* LR clock delayed by one clock, This is so MSB is output on the falling edge of BCLK
* after the falling edge on which LRCLK was toggled. (see I2S spec) */
/* Generate clocks LR Clock low - LEFT */
#ifdef I2S_MODE_TDM
p_lrclk <: 0x00000000;
#else
p_lrclk <: 0x80000000;

#endif

#pragma xta endpoint "i2s_output_l"

#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0)
index = 0;
#pragma loop unroll
/* Output "even" channel to DAC (i.e. left) */
for(int i = 0; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME)
{
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]);
}
#endif

#ifndef CODEC_MASTER
/* Clock out the LR Clock, the DAC data and Clock in the next sample into ADC */
doI2SClocks(divide);
#endif

.....

#ifndef CODEC_MASTER
#ifdef I2S_MODE_TDM
if(frameCount == (I2S_CHANS_PER_FRAME-2))
p_lrclk <: 0x80000000;
else
p_lrclk <: 0x00000000;
#else
p_lrclk <: 0x7FFFFFFF;
#endif
#endif

index = 0;
#pragma xta endpoint "i2s_output_r"
#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0)
/* Output "odd" channel to DAC (i.e. right) */
#pragma loop unroll
for(int i = 1; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME)
{
p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]);
}
#endif

#ifndef CODEC_MASTER
doI2SClocks(divide);
#endif

....
}

Does LRCLK frequency set in this function? but if i add some source code in this function, LRCLK frequency will be change.

would you please tell me where set LRCLK frequency and how to determine LRCLK frequency? thanks very much!

Re: How to determine LRCLK clock frequency

Posted: Thu Apr 05, 2018 2:05 pm
by andrewxcav
You should just be able to set up the appropriate struct in i2s.h. These configs are designed to do most of the work for you in terms of clocking ratios / edges.

Depending on what mode you choose the LRCLK will trigger differently (as you can see in the code that you posted here):

I2S_MODE_I2S, ///< The LR clock transitions ahead of the data by one bit clock.
I2S_MODE_LEFT_JUSTIFIED, ///< The LR clock and data are phase aligned.

In general, you should never need to modify any code in a library.

Re: How to determine LRCLK clock frequency

Posted: Mon Apr 09, 2018 5:30 pm
by Ross
LR frequency in I2S is the sample rate frequency

Re: How to determine LRCLK clock frequency

Posted: Wed Apr 11, 2018 8:11 am
by susanyin0501
Thanks for your reply, Ross and andrewxcav

Re: How to determine LRCLK clock frequency

Posted: Mon May 07, 2018 12:21 pm
by susanyin0501
Does LRCLK frequency set in deliver( )?

if i add some source code in deliver( ), 5 in 5 out TDM16 mode, LRCLK will be less than 48K when playback 48K audio. please check add_code_in_deliver.xc
but i decrease some code in deliver( ), for example, i comment DAC process code, LRCLK will not be changed when playback 48K audio, still 48K, please refer to decrease_code_in_deliver.xc

why will LRCLK be changed when adding source code, but decrease code, LRCLK will not change ( following sample frequency) ?

would you please give some idea? thanks