Teensy 4.1 ADC Channels

NJ-Tom

Member
I am working on migrating a project from Teensy 3.6 to 4.1. It has two analog inputs:
  • Audio from an Adafruit Max9814 microphone, to FFT to flash LED's
  • A thermistor input
On the Teensy 3.6, I put them on separate ADC channels so the audio input could have a channel all to itself, and I would like to do the same on the 4.1. But even with reading through the code, I couldn't figure out which channel was used for which analog inputs, or if there was a way to assign an input to a particular channel. From the datasheet and schematic it looked like 24 & 25 go to ADC1 only, 26, 27, 38, 39 go to ADC2 only, and 14-23, 40 & 41, can go to either channel.

Moreover, I noticed in the comments that A10 & A11 (pins 24 & 25) shouldn't be used for audio, and A12 & A13 (pins 26 & 27) shouldn't be used for analogRead, so now I am really worried about choosing the wrong inputs. I'm making a custom PCB, so it would be best to get it right the first time.

Also can the 4.1 take in good enough audio via the ADC, or do I need to move to I2S?

Thanks!
 
On the Teensy 3.6, I put them on separate ADC channels so the audio input could have a channel all to itself, and I would like to do the same on the 4.1. But even with reading through the code, I couldn't figure out which channel was used for which analog inputs, or if there was a way to assign an input to a particular channel. From the datasheet and schematic it looked like 24 & 25 go to ADC1 only, 26, 27, 38, 39 go to ADC2 only, and 14-23, 40 & 41, can go to either channel.
Maybe this thread will help - Teensy 4.0 which pins for which ADC
 
From the datasheet and schematic it looked like 24 & 25 go to ADC1 only, 26, 27, 38, 39 go to ADC2 only, and 14-23, 40 & 41, can go to either channel.

Moreover, I noticed in the comments that A10 & A11 (pins 24 & 25) shouldn't be used for audio, and A12 & A13 (pins 26 & 27) shouldn't be used for analogRead

NJ-Tom, would you please point me to the data sheet you got this information from? Thx
 
NJ-Tom, would you please point me to the data sheet you got this information from? Thx

Hi Neal,

I got the information from multiple sources, many of which are linked from the main Teensy 4.1 page.

And the code in question, at least on my machine, is in C:\Users\(username)\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.57.1\cores\teensy4\analog.c:

Code:
int analogRead(uint8_t pin)
{
	if (pin > sizeof(pin_to_channel)) return 0;
	if (calibrating) wait_for_cal();
	uint8_t ch = pin_to_channel[pin];
	if (ch == 255) return 0;
	if(!(ch & 0x80)) {
		ADC1_HC0 = ch;
		while (!(ADC1_HS & ADC_HS_COCO0)) {
			yield();
		}
		return ADC1_R0;
	} else {
		ADC2_HC0 = ch & 0x7f;
		while (!(ADC2_HS & ADC_HS_COCO0)) {
			yield();
		}
		return ADC2_R0;
	}
}

I think I have an understanding of what is going on and what to do, and will be posting another response to this thread with a summary.
 
Code:
Moreover, I noticed in the comments that A10 & A11 (pins 24 & 25) shouldn't be used for audio, and A12 & A13 (pins 26 & 27) shouldn't be used for analogRead

Sorry, I should have more specific on information source request. Where did you find the comments regarding the limitations of A10 -A13?
 
A summary of what I found, and what I will do -

The processor the Teensy 4.1 uses has 2 ADC converters, each attached to its own analog multiplexer. Some Teensy pins only go to one multiplexer, but many go to both.

Pins 24 & 25 go to ADC1 only, pins 26, 27, 38, 39 go to ADC2 only, and 14-23, 40 & 41, can go to either channel.
Watch out, A10 & A11 (pins 24 & 25) shouldn't be used for audio, and A12 & A13 (pins 26 & 27) shouldn't be used for analogRead, but the rest of the analog inputs can be used at will.

The Teensy code will prefer ADC1 and will use ADC2 only if necessary. There doesn't appear to be an easy way to override this behavior. It would have been nice to be able to use "4" for ADC1, and "4+128" for ADC2, but that is not possible.

But it turns out all this isn't an issue. In the Audio System Design Tool,
"Pin A2 is used by default for audio input."
and more importantly
"A different pin may be used, but adding it as an parameter to the AudioInputAnalog object definition.
For example, to use pin A3:
AudioInputAnalog adc1(A3);"

So it looks like I could use:
AudioInputAnalog adc2(A3)
and keep the relatively fast audio stream on adc2, while leaving adc1 to bounce around servicing slower analog inputs.

It would be nice if someone could confirm this, but even if I'm wrong and the audio and thermistor have to share an ADC, so what if the audio gets a slight glitch a few times a minute? Not a big issue.

Time for me to buy a Teensy 4.1 (or two), but it looks like there's no need to buy an audio shield.
 
Code:
Moreover, I noticed in the comments that A10 & A11 (pins 24 & 25) shouldn't be used for audio, and A12 & A13 (pins 26 & 27) shouldn't be used for analogRead

Sorry, I should have more specific on information source request. Where did you find the comments regarding the limitations of A10 -A13?

From C:\Users\(username)\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.57.1\libraries\Audio\input_adc.cpp:

Code:
	255,	// 10/A10 AD_B0_12 - only on ADC1, 1 - can't use for audio
	255,	// 11/A11 AD_B0_13 - only on ADC1, 2 - can't use for audio
...
	255,    // 24/A10 AD_B0_12 - only on ADC1, 1 - can't use for audio
	255,    // 25/A11 AD_B0_13 - only on ADC1, 2 - can't use for audio
	3,      // 26/A12 AD_B1_14 - only on ADC2, do not use analogRead()
	4,      // 27/A13 AD_B1_15 - only on ADC2, do not use analogRead()
    #ifdef ARDUINO_TEENSY41
...
	1,      // 38/A14 AD_B1_12 - only on ADC2, do not use analogRead()
	2,      // 39/A15 AD_B1_13 - only on ADC2, do not use analogRead()

I think I am misunderstanding the code. In any case I am going to take the safe way out and avoid using analog inputs or ADC on those pins.

Also in the Audio System Design Tool:
"On Teensy 4, analog pins 24/A10 and 25/A11 are not supported."
 
Back
Top