Skip to content

Commit 7c7dd6e

Browse files
committed
Due: modify ADC enable/disable sequence
to avoid the bug #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
1 parent ede6dd2 commit 7c7dd6e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

cores/arduino/wiring_analog.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ uint32_t analogRead(uint32_t ulPin)
148148
case ADC11 :
149149

150150
// Enable the corresponding channel
151-
if (ulChannel != latestSelectedChannel) {
151+
if (adc_get_channel_status(ADC, ulChannel) != 1) {
152152
adc_enable_channel( ADC, ulChannel );
153-
if ( latestSelectedChannel != (uint32_t)-1 )
153+
if ( latestSelectedChannel != (uint32_t)-1 && ulChannel != latestSelectedChannel)
154154
adc_disable_channel( ADC, latestSelectedChannel );
155155
latestSelectedChannel = ulChannel;
156156
}

cores/arduino/wiring_digital.c

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ extern void pinMode( uint32_t ulPin, uint32_t ulMode )
2929
return ;
3030
}
3131

32+
#if defined __SAM3X8E__ || defined __SAM3X8H__
33+
if(g_APinDescription[ulPin].ulPinType != NO_ADC && adc_get_channel_status(ADC, g_APinDescription[ulPin].ulADCChannelNumber))
34+
{
35+
adc_disable_channel( ADC, g_APinDescription[ulPin].ulADCChannelNumber);
36+
}
37+
#endif
38+
3239
switch ( ulMode )
3340
{
3441
case INPUT:

0 commit comments

Comments
 (0)