Using AREF as a analog input

Hello fellow Arduino users,

For my current project do I need to read 13 different analog inputs with the Arduino nano 33 iot. I do this with the standard analog inputs A0 through A7, the digital pins D4 through D7(through this method: (SOLVED) Arduino Nano 33 IOT additional analog inputs) and AREF. The first twelve work as intended and gives me readings as expected with analogRead. The reading on AREF does it not. This reading gives only values between 302 and 401. Even if a potentiometer is connected (as seen in the picture below, with VS3 connecting to the pin AREF) gives this input these values.

For the ones who does not know, the SAMD21 datasheet (https://community.atmel.com/sites/default/files/forum_attachments/SAM-D21-Family-Datasheet-DS40001882B.pdf) states on page 27 in table 7-1 that pin PA03 (the pin that AREF is connected to) has also the input for ADC[1]. So this means that this pin has an analog input.

The code is written to be a part of a Dual active bridge measuring system. The measuring circuits give a output between 0 V and 3.3 V. To test it is this voltage simulated by a potentiometer.

The code that I use:

const uint32_t VS3 = (1ul << 3);  // Aref pin PA03
int VS3DigitalValue = 0; // Voltage sense for leg 3 in a digital value

void setup() {
    analogReference(AR_DEFAULT);
}

void loop() {
     VS3DigitalValue = analogRead(VS3);
     delayMicroseconds(3);
     VS3DigitalValue = analogRead(VS3);
     Serial.print("Voltage on VS3 input = ");
     Serial.println(/*map(*/VS3DigitalValue/*, 0, 1023, 0, 3300)*/); // To change the digital value to a digital value of the measured voltage, 
// so I should expect a value between 0 and 3300 with some noise to my choosing
 }

In addition to this did I made an adjustement to wiring_analog.c to accept pin PA03(AREF) as input. I did change:

ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[pin].ulADCChannelNumber; // Selection for the positive ADC input

to this:

if (pin == (1ul << 3)) {
        ADC->INPUTCTRL.reg = MUXPOX_PIN1; // Set the ADC input to ADC[1]
    }
    else {
        ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[pin].ulADCChannelNumber; // Selection for the positive ADC input
    }

So the question is why this happens? If anybody knows or can give me a solution then please let me know. If you have any questions do please let me know.
Schakeling potmeter arduino

AREF is an analog input but it is not intended to be used to read an analog value. The internal A/D converter(s) need a reference voltage to compare the inputs to. This reference input is AREF. You can change the value to whatever you want between o and VCC. The analog values are scaled from 0 (analog ground) to AREF (Analog Reference). On some processors there is also internal analog references that can be selected. Generally when that is done the AREF will be connected to that voltage and applying power can destroy the micro.

This line of code sets the reference voltage to the default internal reference according to wiring_analog.c. Specifically, this code sets the reference voltage to INTVCC1 which is half of voltage VDDANA (3.3 V according to the schematic). This is then halved by 2 thus setting the Vref to an internal 1.65 V and thus disconnecting the external AREF through the multiplexer REFCTRL.

So this means the AREF pin is disconnected as voltage reference and that was my intention otherwise I knew that I could not use 13 analog inputs.

This is explained in page 904 of the SAMD21 datasheet (https://community.atmel.com/sites/default/files/forum_attachments/SAM-D21-Family-Datasheet-DS40001882B.pdf)