Is Mixing analogRead() on ADC2 A12 with AudioInputAnalog on A2 Verboten?

conr2286

New member
I have encountered problems (corrupted data) trying to use the audio pipeline setup with an ADC1 source,
AudioInputAnalog adc1; // ADC1
concurrently with reading a resistive touchscreen axis with,
value1 = analogRead(A12); //ADC2
and am wondering if running both Teensy 4.1 ADCs concurrently is a known problem (although a multitude of searches implies it should work).

Things that I know:
  • If I comment out calls to analogRead(A12) the audio pipeline works as expected (no audio data corruption)
  • If I modify analog.c (illustrated below) to not start ADC2 then the audio pipeline works as expected:
    • if (!(ch & 0x80)) {
      ADC1_HC0 = ch;
      while (!(ADC1_HS & ADC_HS_COCO0)) {
      yield(); // TODO: what happens if yield-called code uses analogRead()
      }
      return ADC1_R0;
      } else {
      return 0; // Don't start ADC2
      ADC2_HC0 = ch & 0x7f;
      while (!(ADC2_HS & ADC_HS_COCO0)) {
      yield(); // TODO: what happens if yield-called code uses analogRead()
      }
      return ADC2_R0;
      }

If using ADC2 concurrently with the audio pipeline's use of ADC1 is a known no-no then I'll adopt a different approach (external ADC).

...JimC
 
Resolution: Despite widespread google/Copilot reports to the contrary, the Teensy 4.1 audio pipeline actually uses ADC2, not ADC1 (see input_adc.cpp init()). Leaving my audio on A2 while moving the touchscreen sampling to A16/A17 (available through ADC1) resolved the corrupted audio issue. Lesson: Do not use analogRead() with analog channels only available through ADC2 concurrently with audio pipeline activity on A2. ...JimC
 
Back
Top