From d14b46e08c05f55c56f7dc1fb7f98e774ddf0c73 Mon Sep 17 00:00:00 2001
From: Thibaut VIARD <thibaut.viard@atmel.com>
Date: Wed, 17 Sep 2014 18:43:05 +0200
Subject: [PATCH]  fixing default analog reference

Signed-off-by: Thibaut VIARD <thibaut.viard@atmel.com>
---
 cores/arduino/wiring_analog.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c
index 1547068e..305a0909 100644
--- a/cores/arduino/wiring_analog.c
+++ b/cores/arduino/wiring_analog.c
@@ -54,19 +54,23 @@ static inline uint32_t mapResolution( uint32_t value, uint32_t from, uint32_t to
   }
 }
 
+/*
+ * Internal Reference is at 1.0v
+ * External Reference should be between 1v and VDDANA-0.6v=2.7v
+ *
+ * Warning : On Arduino Zero board the input/output voltage for SAMD21G18 is 3.3 volts maximum
+ */
 void analogReference( eAnalogReference ulMode )
 {
-  // ATTENTION : On this board the default is not 5volts or 3.3volts BUT 1volt
-
   switch ( ulMode )
   {
-    case AR_DEFAULT:
     case AR_INTERNAL:
-    default:
       ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val;
       break;
 
+    case AR_DEFAULT:
     case AR_EXTERNAL:
+    default:
       ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val;
       break;
   }
@@ -75,6 +79,7 @@ void analogReference( eAnalogReference ulMode )
 uint32_t analogRead( uint32_t ulPin )
 {
   uint32_t valueRead = 0;
+
   pinPeripheral(ulPin, g_APinDescription[ulPin].ulPinType);
 
   ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[ulPin].ulADCChannelNumber;
-- 
GitLab