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 » Mon Nov 15, 2021 8:47 am

例如设置sample_rate=48000,bits_per_sample=16,use_apll = true,fixed_mclk = 12288000;
static esp_err_t i2s_apll_calculate_fi2s计算得到真实:real rate: 47999.961
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.

如果i2s_apll_calculate_fi2s按照遍历方式寻找最佳的值得到更接近real rate: 47999.992,fi2s_rate也有一点点提高,不知道这样这几组值对结果有没有什么影响。
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 23 guests