MAX11410 high speed 24-bit Delta-Sigma ADC
Dependents: MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester
Diff: MAX11410.cpp
- Revision:
- 26:298726bd5a3f
- Parent:
- 25:c4be3afbfafd
- Child:
- 27:1cb6c42c6a93
diff -r c4be3afbfafd -r 298726bd5a3f MAX11410.cpp --- a/MAX11410.cpp Thu Apr 16 22:18:10 2020 -0700 +++ b/MAX11410.cpp Mon Apr 20 00:52:36 2020 +0000 @@ -884,6 +884,14 @@ SPIwrite16bits(mosiData16); SPIoutputCS(1); // + if (commandByte == CMD_r000_1110_00ss_0ggg_PGA) + { + // update pgaGain with 1, 2, 4, 8, 16, 32, 64, or 128 based on gain index + static uint8_t pgaGainTable[8] = {1, 2, 4, 8, 16, 32, 64, 128}; + pgaGain = (((regData >> 4) & 2) == SIG_PATH_10_PGA) + ? pgaGainTable[(uint8_t)(regData & 7)] + : 1; + } if (commandByte == CMD_r000_0011_xxxx_xddd_CAL_START) { // after RegWrite CMD_r000_0011_xxxx_xddd_CAL_START, poll status until 0x000004 CAL_RDY @@ -896,17 +904,25 @@ // A bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02 // while ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) { // possible infinite loop; need a timeout or futility countdown to escape - for (int futility_countdown = loop_limit; - ((futility_countdown > 0) && - ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000004_CAL_RDY) == 0)); - futility_countdown--) + // with one exception: skip the wait loop in the corner case where + // cal_start=1 and pga is either buffer, bypass, or GAIN_000_1 -- + // these are effectively 1V/V gain path, and since it's already handled + // by self calibration, the pga calibration command behaves as a no-operation. + if ((regData != 1) || (pgaGain != 1)) { - for (int futility_countdown_inner = 32767; - ((futility_countdown_inner > 0) && + // wait for CAL_RDY unless (cal_start=1 and pgaGain==1) + for (int futility_countdown = loop_limit; + ((futility_countdown > 0) && ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000004_CAL_RDY) == 0)); - futility_countdown_inner--) + futility_countdown--) { - RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + for (int futility_countdown_inner = 32767; + ((futility_countdown_inner > 0) && + ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000004_CAL_RDY) == 0)); + futility_countdown_inner--) + { + RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + } } } } @@ -1374,11 +1390,6 @@ { //---------------------------------------- - // pga gain 1, 2, 4, 8, 16, 32, 64, or 128 based on gain index in register pga CMD_r000_1110_00ss_0ggg_PGA - static uint8_t pgaGainTable[8] = {1, 2, 4, 8, 16, 32, 64, 128}; - pgaGain = (sigpath == SIG_PATH_10_PGA) ? pgaGainTable[(uint8_t)gain] : 1; - - //---------------------------------------- // write8 0x0E PGA RegWrite(CMD_r000_1110_00ss_0ggg_PGA, (uint8_t)(0 | (((uint8_t)sigpath & 2) << 4)