miketeachman / micropython-esp32-i2s-examples

Usage and examples for I2S support on the ESP32 microcontroller
MIT License
152 stars 29 forks source link

I have a flaky/jittery signal on BCK with internal flash example #24

Closed artheist closed 3 years ago

artheist commented 3 years ago

Hi,

First, I would like to thank you for this amazing work, and if I can be of any help for beta-testing let me know, as far as my knowledge goes.

I am struggling to make the example work for the one with the internal SD card. I tried out with the Huzzah Feather as well as with TT-GO and the problem is the same: both Sdout and LRClk look fine on the scope but not BCK ... I am not sure how to describe it and what type of information you would need to help me out on this ...

What I can say is, with only the board plugged to the USB and nothing else attached, the LRClk is clean and ~50-60 ms periodic, where the sdout has a nice waveform about the same frequency, whereas the BCK looks like a bunch of random bursts of square waves ...

Also, I am using the firmware without the spiram and I read that you mentioned a bug in ESP-IDF about LR channel inversion. Could this also be related and should I rather compile my own firmware from your PR ?

Last question, it looks like your PR is 99% there, you are basically just waiting for approval, is that it ?

miketeachman commented 3 years ago

Hi Sylvain,

I tried to recreate the problem, using:

  1. Huzzah32 feather board
  2. esp32-idf4-0-2-i2s-2021-02-27-v1-14.bin firmware file
  3. PCM5102 stereo DAC module (note SCK input needs to be attached to ground)
  4. play-stereo-wav-from-internal-flash.py example code (no change to bck, ws, sd pins)

Result: the side-to-side audio file played correctly through the attached ear buds.

I am having difficulty to explain the problem you are seeing. The frequency used in the example is 8000 Hz. That should translate to a frequency of 8000 Hz (0.125ms period) on the WS pin (LRClk).

Here is something to try: change the sample rate in the example code to see if there is a change in the WS (LRClk) period that you measure on the scope. Try a few different samples rates such as 16000, 22050, 32000, 44100 Hz. Does the measured signal change?

The ESP-IDF code bug that swaps the L and R channels should not be causing this problem.

Sometime this month I will be releasing a new PR for I2S that supports the ESP32, and PyBoards. Hopefully the maintainers will merge the new PR into the mainline. The new PR has an API that is easier to understand.

There is always an answer to these problems. We'll figure it out ! Mike

artheist commented 3 years ago

Hi Mike, thanks for your quick reply.

1 . OK (I have ESP32 version, not ESP8266)

  1. same
  2. same except I have the 5102A version, I do not think there is any difference connectivity wise (SCK ok)
  3. same, no change in code except for the Sample Rate as suggested

I tried first without anything attached, just the board powered over USB, nothing else. Changed the sample rate according to the same values you suggested and LRClk is perfectly fine. I took pictures of LRClk for different sample rates, but nothing to report here.

At 44.1k, sdout looks kind of ok, even though a bit small, but I guess the fact that the wav file is 8k played at 44.1k might give weirder shapes.

But BCK is still wacky, it looks like there is an underlying clock at the correct rate, but with some modulation over it ... I suspect my power in the house to be the pb ... as if the 50Hz was modulating my clock ... This is a wild guess since I am in total despair atm.

artheist commented 3 years ago

Hi Mike,

Just wanted to let you know that I finally got it working ! I think my main problem was the PCM5102A was fried ... Replacing it with another one got it fixed.

Cheers,

Closing the issue since it is resolved for me :)

miketeachman commented 3 years ago

Thanks for following up on the problem. I'm really glad you were able to find the root cause of the flakiness because I was out of ideas !