-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Due bug: Cannot use pin as digital after analogRead #2198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@trickedj I'll open a pull request for this in order to fix it |
here the pull request |
If an analog input is used and during the sketch modified in a digitalOutput the pinMode(AX, OUTPUT) isn't sensed because of this line of codes: wiring_analog.c line 135 // Enable the corresponding channel if (ulChannel != latestSelectedChannel) { adc_enable_channel( ADC, ulChannel ); if ( latestSelectedChannel != (uint32_t)-1 ) adc_disable_channel( ADC, latestSelectedChannel ); latestSelectedChannel = ulChannel; The channel is infact enabled only if different from the previous one because of speed problems. With my patch: when pinMode(PIN, OUTPUT) is declared a control about if the pin is an analog one is done and if so the ADC is released when pinMode(PIN, INPUT) is declared a control is as well done in order to enable the ADC.
I am not sure that calling "adc_enable_channel" for the input mode is |
I wasn't sure too, but i tested it and it works. That if that checks if the channel is changed is a problem. |
I've added some thoughts and code on https://groups.google.com/a/arduino.cc/forum/#!topic/developers/IdhTIT0V5GY , |
to avoid the bug arduino#2198 simply reconfigure the pin -> no additional overhead if pinMode configuration is performed at the beginning of the sketch, 4 to 25% overhead on all analogRead() due to the additional check
to avoid the bug arduino#2198 simply reconfigure the pin -> no additional overhead if pinMode configuration is performed at the beginning of the sketch, 4 to 25% overhead on all analogRead() due to the additional check
to avoid the bug arduino#2198 simply reconfigure the pin -> no additional overhead if pinMode configuration is performed at the beginning of the sketch, 4 to 25% overhead on all analogRead() due to the additional check
Solved by #3524 |
to avoid the bug arduino#2198 simply reconfigure the pin -> no additional overhead if pinMode configuration is performed at the beginning of the sketch, 4 to 25% overhead on all analogRead() due to the additional check
Once a pin has been used by analogRead it cannot be returned to digital use with pinMode(xxxx, OUTPUT) because analogRead only frees up the pin when another channel is read. pinMode needs to check if the pin is currently selected for the ADC and if so free it up.
A work around is to free up the pin by selecting a spare with analogRead
I discovered this while porting (from a Uno to Due) a TFT+touchpanel screen which shares digital TFT functions with raw touchpanel resistors.
The text was updated successfully, but these errors were encountered: