MAX11410 high speed 24-bit Delta-Sigma ADC
Dependents: MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester
Diff: MAX11410.cpp
- Revision:
- 16:00aa1e5a6843
- Parent:
- 15:d5781c8fc002
- Child:
- 17:0e9f2dfc2a30
--- a/MAX11410.cpp Tue Mar 10 16:18:14 2020 -0700 +++ b/MAX11410.cpp Wed Mar 11 02:43:49 2020 -0700 @@ -475,6 +475,7 @@ // @return physical voltage corresponding to MAX11410 code. // // @test Configure_CTRL_REF(2) expect 1 These tests require REF2 = 2.500V +// @test Configure_PGA(0,0) expect 1 These tests require PGA gain=1 // @test group UNIPOLAR VoltageOfCode_Unipolar(0xFFFFFF) expect 2.500 within 0.030 Full Scale // @test group UNIPOLAR VoltageOfCode_Unipolar(0xFFFFFE) expect 2.500 Full Scale // @test group UNIPOLAR VoltageOfCode_Unipolar(0xCCCCCC) expect 2.000 Two Volts @@ -529,6 +530,7 @@ // @return physical voltage corresponding to MAX11410 code. // // @test Configure_CTRL_REF(2) expect 1 These tests require REF2 = 2.500V +// @test Configure_PGA(0,0) expect 1 These tests require PGA gain=1 // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xFFFFFF) expect 2.5 within 0.030 Full Scale // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xFFFFFE) expect 2.5 Full Scale // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0xC00000) expect 1.25 Mid Scale @@ -583,6 +585,7 @@ // @return physical voltage corresponding to MAX11410 code. // // @test Configure_CTRL_REF(2) expect 1 These tests require REF2 = 2.500V +// @test Configure_PGA(0,0) expect 1 These tests require PGA gain=1 // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x7FFFFF) expect 2.500 within 0.030 Full Scale // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x7FFFFE) expect 2.500 Full Scale // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x666666) expect 2.000 Two Volts @@ -1661,7 +1664,7 @@ // 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 = 30; + for (int futility_countdown = 3000; ((futility_countdown > 0) && ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); futility_countdown--) @@ -1748,12 +1751,22 @@ (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_001_2); //---------------------------------------- + // diagnostic GPIO pulse on GP1 during RTD_power_up_interval_msec + RegWrite(CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc3); // diagnostic GPIO pulse GP1 + // write8 0x05 GP1_CTRL (%SW 0x05 0xc3) 11000 output 011 logic 0 + + //---------------------------------------- // TODO1: timing delay after enable RTD bias current #warning "Not Implemented Yet: timing delay after enable RTD bias current" const int RTD_power_up_interval_msec = 100; // timing delay after enable RTD bias current wait_ms(RTD_power_up_interval_msec); // timing delay function, platform-specific //---------------------------------------- + // diagnostic GPIO pulse on GP1 during RTD_power_up_interval_msec + RegWrite(CMD_r000_0101_dddd_xddd_GP1_CTRL, 0xc4); // diagnostic GPIO pulse GP1 + // write8 0x05 GP1_CTRL (%SW 0x05 0xc4) 11000 output 100 logic 1 + + //---------------------------------------- // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01); @@ -1762,6 +1775,20 @@ RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); //---------------------------------------- + // TODO1: wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available + #warning "Not Verified Yet: wait until STATUS indicates data is available" + // 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 = 3000; + ((futility_countdown > 0) && + ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); + futility_countdown--) + { + RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + } + + //---------------------------------------- // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[ainp] = measurement RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)rtd_ainp & 0x0F)]); data0 = AINcode[((int)rtd_ainp & 0x0F)]; @@ -1773,7 +1800,7 @@ //---------------------------------------- // resistance calculated from raw LSB code and VRef_REF1 reference resistance in ohms rtd_resistance = VoltageOfCode(AINcode[((int)rtd_ainp & 0x0F)]); - TemperatureOfRTD_PT1000(rtd_resistance); // calculate RTD_Temperature + TemperatureOfRTD(rtd_resistance); // calculate RTD_Temperature return rtd_resistance; } @@ -1808,6 +1835,70 @@ } //---------------------------------------- +// Return the physical temperature corresponding to measured resistance +// of a PT100 type Resistive Temperature Device (RTD). +// +// @param[in] rtd_resistance = RTD resistance in ohms, default=100 +// @post RTD_Temperature: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C +// +// @return ideal temperature in degrees C, calculated from RTD resistance in ohms +// @test group RTD_PT100 TemperatureOfRTD_PT100(84.294) expect -40.0 within 0.1 PT-100 RTD at -40C +// @test group RTD_PT100 TemperatureOfRTD_PT100(100.00) expect 0.0 within 0.1 PT-100 RTD at 0C +// @test group RTD_PT100 TemperatureOfRTD_PT100(109.73) expect 25.0 within 0.1 PT-100 RTD at 25C +// @test group RTD_PT100 TemperatureOfRTD_PT100(132.81) expect 85.0 within 0.1 PT-100 RTD at 85C +// @test group RTD_PT100 TemperatureOfRTD_PT100(147.95) expect 125.0 within 0.1 PT-100 RTD at 125C +// +double MAX11410::TemperatureOfRTD_PT100(double rtd_resistance) +{ + + //---------------------------------------- + // Temperature from RTD Resistance maths + // ITS-90 PT-100 RTD + double R0 = 100.0; + double a = 3.9083e-3; + double b = -5.7750e-7; + // calculate T from R and R0 + double sqrtTerm = sqrt(R0*R0 * a*a - 4*R0*b*(R0 - rtd_resistance)); + double denominator = 2 * R0 * b; + RTD_Temperature = ((-R0 * a) + (sqrtTerm)) / denominator; + return RTD_Temperature; +} + +//---------------------------------------- +// Return the physical temperature corresponding to measured resistance +// of a PT100 or PT1000 type Resistive Temperature Device (RTD). +// +// @param[in] rtd_resistance = RTD resistance in ohms, default=100 +// @post RTD_Temperature: Temperature calculated from RTD Resistance; Thermocouple Cold Junction, in degrees C +// +// @return ideal temperature in degrees C, calculated from RTD resistance in ohms +// @test group RTD TemperatureOfRTD(84.294) expect -40.0 within 0.1 PT-100 RTD at -40C +// @test group RTD TemperatureOfRTD(100.00) expect 0.0 within 0.1 PT-100 RTD at 0C +// @test group RTD TemperatureOfRTD(109.73) expect 25.0 within 0.1 PT-100 RTD at 25C +// @test group RTD TemperatureOfRTD(132.81) expect 85.0 within 0.1 PT-100 RTD at 85C +// @test group RTD TemperatureOfRTD(147.95) expect 125.0 within 0.1 PT-100 RTD at 125C +// @test group RTD TemperatureOfRTD(842.94) expect -40.0 within 0.1 PT-1000 RTD at -40C +// @test group RTD TemperatureOfRTD(1000.0) expect 0.0 within 0.1 PT-1000 RTD at 0C +// @test group RTD TemperatureOfRTD(1097.3) expect 25.0 within 0.1 PT-1000 RTD at 25C +// @test group RTD TemperatureOfRTD(1328.1) expect 85.0 within 0.1 PT-1000 RTD at 85C +// @test group RTD TemperatureOfRTD(1479.5) expect 125.0 within 0.1 PT-1000 RTD at 125C +// +double MAX11410::TemperatureOfRTD(double rtd_resistance) +{ + + //---------------------------------------- + // return TemperatureOfRTD_PT100 or TemperatureOfRTD_PT1000 + if (rtd_resistance > 500.0) + { + return TemperatureOfRTD_PT1000(rtd_resistance); + } + else + { + return TemperatureOfRTD_PT100(rtd_resistance); + } +} + +//---------------------------------------- // Menu item 'TM' // Trigger Measurement for Thermocouple // @@ -1894,6 +1985,20 @@ RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); //---------------------------------------- + // TODO1: wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available + #warning "Not Verified Yet: wait until STATUS indicates data is available" + // 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 = 3000; + ((futility_countdown > 0) && + ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); + futility_countdown--) + { + RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status); + } + + //---------------------------------------- // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0): AINcode[tc_ainp] = measurement RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &AINcode[((int)tc_ainp & 0x0F)]); data0 = AINcode[((int)tc_ainp & 0x0F)];