-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for mclk/bclk divisors #8326 (IDFGH-6698) #8327
Conversation
Tentative fix for espressif/arduino-esp32#5938 |
Applying this patch locally makes Audio DAC working again. Here are the new computed values: |
Many thanks for fixing the DAC clock, I have checked it and it can work. But have you test this clock setting with ADC mode? It seems can't work for ADC mode |
No I haven't tested ADC mode. |
Oh sorry, don't mind ADC, it's my fault. So now the FYI, while we are not using APLL, and set a low sample rate for ADC/DAC, the mclk_div will exceed its maximum value 255 (it has only 8 bit in reg), which can lead the clock go wrong. |
Thanks for the feedback. I suppose that |
Considering sometimes DAC will work together with ADC, 8 bits is not the best solution, because ADC needs 16 bits channel width to receive 12 bits width data. I think we need to use This issue will be fixed recently, the commit in the PR will be involved, thanks for the contribution! |
Thanks for your contribution, changes merged with 2f0e7e9 |
This fix broke the I2S ADC, had to revert the old code back |
Can you give more details about the parameters you have been using? |
My board is ESP32-WROOM-32. I didn't use a DAC so I don't know how it behaves, but the ADC works with the wrong frequency to read samples. I recorded from a microphone and the sound turned out to be very slow. int _sampleRate = 16000;
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),
.sample_rate = _sampleRate,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2,
.dma_buf_count = 128,
.dma_buf_len = 2,
.use_apll = false
}; I fixed it by returning the code with this condition to the compiler #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(3, 3, 5)
#define I2S_LL_AD_BCK_FACTOR (2)
int bclk = _sampleRate * I2S_LL_AD_BCK_FACTOR * 2;
int bclk_div = I2S_LL_AD_BCK_FACTOR;
i2s_config.use_apll = true;
i2s_config.fixed_mclk = bclk * bclk_div;
#endif And the problem was solved, the samples are normal. |
This is a first tentative to #8326
bclk_div
is set to 32 which is the highest power of 2 possible for this hardware register (6 bits).bclk
target is sample_rate * I2S_LL_AD_BCK_FACTOR. I removed the additional factor 2 which looks erroneous with audio output.