Help with analogRead() on nRF52840 ?

0

I hope I am just missing something simple here, but I have been banging my head on the desk for a while trying to solve this very simple problem that I can't seem to find a solution for online.

I have a seeed XIAO nrf52840 and I want to simply do an analogRead(A3).

The issue is that when I apply 3 volts, the output is 2.7 volts from this code below:

#include <Arduino.h>


float mv_per_lsb = 3300.0F / 1024.0F; // 10-bit ADC with 3.3V input range

void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 3:
  int sensorValue = analogRead(A3);
  // print out the value as mV:
  Serial.println((float)sensorValue * mv_per_lsb);
  delay(50);        // delay in between reads for stability
}

I have tried other voltages and this is what I see:

INPUT: 0.5V OUTPUT: 0.47V

INPUT: 1.5V OUTPUT: 1.41V

INPUT: 3.3V OUTPUT: 3.05V

So it seems to be slightly more accurate on the lower range.

My setup is a power supply with ground connected to the GND pin on the nRF and the power connected directly to the A3 pin on the nRF. The nRF is being powered over USB.

What am I missing here?

I also confirmed with a volt meter that the voltage output from my bench power supply is outputting correct values. Lastly I tried a brand new nRF board, and got same result.

What is the actual analog reference voltage?

I dont know what the reference voltage is for this board. I assumed it is 3.3v since it is a 3.3v board?

Poor assumption! Measure the ADC reference voltage.

How do i do that?
The power at the 3 volt pin is 3.3.

Did you measure that, or is that another assumption?

Check the processor data sheet to see whether the analog reference voltage is brought out and available to measure. Also, there are probably selectable, fixed ADC reference voltages from which to choose. They may require calibration.

It is a 3.6V reference.
Changing 3300 to 3600 in my code fixed the issue.

Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.