[sam] Improved analogRead speed.

See #1418
This commit is contained in:
Cristian Maglie 2013-10-09 16:19:16 +02:00
parent fdf10eb663
commit 1fc54f5003
1 changed files with 6 additions and 2 deletions

View File

@ -130,6 +130,7 @@ uint32_t analogRead(uint32_t ulPin)
#endif
#if defined __SAM3X8E__ || defined __SAM3X8H__
static uint32_t latestSelectedChannel = -1;
switch ( g_APinDescription[ulPin].ulAnalogChannel )
{
// Handling ADC 12 bits channels
@ -147,7 +148,10 @@ uint32_t analogRead(uint32_t ulPin)
case ADC11 :
// Enable the corresponding channel
adc_enable_channel( ADC, ulChannel );
if (ulChannel != latestSelectedChannel) {
adc_enable_channel( ADC, ulChannel );
latestSelectedChannel = ulChannel;
}
// Start the ADC
adc_start( ADC );
@ -161,7 +165,7 @@ uint32_t analogRead(uint32_t ulPin)
ulValue = mapResolution(ulValue, ADC_RESOLUTION, _readResolution);
// Disable the corresponding channel
adc_disable_channel(ADC, ulChannel);
//adc_disable_channel(ADC, ulChannel);
break;