This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

INA238: INA238 Current sensing

Part Number: INA238

We are using INA238 for current sensing, we are using Eval board INA238 with our ST microcontroller. We are using R shunt= 50 mOhm and it is calculated as per datasheet 

For Shunt calculation referring this equation SHUNT_CAL = 819.2 x 10^6 x CURRENT_LSB x RSHUNT

Derived Current LSB considering our maximum current 2.4A

Current LSB = (2.4) / (2^15) 

We are keeping  all default configurations.

But still, we not able to get exact or nearest current value after reading through directly current resistors.  

could you please guide on these, if we are missing anything? 

  • Hi,

    It looks like you’re following exactly section 8.1.2. How far away are the measurements from true value? It could be an accuracy issue, if the device setup is correct.

    To avoid chasing down the wrong path, I would take one step back and make sure the shunt voltage is measured correctly. Comparing the measured Vshunt with a DVM reading taken at the input pins is a good start. Once Vshunt lines up correctly, then we can come back to figure out current measurement if it continues to be a problem.

    Regards, Guang  

  • Hello Gaung, 

    Thanks for quick support. 

    We have captured some of Shunt voltages w. r. t current. 

    Rshunt (Ohm)  Set current (mA) Shunt voltage  measured at hardware level  (mV)  Shunt  Voltage measured at firmware level  (mV)  Difference (mV)
    0.05 130 6.3 6.05 0.25
    0.05 256 12.9 11.14 1.76
    0.05 430 21.9 24.2 -2.3

    Actual it shows difference in hardware level and Firmware level.    

    We have also tried to measure the Bus Voltage and it is working too well, we are getting same bust voltage as per settled voltage. 

    Let me know, what we are missing in the shunt voltages and Current Sense. 

  • Hi,

    Can you loop the measurement many times, at say 430mA, and observe if the results are stable? At the same time, is the DVM reading stable? You can print out the shunt register values.

    An alternative is to remove the shunt resistor and apply a voltage source to the inputs. Often times, it is easier to debug.

    There is no pattern in the current data and it is hard to speculate what is causing the difference.

    Regards, Guang  

  • Hello,

    Yes. Results are stable & DVM reading are also stable.

    We removed the shunt resistor and applied the voltage source and try to read the values, but we are continually getting same value.

    below is our code  for VShunt, Current sense and Vbus

    int i2c__ina_238_read_raw_data(uint32_t dev_add, uint8_t reg, uint16_t *read_data)
    {
    HAL_StatusTypeDef ret_status;
    uint8_t read_buff[2] = {0};

    ret_status = HAL_I2C_Mem_Read(&hi2c1,(dev_add << 1), (uint16_t) reg, 1, read_buff, 2, 100);
    if(ret_status != HAL_OK) {
    // uart__write("ERROR:: i2c__ina_238_read_raw_data failed\n\r");
    return 0;
    }
    *read_data = (uint16_t)(read_buff[0] << 8) | (uint16_t)(read_buff[1]);
    return 1;
    }

    int i2c__ina_238_write_data(uint32_t dev_add, uint8_t reg, uint16_t write_data)
    {
    HAL_StatusTypeDef ret_status;
    uint8_t write_buff[2] = {0};
    write_buff[0] = (write_data >> 8);
    write_buff[0] = write_data;
    ret_status = HAL_I2C_Mem_Write(&hi2c1,(dev_add << 1), (uint16_t) reg, 1, write_buff, 2, 100);
    if(ret_status != HAL_OK) {
    // uart__write("ERROR:: i2c__ina_238_write_data failed\n\r");
    return 0;
    }
    return 1;
    }

    float curr;
    i2c__ina_238_read_raw_data(0x40, INA_238_CURRENT, &raw_vltg);

    if(raw_vltg > 0x7FFF) {
    raw_vltg = (float)raw_vltg - 0x10000;
    }
    curr = raw_vltg * 0.0000006;

    HAL_Delay(100);


    i2c__ina_238_read_raw_data(0x40, INA_238_CURRENT, &raw_vltg);
    if(raw_vltg > 0x7FFF) {
    raw_vltg = (float)raw_vltg - 0x10000;
    }
    curr = raw_vltg * 0.000305;
    HAL_Delay(100);

    i2c__ina_238_read_raw_data(0x40, INA_238_VBUS, &raw_vltg);
    if(raw_vltg > 0x7FFF) {
    raw_vltg = (float)raw_vltg - 0x10000;
    }
    float vbus = (float) (0.003125) * raw_vltg;
    HAL_Delay(100);

    i2c__ina_238_read_raw_data(0x40, INA_238_V_SHUNT, &raw_vltg);
    if(raw_vltg > 0x7FFF) {
    raw_vltg = (float)raw_vltg - 0x10000;
    }
    float vshunt = (float)0.000005 * raw_vltg;
    HAL_Delay(100);

    We are able to read the Vbus value, only issue with current sense part.

  • Hi,
    By “continually getting same value.”, do you mean the phenomenon is the same as before?
    Can you step the input shunt voltage through a list of values and list side by side the actual Vshunt and the INA238 measurements?
    Because current is simply calculated from Vshunt, we can focus on Vshunt for now and current will naturally follow.
    Regards, Guang

  • Hello Guang, 

    continually getting same value means we are getting same value 0 for any current. 

    Now I have changed load and try to read Vshunt , we received same Vshunt value through firmware.

    Sr.no current(mA)  Vshunt (mV) hardware Vshunt (mV) Software
    1 530 26.45 26.41
    2 605 30.4 30.235
    3 725 36.64 36.54
    4 890 45.513 45.4

     still, we are not able to read current.

    for current sense, is it really necessary to calculate SHUNT_CAL for current measurement?

    We are trying to set the SHUNT_CAL register, but we are getting some garbage value.

    Do you have any idea, what is the procedure SHUNT_CAL, write and read.  

  • Hi Sonal,

    As we discussed on the call, you’ve resolved this issue by following the I2C read/read command section of the datasheet, and are able to read both voltage and current now.

    We’ll close this thread.

    Regards, Guang