npm1300 readings delayed by one measurement

Hi,

I am using the npm1300 with the nrf9160 with ncs2.7

When we do a reading from the npm1300 to get the current and voltage values, the readings are always delayed by 1 reading.  So for example, if I have the voltage set to 3.7V, and then change it to 3.6V and wait several seconds, when I read the pmic values it reads 3.7V.  If I read again it shows 3.6V.

Here is the code we are using for reading. I am working on getting an i2c trace of the communication

void pmic_read_sensors(void)
{
    struct sensor_value volt;
    struct sensor_value current;
    struct sensor_value temp;
    struct sensor_value error;
    struct sensor_value status;

    sensor_sample_fetch(charger);
    sensor_channel_get(charger, SENSOR_CHAN_GAUGE_VOLTAGE, &volt);
    sensor_channel_get(charger, SENSOR_CHAN_GAUGE_AVG_CURRENT, &current);
    sensor_channel_get(charger, SENSOR_CHAN_GAUGE_TEMP, &temp);
    sensor_channel_get(charger, SENSOR_CHAN_NPM1300_CHARGER_STATUS, &status);
    sensor_channel_get(charger, SENSOR_CHAN_NPM1300_CHARGER_ERROR, &error);

    LOG_DBG("V: %d.%03d ", volt.val1, volt.val2 / 1000);

    LOG_DBG("I: %s%d.%04d ", ((current.val1 < 0) || (current.val2 < 0)) ? "-" : "", abs(current.val1),
            abs(current.val2) / 100);

    LOG_DBG("T: %s%d.%02d", ((temp.val1 < 0) || (temp.val2 < 0)) ? "-" : "", abs(temp.val1), abs(temp.val2) / 10000);

    LOG_DBG("Charger Status: %d, Error: %d", status.val1, error.val1);
}

Parents Reply Children
  • dave said:
    If I want the immediate results can I call sensor_fetch() twice back to back?  Do I need to leave any time in between for the ADC to process?

    This would work, however, it is not ideal in terms of energy consumption.

    The conversion time, tconv is 250 µs per sample. Four samples are triggered by the fetch() function (battery voltage, battery current, battery ntc, die temperature).

    On the nPM1300 EK we trigger sampling, wait for it to be done, and then read out the result. This way one will get the latest result. 

    It is possible to do ADC readings from the application with manual I2C reads/writes. We have functions for this in npm1300.h: mfd_npm1300_reg_write and mfd_npm1300_reg_read.

Related