MAX11410 high speed 24-bit Delta-Sigma ADC
Dependents: MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester
Diff: MAX11410.cpp
- Revision:
- 21:847b2220e96e
- Parent:
- 20:fb7527415308
- Child:
- 22:c6812214a933
--- a/MAX11410.cpp Sun Mar 29 17:15:20 2020 -0700 +++ b/MAX11410.cpp Mon Apr 06 05:15:22 2020 -0700 @@ -412,9 +412,6 @@ // // @future test xxxxxx // comment // -// TODO1: #169 SelfTest support @test tinyTester.print("message") -// @future test tinyTester.print("message print to console") -// // TODO1: #169 SelfTest support RegRead // @future test tinyTester.print("PART_ID value") // @test RegRead(MAX11410::CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, buffer) expect 1 expect-buffer 0x000F02 @@ -470,7 +467,6 @@ // @test RegRead(0x08, buffer) expect 1 expect-buffer 0x34 // @future test RegRead(MAX11410::CMD_enum_t::CMD_r000_1000_x0dd_dddd_FILTER, &buffer) expect 1 expect-buffer 0x34 // -// TODO1: #169 SelfTest support @test tinyTester.settle_time_msec = 250 // @test tinyTester.settle_time_msec = 250 // default 250 // @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // @test tinyTester.input_timeout_time_msec = 250 // default 250 @@ -478,14 +474,8 @@ // @test tinyTester.blink_time_msec = 20 // quickly speed through the software verification // @test tinyTester.input_timeout_time_msec = 100 // default 250 // -// TODO1: #169 SelfTest support @test tinyTester.Wait_Output_Settling() // @test tinyTester.Wait_Output_Settling() // -// TODO1: #169 SelfTest support tinyTester.AnalogIn0_Read_Expect_voltageV(2.048) -// @future test tinyTester.err_threshold = 0.030 // 30mV -// @future test tinyTester.AnalogIn0_Read_Expect_voltageV(2.048) -// -// TODO1: #169 SelfTest support tinyTester.DigitalIn_Read_Expect_WarnOnly // @future test tinyTester.DigitalIn_Read_Expect_WarnOnly(DigitalIn& digitalInPin, const char* pinName, int expect_result, const char *expect_description) // // TODO1: #169 SelfTest support tinyTester.max541.Set_Code @@ -528,8 +518,47 @@ pgaGain = 1; //---------------------------------------- + // When driver polls status of a pin signal or a register status bit, + // and there is no device physically connected, the driver must + // be able to halt and report failure if too many tries. Each attempt + // counts down until futility_countdown_limit is reached or exceeded. + // + // If driver seems to hang or takes too long to decide that device + // is not connected, reduce the futility countdown limit value. + // + // If driver sometimes works but sometimes intermittently fails to + // recognize device is attached, increase the futility countdown limit. + futility_countdown_limit = 30; + + //---------------------------------------- + // list of registers to be read by menu item * with no arguments + static MAX11410::MAX11410_CMD_enum_t readAllStatusListValues[] = { + MAX11410::CMD_r000_0000_xxxx_xxdd_PD, + MAX11410::CMD_r000_0001_xddd_xxdd_CONV_START, + MAX11410::CMD_r000_0010_xddd_dddd_SEQ_START, + MAX11410::CMD_r000_0011_xxxx_xddd_CAL_START, + MAX11410::CMD_r000_0100_dddd_xddd_GP0_CTRL, + MAX11410::CMD_r000_0101_dddd_xddd_GP1_CTRL, + MAX11410::CMD_r000_0110_xddd_xxdd_GP_CONV, + MAX11410::CMD_r000_0111_xddd_dddd_GP_SEQ_ADDR, + MAX11410::CMD_r000_1000_x0dd_dddd_FILTER, + MAX11410::CMD_r000_1001_dddd_dddd_CTRL, + MAX11410::CMD_r000_1010_dddd_dddd_SOURCE, + MAX11410::CMD_r000_1011_dddd_dddd_MUX_CTRL0, + MAX11410::CMD_r000_1100_dddd_dddd_MUX_CTRL1, + MAX11410::CMD_r000_1101_dddd_dddd_MUX_CTRL2, + MAX11410::CMD_r000_1110_xxdd_xddd_PGA, + MAX11410::CMD_r000_1111_dddd_dddd_WAIT_EXT, + MAX11410::CMD_r001_0000_xxxx_xxxx_WAIT_START, + }; + readAllStatusList = readAllStatusListValues; + + //---------------------------------------- + // number of registers to be read by menu item * with no arguments + readAllStatusListLen = 17; + + //---------------------------------------- // Device ID Validation - #warning "Not Implemented Yet: MAX11410::Init Device ID Validation..." const uint32_t part_id_expect = 0x000F02; uint32_t part_id_readback; RegRead(CMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback); @@ -559,9 +588,10 @@ // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). // @return physical voltage corresponding to MAX11410 code. // -// @test tinyTester.blink_time_msec = 20 // quickly speed through the software verification -// @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 // Verify function VoltageOfCode_Unipolar +// @test group UNIPOLAR tinyTester.blink_time_msec = 20 // quickly speed through the software verification +// @test group UNIPOLAR Configure_CTRL_REF(2) expect 1 // These tests require REF2 = 2.500V +// @test group UNIPOLAR 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 @@ -576,7 +606,7 @@ // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000002) expect 0.00000029802326 // Two LSB // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000001) expect 0.00000014901162 // One LSB // @test group UNIPOLAR VoltageOfCode_Unipolar(0x000000) expect 0.0 // Zero Scale -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group UNIPOLAR tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::VoltageOfCode_Unipolar(uint32_t value_u24) { @@ -616,9 +646,10 @@ // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). // @return physical voltage corresponding to MAX11410 code. // -// @test tinyTester.blink_time_msec = 20 // quickly speed through the software verification -// @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 // Verify function VoltageOfCode_Bipolar_OffsetBinary +// @test group BIPOB tinyTester.blink_time_msec = 20 // quickly speed through the software verification +// @test group BIPOB Configure_CTRL_REF(2) expect 1 // These tests require REF2 = 2.500V +// @test group BIPOB 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 @@ -632,7 +663,7 @@ // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x400000) expect -1.25 // Negative Mid Scale // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x000001) expect -2.5 // Negative Full Scale // @test group BIPOB VoltageOfCode_Bipolar_OffsetBinary(0x000000) expect -2.5 // Negative Full Scale -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group BIPOB tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::VoltageOfCode_Bipolar_OffsetBinary(uint32_t value_u24) { @@ -673,9 +704,10 @@ // @param[in] value_u24: raw 24-bit MAX11410 code (right justified). // @return physical voltage corresponding to MAX11410 code. // -// @test tinyTester.blink_time_msec = 20 // quickly speed through the software verification -// @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 // Verify function VoltageOfCode_Bipolar_2sComplement +// @test group BIP2C tinyTester.blink_time_msec = 20 // quickly speed through the software verification +// @test group BIP2C Configure_CTRL_REF(2) expect 1 // These tests require REF2 = 2.500V +// @test group BIP2C 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 @@ -699,7 +731,7 @@ // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x99999A) expect -2.000 // Negative Two Volts // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x800001) expect -2.500 // Negative Full Scale // @test group BIP2C VoltageOfCode_Bipolar_2sComplement(0x800000) expect -2.500 // Negative Full Scale -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group BIP2C tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::VoltageOfCode_Bipolar_2sComplement(uint32_t value_u24) { @@ -744,10 +776,6 @@ { //---------------------------------------- - // warning -- WIP work in progress - #warning "Not Tested Yet: MAX11410::VoltageOfCode..." - - //---------------------------------------- // Determine format from CTRL register U_BN and FORMAT uint8_t u_bn_bitmask = (1 << 6); uint8_t format_bitmask = (1 << 5); @@ -798,7 +826,7 @@ { //---------------------------------------- - // switch based on register address szie RegSize(commandByte) + // switch based on register address size RegSize(commandByte) commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); switch(RegSize(commandByte)) { @@ -882,7 +910,7 @@ { //---------------------------------------- - // switch based on register address szie RegSize(regAddress) + // switch based on register address size RegSize(regAddress) commandByte = (MAX11410_CMD_enum_t)((commandByte &~ CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); switch(RegSize(commandByte)) { @@ -1770,11 +1798,10 @@ //---------------------------------------- // 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; + for (int futility_countdown = futility_countdown_limit; ((futility_countdown > 0) && ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); futility_countdown--) @@ -1866,8 +1893,7 @@ // 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" + // 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 @@ -1886,11 +1912,10 @@ //---------------------------------------- // 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; + for (int futility_countdown = futility_countdown_limit; ((futility_countdown > 0) && ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); futility_countdown--) @@ -1922,13 +1947,14 @@ // @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 tinyTester.blink_time_msec = 20 // quickly speed through the software verification +// @test group RTD_PT1000 // PT1000 type Resistive Temperature Device (RTD) +// @test group RTD_PT1000 tinyTester.blink_time_msec = 20 // quickly speed through the software verification // @test group RTD_PT1000 TemperatureOfRTD_PT1000(842.94) expect -40.0 within 0.1 // PT-1000 RTD at -40C // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1000.0) expect 0.0 within 0.1 // PT-1000 RTD at 0C // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1097.3) expect 25.0 within 0.1 // PT-1000 RTD at 25C // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1328.1) expect 85.0 within 0.1 // PT-1000 RTD at 85C // @test group RTD_PT1000 TemperatureOfRTD_PT1000(1479.5) expect 125.0 within 0.1 // PT-1000 RTD at 125C -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group RTD_PT1000 tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::TemperatureOfRTD_PT1000(double rtd_resistance) { @@ -1954,13 +1980,14 @@ // @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 tinyTester.blink_time_msec = 20 // quickly speed through the software verification +// @test group RTD_PT100 // PT100 type Resistive Temperature Device (RTD) +// @test group RTD_PT100 tinyTester.blink_time_msec = 20 // quickly speed through the software verification // @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 -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group RTD_PT100 tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::TemperatureOfRTD_PT100(double rtd_resistance) { @@ -1998,7 +2025,7 @@ // @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 -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group RTD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::TemperatureOfRTD(double rtd_resistance) { @@ -2016,7 +2043,7 @@ } //---------------------------------------- -// Menu item 'TM' +// Menu item 'TM' -> tc_voltage, tc_deltaT, tc_Temperature // Trigger Measurement for Thermocouple // // Example code for typical Thermocouple measurement. @@ -2029,16 +2056,15 @@ // @param[in] rtd_ainp = channel RTD high side sense, default=AINP_SEL_1000_AIN8 // @param[in] rtd_ainn = channel RTD low side, default=AINN_SEL_1001_AIN9 // @post AINcode[tc_ainp]: measurement result LSB code +// @post tc_voltage: raw thermocouple voltage in Volts +// @post tc_deltaT: temperature in degC above cold junction +// @post tc_Temperature: temperature in degC // // @return 1 on success; 0 on failure double MAX11410::Measure_Thermocouple(MAX11410_AINP_SEL_enum_t tc_ainp, MAX11410_AINN_SEL_enum_t tc_ainn, MAX11410_AINP_SEL_enum_t rtd_iout, MAX11410_AINP_SEL_enum_t rtd_ainp, MAX11410_AINN_SEL_enum_t rtd_ainn) { //---------------------------------------- - // warning -- WIP work in progress - #warning "Not Implemented Yet: MAX11410::Measure_Thermocouple..." - - //---------------------------------------- // restrict channel selection to valid index range if ((uint8_t)tc_ainp > /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD) { @@ -2103,11 +2129,10 @@ //---------------------------------------- // 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; + for (int futility_countdown = futility_countdown_limit; ((futility_countdown > 0) && ((status & /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0)); futility_countdown--) @@ -2122,11 +2147,22 @@ //---------------------------------------- // ideal voltage calculated from raw LSB code and reference voltage - return VoltageOfCode(AINcode[((int)tc_ainp & 0x0F)]); + tc_voltage = VoltageOfCode(AINcode[((int)tc_ainp & 0x0F)]); + + //---------------------------------------- + // ideal voltage calculated from raw LSB code and reference voltage + tc_deltaT = TemperatureOfTC_TypeK(tc_voltage); + + //---------------------------------------- + // ideal voltage calculated from raw LSB code and reference voltage + tc_Temperature = RTD_Temperature + tc_deltaT; + + //---------------------------------------- + // ideal voltage calculated from raw LSB code and reference voltage + return tc_voltage; } //---------------------------------------- -// Menu item 'TK' // Return the physical temperature corresponding to measured voltage // of a type K Thermocouple (TC). // @@ -2134,7 +2170,9 @@ // @param[in] tc_voltage = Thermocouple voltage in volts, default=0.0254 // // @return ideal temperature in degrees C, calculated from RTD resistance in ohms -// @test tinyTester.blink_time_msec = 20 // quickly speed through the software verification +// @test group TC_1 // Verify Thermocouple function TemperatureOfTC_TypeK +// @test group TC_2 // Verify Thermocouple function TemperatureOfTC_TypeK in more detail +// @test group TC_1 tinyTester.blink_time_msec = 20 // quickly speed through the software verification // @test group TC_1 TemperatureOfTC_TypeK(0.000e-3) expect 0.0 within 0.1 // TC_TypeK at 0C = 0.000mV // @test group TC_1 TemperatureOfTC_TypeK(0.039e-3) expect 1.0 within 0.1 // TC_TypeK at 1C = 0.039mV // @test group TC_1 TemperatureOfTC_TypeK(0.079e-3) expect 2.0 within 0.1 // TC_TypeK at 2C = 0.079mV @@ -2180,7 +2218,7 @@ // @test group TC_1 TemperatureOfTC_TypeK(16.397e-3) expect 400.0 within 0.1 // TC_TypeK at 400C = 16.397mV // @test group TC_1 TemperatureOfTC_TypeK(18.516e-3) expect 450.0 within 0.1 // TC_TypeK at 450C = 18.516mV // @test group TC_1 TemperatureOfTC_TypeK(20.218e-3) expect 490.0 // TC_TypeK at 490C = 20.218mV -// @test tinyTester.blink_time_msec = 75 // default 75 resume hardware self test +// @test group TC_1 tinyTester.blink_time_msec = 75 // default 75 resume hardware self test // double MAX11410::TemperatureOfTC_TypeK(double tc_voltage) { @@ -2267,10 +2305,6 @@ { //---------------------------------------- - // warning -- WIP work in progress - #warning "Not Tested Yet: MAX11410::temperatureDegC_polynomial..." - - //---------------------------------------- // Temperature from polynomial coefficients maths double temperatureDegC = 0; int index;