Hello.
I have a Teensy 3.6 and I am using Arduino 1.8.8 and Teensyduino 1.45.
I was wondering whether it is possible to change pins A21 and A22 to be high-impedance (floating) after having used them with analogWrite (which obviously causes the pins to be driven to a specific voltage)?
I ran the following test code:
I then verified that A21 (or any pin other than A22) was floating by measing 0V between the pin and GND as well as measuring 0V between the pin and 3.3V. I then measured pin A22 and I get 1.65V between the pin and GND, as well as 1.65V between the pin and 3.3V. This means that it is still being driven, even though it has been used with analogRead() after the analogWrite() call.
To ensure nothing was being optimized away or there was timing/race issue I changed to the code to:
and compiled with the "Optimize: Debug" option. The serial output was "A22 value: 513" and the pin remains at around 1.65V.
I searched the forum and the internet and didn't find answers to this. I know I can't use pinMode() with these pins. I took a look at the source code for analogRead (line 438 in analog.c) and I didn't see an obvious place where the pins would be "muxed back" from the DAC function which analogWrite uses, although I'm out of my depth there since I haven't looked at the MCU's datasheet.
Any help, thoughts, ideas, suggestions, workarounds welcomed.
I have a Teensy 3.6 and I am using Arduino 1.8.8 and Teensyduino 1.45.
I was wondering whether it is possible to change pins A21 and A22 to be high-impedance (floating) after having used them with analogWrite (which obviously causes the pins to be driven to a specific voltage)?
I ran the following test code:
Code:
void setup()
{
analogWrite(A22, 128);
analogRead(A22);
}
void loop()
{
}
I then verified that A21 (or any pin other than A22) was floating by measing 0V between the pin and GND as well as measuring 0V between the pin and 3.3V. I then measured pin A22 and I get 1.65V between the pin and GND, as well as 1.65V between the pin and 3.3V. This means that it is still being driven, even though it has been used with analogRead() after the analogWrite() call.
To ensure nothing was being optimized away or there was timing/race issue I changed to the code to:
Code:
void setup()
{
Serial.begin(0);
analogWrite(A22, 128);
delay(1000);
int val;
val = analogRead(A22);
delay(1000);
Serial.printf("A22 value: %i\r\n", val);
}
void loop()
{
}
I searched the forum and the internet and didn't find answers to this. I know I can't use pinMode() with these pins. I took a look at the source code for analogRead (line 438 in analog.c) and I didn't see an obvious place where the pins would be "muxed back" from the DAC function which analogWrite uses, although I'm out of my depth there since I haven't looked at the MCU's datasheet.
Any help, thoughts, ideas, suggestions, workarounds welcomed.