MAX11410 high speed 24-bit Delta-Sigma ADC

Dependents:   MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester

Revision:
8:3a9dfa2e8234
Parent:
5:a2e74357cfc0
Child:
9:06ca88952f1c
--- a/MAX11410.cpp	Wed Jan 22 02:04:18 2020 +0000
+++ b/MAX11410.cpp	Wed Jan 22 07:50:05 2020 +0000
@@ -1487,7 +1487,7 @@
 //----------------------------------------
 // Menu item '$'
 // Measure all ADC channels in sequence.
-// @post AINcode[0..9]: measurement result LSB code
+// @post AINcode[0..10]: measurement result LSB code
 //
 // @return 1 on success; 0 on failure
 uint8_t MAX11410::Read_All_Voltages(void)
@@ -1523,6 +1523,20 @@
 {
     
     //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)ainp >  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD)
+    {
+        ainp =  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)ainn >  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND)
+    {
+        ainn =  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND;
+    }
+    
+    //----------------------------------------
     // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND
     Configure_MUX_CTRL0((uint8_t)ainp, (uint8_t)ainn);
     
@@ -1647,6 +1661,27 @@
 {
     
     //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)rtd_iout >  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD)
+    {
+        rtd_iout =  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)rtd_ainp >  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD)
+    {
+        rtd_ainp =  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)rtd_ainn >  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND)
+    { 
+        rtd_ainn =  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND;
+    }
+    
+    //----------------------------------------
     // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous)
     Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4,
                 (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100);
@@ -1781,16 +1816,76 @@
     #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)
+    {
+        tc_ainp =  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)tc_ainn >  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND)
+    {
+        tc_ainn =  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)rtd_iout >  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD)
+    {
+        rtd_iout =  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)rtd_ainp >  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD)
+    {
+        rtd_ainp =  /* MAX11410_AINP_SEL_enum_t:: */ AINP_SEL_1010_AVDD;
+    }
+    
+    //----------------------------------------
+    // restrict channel selection to valid index range
+    if ((uint8_t)rtd_ainn >  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND)
+    { 
+        rtd_ainn =  /* MAX11410_AINN_SEL_enum_t:: */ AINN_SEL_1010_GND;
+    }
+    
+    //----------------------------------------
+    // write8 0x0B MUX_CTRL0 = 0x0A to select AINP=AIN0 and AINN=GND
+    Configure_MUX_CTRL0((uint8_t)tc_ainp, (uint8_t)tc_ainn);
+    
+    //----------------------------------------
+    // write8 0x09 CTRL to select reference REF2P/REF2N; Data Format = Bipolar 2's Complement
+    Configure_CTRL(/*extclk*/ 0, /*u_bn*/ 0, /*format*/ 0,
+                /*refbufp_en*/ 0, /*refbufn_en*/ 0,
+                /*ref_sel*/ (uint8_t)REF_SEL_010_REF2P_REF2N);
+    
+    //----------------------------------------
+    // write8 0x0E PGA
+    Configure_PGA((uint8_t) /* MAX11410_SIG_PATH_enum_t:: */ SIG_PATH_00_BUFFERED, 
+                (uint8_t) /* MAX11410_GAIN_enum_t:: */ GAIN_000_1);
+    
+    //----------------------------------------
+    // write8 0x08 FILTER = 0x34 to select RATE_0100, LINEF_11_SINC4 60SPS (given CONV_TYPE_01_Continuous)
+    Configure_FILTER((uint8_t) /* MAX11410::MAX11410_LINEF_enum_t:: */ LINEF_11_SINC4,
+                (uint8_t) /* MAX11410::MAX11410_RATE_enum_t:: */ RATE_0100);
+    
+    //----------------------------------------
+    // write8 0x01 CONV_START = 0x01 to set Conversion Mode = Continuous
+    RegWrite(CMD_r000_0001_xddd_xxdd_CONV_START, 0x01);
+    
+    //----------------------------------------
     // read24 0x80|0x38 STATUS (%SW 0xB8 0 0 0)
     RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status);
     
     //----------------------------------------
-    // read24 0x80|0x30 DATA0 (%SW 0xB0 0 0 0)
-    RegRead(CMD_r011_0000_dddd_dddd_dddd_dddd_dddd_dddd_DATA0, &data0);
+    // 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)];
     
     //----------------------------------------
     // ideal voltage calculated from raw LSB code and reference voltage
-    return VoltageOfCode(AINcode[((int)rtd_ainp & 0x0F)]);
+    return VoltageOfCode(AINcode[((int)tc_ainp & 0x0F)]);
 }
 
 //----------------------------------------