i2s_apll_calculate_fi2s 计算问题

106415718@QQ.COM
Posts: 3
Joined: Mon Nov 15, 2021 8:31 am

i2s_apll_calculate_fi2s 计算问题

Postby 106415718@QQ.COM » Tue Nov 16, 2021 12:52 am

i2s设置sample_rate=48000,bits_per_sample=16,use_apll=true,fixed_mclk=12288000
i2s_apll_calculate_fi2s计算得到real rate: 47999.961,如果换成循环遍历sdm的方式得到real rate: 47999.992,看起来好像好一点点,不知道会不会有实质的影响。
i2s_apll_calculate_fi2s计算:
I (402) I2S: DMA Malloc info, datalen=blocksize=128, dma_buf_count=64
I (412) I2S: sdm0=2, sdm1=154, sdm2=4, odir=5
I (412) I2S: APLL: Req RATE: 48000, fi2s_rate: 12287990.000, real rate: 47999.961, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 12287990.000, SCLK: 1535998.750000, diva: 1, divb: 0
I (422) bsp_i2s_init: I2S driver installed.

循环遍历sdm的方式得到:
I (3162) I2S: sdm0=149, sdm1=212, sdm2=5, odir=6
E (3162) i2s_apll_get_fi2s: f_xtal:40000000,fout:393215936.000,fpll:12287998.000
I (3162) I2S: APLL: Req RATE: 48000, fi2s_rate: 12287998.000, real rate: 47999.992, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 12287998.000, SCLK: 1535999.750000, diva: 1, divb: 0
I (3182) bsp_i2s_init: I2S driver installed.

循环遍历:
float f_xtal = (float)(rtc_clk_xtal_freq_get() * 1000000);

min_diff = APLL_MAX_FREQ;

float t_odir,t_sdm0,t_sdm1;

for (_odir = 0; _odir < 32; _odir ++){
t_odir = f_xtal / (2 * (_odir+2)) / 2;
for (_sdm0 = 0; _sdm0 < 256; _sdm0 ++) {
t_sdm0 = (_sdm0 / 65536.0f) + 4;
for (_sdm1 = 0; _sdm1 < 256; _sdm1 ++){
t_sdm1 = (_sdm1 / 256.0f) + t_sdm0;
for (_sdm2 = 4; _sdm2 < 9; _sdm2 ++)
{
//avg = i2s_apll_get_fi2s(bits_per_sample, _sdm0, *sdm1, *sdm2, *odir);
avg = t_odir * (t_sdm1 + _sdm2);
if (abs(avg - rate) < min_diff) {
min_diff = abs(avg - rate);
*odir = _odir;
*sdm0 = _sdm0;
*sdm1 = _sdm1;
*sdm2 = _sdm2;
}
}
}
}
}

Who is online

Users browsing this forum: No registered users and 80 guests