Goal

I have a esp32 board called a “TTGO LoRa32-OLED” here that I am trying to output an I2S signal from into a breakout board based on a PCM5102A i2s auidio DAC. I noticed a problem though when generating a sin wave signal, there was a ‘pop’ a couple of times a second. Outputting a ramp test pattern:

Into a scope reveals this:

There’s a bunch of glitches in the output! This tells us that the glitch is not caused by the loop not being serviced regularly though (I think) since that would cause a flatline presumably.

Drilling down

Taking a look at the decoded protocol we see this:

You can see that along the bottom the i2s decoded numbers continue to increase even though there is a discontinuity downwards. Perhaps then it’s the amplifiers problem? There are a bunch of modes in i2s that I don’t really understand so maybe we are uing the wrong one and the timing iss marginal or something.

Check yourself before you rek yourself

Here is a screenshot of the signal on a normal falling edge:

This also has the samples ascending! Looking at the datasheet it talks about filtering and latency a bunch, so that’s probably what’ going on here.

The solution

It turns out that the arduino library I was using here had some circular buffer mutex freeRTOS synchronisation stuff going on. I wrote my own simple version based of some stuff on the internets and that works fine.