significant bit handling fixes

This commit is contained in:
Wolfgang Hottgenroth
2014-11-16 19:19:49 +01:00
parent cb329623af
commit 5422180fd5
2 changed files with 6 additions and 4 deletions

View File

@ -74,10 +74,12 @@ void ADS1210::exec() {
//Serial << "DOR4x8: " << _HEX(res.in[3]) << " " << _HEX(res.in[2]) << " " << _HEX(res.in[1]) << " " << _HEX(res.in[0]) << endl; //Serial << "DOR4x8: " << _HEX(res.in[3]) << " " << _HEX(res.in[2]) << " " << _HEX(res.in[1]) << " " << _HEX(res.in[0]) << endl;
//Serial << "DOR1x32: " << _HEX(res.out) << endl; //Serial << "DOR1x32: " << _HEX(res.out) << endl;
value = (res.out & V_MASK); value = res.out >> SKIPPED_BITS;
u = (((float)value) / ((float)V_MAX)) * U_REF; uint32_t vMax = V_MAX >> SKIPPED_BITS;
rRaw = ((((float)V_MAX) / ((float)value)) - 1.0) * R_REF;
u = (((float)value) / ((float)vMax)) * U_REF;
rRaw = ((((float)vMax) / ((float)value)) - 1.0) * R_REF;
r = (rRaw + m_calOffset) * m_calFactor; r = (rRaw + m_calOffset) * m_calFactor;
} }
} }

View File

@ -75,7 +75,7 @@ private:
const uint32_t V_MAX = 0x3FFFFF; const uint32_t V_MAX = 0x3FFFFF;
const float R_REF = 3000.0; const float R_REF = 3000.0;
const uint32_t V_MASK = 0x3FFFF0; const uint8_t SKIPPED_BITS = 4;
uint8_t m_csPin; uint8_t m_csPin;
uint8_t m_drdyPin; uint8_t m_drdyPin;