Hi,
i am trying to read ADC value from my nrf9160 dev board, i can get the exact value upto 2.5v, if i go morethan 2.5v it decrease the ADC value. my values are
voltage 2.5 = 690
voltage 2.6 = 605
voltage 2.7 = 595
......
voltage 3.6 = 360
but i need full scale value while 3.6V (1024).
my code here
#include <adc.h>
#include <hal/nrf_saadc.h>
#define ADC_DEVICE_NAME DT_ADC_0_NAME
#define ADC_RESOLUTION 10
#define ADC_GAIN ADC_GAIN_1_6
#define ADC_REFERENCE ADC_REF_INTERNAL
#define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)
#define ADC_1ST_CHANNEL_ID 0
static s16_t m_sample_buffer[1];
struct adc_channel_cfg m_1st_channel_cfg;
struct device *adc_dev;
int16_t ADC_RAW_DATA(int Channel_pin);
int16_t Adc_Data_Read(int channel_Id);
int16_t ADC_RAW_DATA(int Channel_pin)
{
int err;
int16_t ret;
m_1st_channel_cfg.gain = ADC_GAIN;
m_1st_channel_cfg.reference = ADC_REFERENCE;
m_1st_channel_cfg.acquisition_time = ADC_ACQUISITION_TIME;
m_1st_channel_cfg.channel_id = ADC_1ST_CHANNEL_ID;
m_1st_channel_cfg.input_positive = Channel_pin;
printk("nrf91 saadc sampling starts\n");
adc_dev = device_get_binding("ADC_0");
if (!adc_dev) {
printk("device_get_binding ADC_0 failed\n");
}
err = adc_channel_setup(adc_dev, &m_1st_channel_cfg);
if (err) {
printk("Error in adc setup: %d\n", err);
}
NRF_SAADC_NS->TASKS_CALIBRATEOFFSET = 1;
{
ret = Adc_Data_Read(ADC_1ST_CHANNEL_ID);
if (err) {
printk("Error in adc sampling: %d\n", err);
}
}
return ret;
}
int16_t Adc_Data_Read(int channel_Id)
{
int ret;
uint8_t cnt;
int16_t data[5]={0};
struct adc_sequence sequence = {
.channels = BIT(channel_Id),
.buffer = m_sample_buffer,
.buffer_size = sizeof(m_sample_buffer),
.resolution = ADC_RESOLUTION,
};
cnt = 0;
do
{
ret = adc_read(adc_dev, &sequence);
//printk("ADC read err: %d\n", ret);
data[cnt++] = m_sample_buffer[0];
}while(cnt <= 5);
return ((data[1]+data[2]+data[3]+data[4])/4);
}
lp me out this.
Thanks & Regards
hmdra