Hi!,
I am trying to use one of the analog inputs for reading the voltage using saadc.
Since a don't have a battery now that is about 3.5V or less, I decided to use one of the digital outputs as source.
So I have successfully activated a pin to output 2.8V, using:
nrf_gpio_cfg_output(5); nrf_gpio_pin_set(5);
Then I have connected the pin 5 to my analog input. I have configured the channel as follows:
saadc_config.low_power_mode = true; //Enable low power mode. saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT; saadc_config.oversample = SAADC_OVERSAMPLE; saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW; channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL; channel_config.gain = NRF_SAADC_GAIN1_6; channel_config.acq_time = NRF_SAADC_ACQTIME_10US; channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED; channel_config.pin_p = NRF_SAADC_INPUT_AIN0; channel_config.pin_n = NRF_SAADC_INPUT_DISABLED; channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED; channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED; //Disable pulldown resistor on the input pin
I then sample using:
nrf_drv_saadc_sample();
The problem now is that the readings I am getting are random values between 10 and 100 more or less. I would expect values closer to 2000, since the voltage is 2.8 and the gain is 1/6.
What I am doing wrong? Probably a lot :). Thank you.