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.