Skip to content

Commit 1fc54f5

Browse files
committed
[sam] Improved analogRead speed.
See #1418
1 parent fdf10eb commit 1fc54f5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

hardware/arduino/sam/cores/arduino/wiring_analog.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ uint32_t analogRead(uint32_t ulPin)
130130
#endif
131131

132132
#if defined __SAM3X8E__ || defined __SAM3X8H__
133+
static uint32_t latestSelectedChannel = -1;
133134
switch ( g_APinDescription[ulPin].ulAnalogChannel )
134135
{
135136
// Handling ADC 12 bits channels
@@ -147,7 +148,10 @@ uint32_t analogRead(uint32_t ulPin)
147148
case ADC11 :
148149

149150
// Enable the corresponding channel
150-
adc_enable_channel( ADC, ulChannel );
151+
if (ulChannel != latestSelectedChannel) {
152+
adc_enable_channel( ADC, ulChannel );
153+
latestSelectedChannel = ulChannel;
154+
}
151155

152156
// Start the ADC
153157
adc_start( ADC );
@@ -161,7 +165,7 @@ uint32_t analogRead(uint32_t ulPin)
161165
ulValue = mapResolution(ulValue, ADC_RESOLUTION, _readResolution);
162166

163167
// Disable the corresponding channel
164-
adc_disable_channel(ADC, ulChannel);
168+
//adc_disable_channel(ADC, ulChannel);
165169

166170
break;
167171

0 commit comments

Comments
 (0)