Read voltage power supply with an internal reference on ONE

Hi,
I would like to measure the evolution of the power supply of the SODAQ ONE board.
I used an external supply 3.3V, so I removed the jumper SJ2 to supply the board with the 3.3V pin.
For example, I put a voltage divider with 2 x 1Mohm resistors and a 100nF capacitor, connected to A0.
I used internal reference of the board to be sure we can follow evolution of the 3.3V voltage.
But there is no difference of the value when I supply the board from 2.6V to 3.3V, the analog value is the same.
By changing gain and reference voltage by code, it is the same thing I got an other fixed value over the time.
I tried changing gain and reference voltage with the documentation here :

// Set custom reference and gain
// Valid values:
// ADC_INPUTCTRL_GAIN_1X_Val
// ADC_INPUTCTRL_GAIN_2X_Val
// ADC_INPUTCTRL_GAIN_4X_Val
// ADC_INPUTCTRL_GAIN_8X_Val
// ADC_INPUTCTRL_GAIN_16X_Val
// ADC_INPUTCTRL_GAIN_DIV2_Val

ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val;

// INTVCC1 = 1.65V or half VCC
// Valid values:
// ADC_REFCTRL_REFSEL_INT1V 1.00V
// ADC_REFCTRL_REFSEL_INTVCC0 2.23V
// ADC_REFCTRL_REFSEL_INTVCC1 1.65V
// ADC_REFCTRL_REFSEL_AREFA Voltage on AREFA (AREF Pin)
// ADC_REFCTRL_REFSEL_AREFB Voltage on AREFB (A3 Pin?)

ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0;

Or here:

void analogReference(eAnalogReference mode)
{
syncADC();
switch (mode)
{
case AR_INTERNAL:
case AR_INTERNAL2V23:
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC0_Val; // 1/1.48 VDDANA = 1/1.48* 3V3 = 2.2297
break;

case AR_EXTERNAL:
  ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val;      // Gain Factor Selection
  ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val;
  break;

case AR_INTERNAL1V0:
  ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val;      // Gain Factor Selection
  ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val;   // 1.0V voltage reference
  break;

case AR_INTERNAL1V65:
  ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val;      // Gain Factor Selection
  ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
  break;

case AR_DEFAULT:
default:
  ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val;
  ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INTVCC1_Val; // 1/2 VDDANA = 0.5* 3V3 = 1.65V
  break;

}
}

Do you have some idea if it is possible to have this process ?

Thank you in advance,
Olivier

Hi Olivier,

You must use ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val. By using ADC_INPUTCTRL_GAIN_1X_Val you’re constantly clipping it to the maximum value.

What you probably want to use is an option not given by default by Arduino:
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val;
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; // 1.0V voltage reference

Remember, your sanitized analog input voltage may not be higher than the reference voltage.

Regards,
Thom

Hi Thom,
Thank you for your support, with this configuration it works very fine
Best regards,
Olivier