Hi, Frank. I checked multiple times for any grounding / ground loop issues and couldn't find any. It still doesn't explain why the same issues don't appear with I2S
Anyway, I borrowed a second T4.1 to check if my sample is possibly defective and did a lot more testing today. Managed to isolate the main problem - I couldn't pinpoint it before because it's not a single issue, but a few issues appearing at the same time... And it has absolutely no connection with extra pins or the hardware around Teensy. I'll divide the conclusions into 3 categories, and then we'll hopefully be somewhat smarter together.
1) Memory issues
I use a memory buffer for partial screen redraw by pushing it to ILI9341 with a procedure similar to writeRect(). The array is declared in RAM2 at the beginning of the main .ino file:
Code:
uint16_t *scrBuff = new uint16_t[240*320];
Those horrible audio glitches I previously thought were SPI related are, in fact, mainly related to this buffer. When I move the buffer to ITCM
Code:
uint16_t scrBuff[240*320];
the issue is mainly gone and TDM now behaves more or less like I2S. But I really can't afford a 150kB buffer in precious RAM1
T4.0 works normally with this buffer in RAM2.
2) TDM issues
When I connected all 8 TDM channels instead of only 2, things got much better; but the glitches still appear on the oscilloscope and are clearly audible. Then I connected just 2 channels that are producing constant audio signal to these 8 TDM channels (audio 0 to TDM 0, audio 1 to TDM 2, audio 0 to TDM 4, audio 1 to TDM 6, and so on) and everything suddenly worked very well. As soon as I stop sending audio blocks to any of the connected TDM channels (or stop sending empty audio blocks to the mixer to save proc. usage), the glitches reappear. Again, this works perfectly well on T4.0.
3) ADC issues
I tested the complete ADC section (12 pots on Teensy ADC pins, 16 pots connected via HC4067 mux, 8 CV ins via AD7327 13-bit SPI ADC on SPI1) without Audio Library part, and it works exceptionally well: no analogReadAveraging or ResponsiveAnalogRead needed, rock solid 12-bit readings, fully satisfied. As soon as I involve Audio Library objects and start I2S or TDM output, ADC goes haywire and both 12-bit and 10-bit readings are all over the place
Not by one or two bits, but seriously unstable and oscillating by four or five bits several times per second. I need to use analogReadAveraging(16) and ResponsiveAnalogRead with setActivityThreshold(16) to get barely acceptable results, but it slows the readings so much they are practically unusable
This unfortunately happens with T4.0 too, but external SPI ADC readings are not affected. I finally tested the situation where T4.0 is driving the TDM DAC and T4.1 is reading ADCs to make sure the external hardware and traces are not to blame, and as I suspected the readings were stable again. So, it has to be some internal IMXRT1062 glitch or a bug and I have no idea how to solve this