Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.

Dependencies:   MaximTinyTester CmdLine MAX541 USBDevice

Revision:
93:6b22269935a6
Parent:
91:9e78c6194d6e
--- a/MAX11043/MAX11043.cpp	Mon Mar 02 23:00:51 2020 +0000
+++ b/MAX11043/MAX11043.cpp	Wed Mar 04 10:03:12 2020 +0000
@@ -779,6 +779,106 @@
 }
 
 //----------------------------------------
+// Return the physical voltage corresponding to conversion result
+// (conversion format is Bipolar mode, 2's complement)
+// Does not perform any offset or gain correction.
+//
+// @pre CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT is 0: 16-bit mode is configured
+// @pre VRef = Voltage of REF input, in Volts
+// @param[in] value_u24: raw 24-bit MAX11043 code (right justified).
+// @return physical voltage corresponding to MAX11043 code.
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x7FFF) expect 2.500 within 0.030 Full Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x7FFF) expect 2.500             Full Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x6666) expect 2.000             Two Volts
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x6000) expect 1.875             75% Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x4000) expect 1.250             Mid Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x3333) expect 1.000             One Volt
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x2000) expect 0.625             25% Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x051e) expect 0.100             100mV
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.00000894069671  Three LSB
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.00000596046447  Two LSB
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.0000029802326   One LSB
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.0               Zero Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xFFFF) expect -0.0000029802326  Negative One LSB
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xFFFF) expect -0.0000059604644  Negative Two LSB
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xFFFF) expect -0.0000089406967  Negative Three LSB
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xFAE1) expect -0.100            Negative 100mV
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xE000) expect -0.625            Negative 25% Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xCCCC) expect -1.000            Negative One Volt
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xC000) expect -1.250            Negative Mid Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0xA000) expect -1.875            Negative 75% Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x9999) expect -2.000            Negative Two Volts
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x8000) expect -2.500            Negative Full Scale
+// @test group BIP2C16 ADCVoltageOfCode_16bit(0x8000) expect -2.500            Negative Full Scale
+//
+double MAX11043::ADCVoltageOfCode_16bit(uint32_t value_u16)
+{
+    
+    //----------------------------------------
+    // Linear map min and max endpoints
+    double MaxScaleVoltage = 2 * VRef; // voltage of maximum code 0x7fff
+    double MinScaleVoltage = 0; // voltage of minimum code 0x8000
+    const int32_t FULL_SCALE_CODE_16BIT_2S_COMPLEMENT = 0x7fff;
+    const int32_t SIGN_BIT_16BIT_2S_COMPLEMENT = 0x8000;
+    if (value_u16 >= SIGN_BIT_16BIT_2S_COMPLEMENT) { value_u16 = value_u16 - (2 * SIGN_BIT_16BIT_2S_COMPLEMENT); }
+    const int32_t MaxCode = FULL_SCALE_CODE_16BIT_2S_COMPLEMENT;
+    const int32_t CodeSpan = 0x10000;
+    const int32_t MinCode = 0;
+    double codeFraction = ((double)((int32_t)value_u16) - MinCode) / CodeSpan;
+    return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)); //  / pgaGain;
+}
+
+//----------------------------------------
+// Return the physical voltage corresponding to conversion result
+// (conversion format is Bipolar mode, 2's complement)
+// Does not perform any offset or gain correction.
+//
+// @pre CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT is 1: 24-bit mode is configured
+// @pre VRef = Voltage of REF input, in Volts
+// @param[in] value_u24: raw 24-bit MAX11043 code (right justified).
+// @return physical voltage corresponding to MAX11043 code.
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x7FFFFF) expect 2.500 within 0.030 Full Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x7FFFFE) expect 2.500             Full Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x666666) expect 2.000             Two Volts
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x600000) expect 1.875             75% Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x400000) expect 1.250             Mid Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x333333) expect 1.000             One Volt
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x200000) expect 0.625             25% Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x051eb8) expect 0.100             100mV
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x000003) expect 0.00000894069671  Three LSB
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x000002) expect 0.00000596046447  Two LSB
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x000001) expect 0.0000029802326   One LSB
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x000000) expect 0.0               Zero Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xFFFFFF) expect -0.0000029802326  Negative One LSB
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xFFFFFE) expect -0.0000059604644  Negative Two LSB
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xFFFFFD) expect -0.0000089406967  Negative Three LSB
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xFAE148) expect -0.100            Negative 100mV
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xE00000) expect -0.625            Negative 25% Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xCCCCCD) expect -1.000            Negative One Volt
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xC00000) expect -1.250            Negative Mid Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0xA00000) expect -1.875            Negative 75% Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x99999A) expect -2.000            Negative Two Volts
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x800001) expect -2.500            Negative Full Scale
+// @test group BIP2C24 ADCVoltageOfCode_24bit(0x800000) expect -2.500            Negative Full Scale
+//
+double MAX11043::ADCVoltageOfCode_24bit(uint32_t value_u24)
+{
+    
+    //----------------------------------------
+    // Linear map min and max endpoints
+    double MaxScaleVoltage = 2 * VRef; // voltage of maximum code 0x7fffff
+    double MinScaleVoltage = 0; // voltage of minimum code 0x800000
+    const int32_t FULL_SCALE_CODE_24BIT_2S_COMPLEMENT = 0x7fffff;
+    const int32_t SIGN_BIT_24BIT_2S_COMPLEMENT = 0x800000;
+    if (value_u24 >= SIGN_BIT_24BIT_2S_COMPLEMENT) { value_u24 = value_u24 - (2 * SIGN_BIT_24BIT_2S_COMPLEMENT); }
+    const int32_t MaxCode = FULL_SCALE_CODE_24BIT_2S_COMPLEMENT;
+    const int32_t CodeSpan = 0x1000000;
+    const int32_t MinCode = 0;
+    double codeFraction = ((double)((int32_t)value_u24) - MinCode) / CodeSpan;
+    return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)); //  / pgaGain;
+}
+
+//----------------------------------------
 // Write a MAX11043 register.
 //
 // CMDOP_1aaa_aaaa_ReadRegister bit is cleared 0 indicating a write operation.
@@ -946,10 +1046,10 @@
 // @return 1 on success; 0 on failure
 uint8_t MAX11043::RegRead(MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData)
 {
-#define SIGN_EXTEND_INT16_VALUE(x) (((x)&(0x8000))?((x)-65536):(x))
     
     //----------------------------------------
     // switch based on register address szie RegSize(regAddress)
+    #define SIGN_EXTEND_INT16_VALUE(x) (((x)&(0x8000))?((x)-65536):(x))
     //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF);
     switch(RegSize(commandByte))
     {
@@ -1554,7 +1654,7 @@
 // Menu item 'GA'
 // Write AGain register
 //
-// @param[in] gain 2's complement, 0x800=0.25V/V, 0x1000=0.5V/V, 0x2000=1VV/V, 0x4000=2V/V, default=0x2000
+// @param[in] gain 2's complement, 0x800=0.25V/V, 0x1000=0.5V/V, 0x2000=1V/V, 0x4000=2V/V, default=0x2000
 //
 // @return 1 on success; 0 on failure
 uint8_t MAX11043::Write_AGain(uint32_t gain)