Skip to content

getShuntVoltage_mV needs to use int16_t, not uint16_t #2

@we9v

Description

@we9v

Thanks for your library. Just starting trying to use it today and was wondering why several of my readings were not correct. Turns out that you're not handling negative numbers properly.

From the datasheet, section 7.6.3.2 states: This register stores the current shunt voltage reading, VSHUNT. Negative numbers are represented in two's complement format.

float INA233::getShuntVoltage_mV() {
uint16_t value=getShuntVoltage_raw();
float vshunt;
vshunt=(value*pow(10,-R_vs)-b_vs)/m_vs;
return vshunt * 1000;
}

should be:
float INA233::getShuntVoltage_mV() {
int16_t value=getShuntVoltage_raw();
float vshunt;
vshunt=(value*pow(10,-R_vs)-b_vs)/m_vs;
return vshunt * 1000;
}

There's the same problem in getCurrent_mA()...needs to use int16_t for value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions