AdiSense1000_V21 MBED API

Fork of AdiSense1000 by PoC_Team

Revision:
3:3796776e2c27
Parent:
2:625a45555a85
Child:
5:dbb2b71a59ed
--- a/main.cpp	Fri Aug 25 11:17:37 2017 +0000
+++ b/main.cpp	Fri Aug 25 12:52:52 2017 +0000
@@ -1,167 +1,193 @@
-/*!
- ******************************************************************************
- * @file:   main.cpp
- * @brief:
- *-----------------------------------------------------------------------------
- *
-Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc.
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-  - Redistributions of source code must retain the above copyright notice,
-    this list of conditions and the following disclaimer.
-  - Redistributions in binary form must reproduce the above copyright notice,
-    this list of conditions and the following disclaimer in the documentation
-    and/or other materials provided with the distribution.
-  - Modified versions of the software must be conspicuously marked as such.
-  - This software is licensed solely and exclusively for use with processors
-    manufactured by or for Analog Devices, Inc.
-  - This software may not be combined or merged with other code in any manner
-    that would cause the software to become subject to terms and conditions
-    which differ from those listed here.
-  - Neither the name of Analog Devices, Inc. nor the names of its
-    contributors may be used to endorse or promote products derived
-    from this software without specific prior written permission.
-  - The use of this software may or may not infringe the patent rights of one
-    or more patent holders.  This license does not release you from the
-    requirement that you obtain separate licenses from these patent holders
-    to use this software.
-
-THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
-TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
-NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
-PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *****************************************************************************/
-/******************************************************************************/
-/* Include Files                                                              */
-/******************************************************************************/
-#include "mbed.h"
-#include "inc/adisense1000.h"
-
-#define BITP_VALID_DATA (7)
-#define SAMPLE_COUNT (10)
-
-void setupCJC0(void);
-void setupSENSOR0(void);
-
-Serial pc(PA_11, PA_12, 115200);
-
-ADI_Channel_Config_t CJC0;
-ADI_Channel_Config_t SENSOR0;
-
-int main() {
-    uint8_t     chStatus        = 0;
-    uint16_t    deviceID        = 0;
-    uint32_t    rawSample       = 0;
-    float       temperature     = 0;
-    bool        validSample     = 0;
-    ADI_CORE_Status_t devStatus;
-    ADI_SENSE_RESULT retValue;
-
-    pc.printf("\r\n\r\n\r\n\r\n");
-
-    retValue = ADISense1000_Open();
-    pc.printf("Host - Device Comms Opened with return:  %d\r\n", retValue);
-
-    retValue = ADISense1000_GetID(&deviceID);
-    pc.printf("Read device ID 0x%lx with return %d\r\n", deviceID, retValue);
-
-    retValue = ADISense1000_GetStatus(&devStatus);
-    pc.printf("Read Status 0x%lx with return %d\r\n", devStatus, retValue);
-
-    retValue = ADISense1000_ConfigureModule();
-    pc.printf("Configure Module with return %d\r\n", retValue);
+/*!
+ ******************************************************************************
+ * @file:   main.cpp
+ * @brief:
+ *-----------------------------------------------------------------------------
+ *
+Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc.
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+  - Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+  - Redistributions in binary form must reproduce the above copyright notice,
+    this list of conditions and the following disclaimer in the documentation
+    and/or other materials provided with the distribution.
+  - Modified versions of the software must be conspicuously marked as such.
+  - This software is licensed solely and exclusively for use with processors
+    manufactured by or for Analog Devices, Inc.
+  - This software may not be combined or merged with other code in any manner
+    that would cause the software to become subject to terms and conditions
+    which differ from those listed here.
+  - Neither the name of Analog Devices, Inc. nor the names of its
+    contributors may be used to endorse or promote products derived
+    from this software without specific prior written permission.
+  - The use of this software may or may not infringe the patent rights of one
+    or more patent holders.  This license does not release you from the
+    requirement that you obtain separate licenses from these patent holders
+    to use this software.
+
+THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
+PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *****************************************************************************/
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "mbed.h"
+#include "inc/adisense1000.h"
+
+#define BITP_VALID_DATA (7)
+#define SAMPLE_COUNT (10)
+
+void setupCJC0(void);
+void setupSENSOR0(void);
+void setVoltage(void);
+void printCalTable(void);
+
+Serial pc(PA_11, PA_12, 115200);
+
+ADI_Channel_Config_t CJC0;
+ADI_Channel_Config_t SENSOR0;
+
+int main() {
+    uint8_t     chStatus        = 0;
+    uint16_t    deviceID        = 0;
+    uint32_t    rawSample       = 0;
+    float       temperature     = 0;
+    bool        validSample     = 0;
+    ADI_CORE_Status_t devStatus;
+    ADI_SENSE_RESULT retValue;
+
+    pc.printf("\r\n\r\n\r\n\r\n");
+
+    retValue = ADISense1000_Open();
+    pc.printf("Host - Device Comms Opened with return:  %d\r\n", retValue);
+
+    retValue = ADISense1000_GetID(&deviceID);
+    pc.printf("Read device ID 0x%lx with return %d\r\n", deviceID, retValue);
+
+    retValue = ADISense1000_GetStatus(&devStatus);
+    pc.printf("Read Status 0x%lx with return %d\r\n", devStatus, retValue);
+
+    retValue = ADISense1000_ConfigureModule();
+    pc.printf("Configure Module with return %d\r\n", retValue);
+
+    printCalTable();
+
+    setupCJC0();
+    pc.printf("\r\nStart CJC0 Channel Config \r\n");
+    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_CJC0, &CJC0);
+    pc.printf("Channel setup complete with return: %d\r\n", retValue);
+
+    setupSENSOR0();
+    pc.printf("\r\nStart SENSOR0 Channel Config \r\n");
+    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_0, &SENSOR0);
+    pc.printf("Channel setup complete with return: %d\r\n", retValue);
+
+    retValue = ADISense1000_StartMeasurement(CORE_COMMAND_CONVERT_WITH_RAW);
+    pc.printf("Measurement started with return: %d\r\n\r\n", retValue);
+
+
+    while(!ADISense1000_SampleReady()) {
+    }
+
+
+    for(uint8_t i=0; i<(SAMPLE_COUNT*2); i++)
+    {
+        /* Read data from the enabled channels */
+        retValue = ADISense1000_GetData(&rawSample, &temperature, &chStatus);
+        validSample = (chStatus >> BITP_VALID_DATA)&0x01;
+        pc.printf("-%s- :: Sample # %2d Channel # %2d :: -%s- :: Raw %8d  :: Temperature %.7f\r\n",
+          ((retValue>0) ? "ERROR" : "OK") , (i+1), (chStatus&0x0f), (validSample ? "VALID" : "INVALID"), rawSample, temperature);
+    }
+
+    while (true) {
+        pc.printf("()\r");
+        wait(1);
+        pc.printf("[]\r");
+        wait(1);
+    }
+
+}
+
+
+void setupCJC0(void)
+{
+    CJC0.Count.Channel_Count        =   SAMPLE_COUNT - 1;
+    CJC0.Count.Channel_Enable       =   1;
+
+    CJC0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_RTD_2W_PT100;
+    CJC0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
+    CJC0.Type.Sensor_Load_Defaults  =   0;
+
+    CJC0.Details.CJC_Publish                =   1;
+    CJC0.Details.Vbias                      =   0;
+    CJC0.Details.Reference_Buffer_Disable   =   0;
+    CJC0.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_RINT1;
+    CJC0.Details.PGA_Gain                   =   3; /* G=8 */
+
+    CJC0.Excitation.IOUT_Excitation_Current     =   4; /* 500uA */
+    CJC0.Excitation.IOUT0_Disable               =   0;
+
+    CJC0.DigitalCoding.VALUE16  =   0;
+
+    CJC0.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
+    CJC0.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
+}
+
+
+void setupSENSOR0(void)
+{
+    SENSOR0.Count.Channel_Count        =   SAMPLE_COUNT - 1;
+    SENSOR0.Count.Channel_Enable       =   1;
+
+    SENSOR0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_THERMOCOUPLE_K;
+    SENSOR0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
+    SENSOR0.Type.Sensor_Load_Defaults  =   0;
+
+    SENSOR0.Details.Vbias                      =   1;
+    SENSOR0.Details.Reference_Buffer_Disable   =   1;
+    SENSOR0.Details.Compensation_Channel       =   0; /* CJC0 */
+    SENSOR0.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
+    SENSOR0.Details.PGA_Gain                   =   5; /* G=32 */
+
+    SENSOR0.Excitation.VALUE8      =   0;
+    SENSOR0.DigitalCoding.VALUE16  =   0;
+
+    SENSOR0.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
+    SENSOR0.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
+}
+
+static float calDataBuffer[56 * 3];
+void printCalTable(void)
+{
+    ADI_SENSE_RESULT retValue;
+    unsigned dataLen, nRows, nColumns;
+
+    retValue = ADISense1000_ReadCalTable(calDataBuffer, sizeof(calDataBuffer),
+                                         &dataLen, &nRows, &nColumns);
+    pc.printf("Cal table read complete with return: %d\r\n", retValue);
+
+    pc.printf("Calibration Table:\r\n");
+    pc.printf("%6s| %10s | %10s | %10s |\r\n", "index", "25", "-40", "85");
+    for (unsigned row = 0; row < nRows; row++)
+    {
+        pc.printf("%6d", row);
+        for (unsigned col = 0; col < nColumns; col++)
+            pc.printf("| %10f ", calDataBuffer[(row * nColumns) + col]);
+        pc.printf("|\r\n");
+    }
+}
 
-    setupCJC0();
-    pc.printf("\r\nStart CJC0 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_CJC0, &CJC0);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupSENSOR0();
-    pc.printf("\r\nStart SENSOR0 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_0, &SENSOR0);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    retValue = ADISense1000_StartMeasurement(CORE_COMMAND_CONVERT_WITH_RAW);
-    pc.printf("Measurement started with return: %d\r\n\r\n", retValue);
-
-
-    while(!ADISense1000_SampleReady()) {
-    }
-
-
-    for(uint8_t i=0; i<(SAMPLE_COUNT*2); i++)
-    {
-        /* Read data from the enabled channels */
-        retValue = ADISense1000_GetData(&rawSample, &temperature, &chStatus);
-        validSample = (chStatus >> BITP_VALID_DATA)&0x01;
-        pc.printf("-%s- :: Sample # %2d Channel # %2d :: -%s- :: Raw %8d  :: Temperature %.7f\r\n",
-          ((retValue>0) ? "ERROR" : "OK") , (i+1), (chStatus&0x0f), (validSample ? "VALID" : "INVALID"), rawSample, temperature);
-    }
-
-    while (true) {
-        pc.printf("()\r");
-        wait(1);
-        pc.printf("[]\r");
-        wait(1);
-    }
-
-}
-
-
-void setupCJC0(void)
-{
-    CJC0.Count.Channel_Count        =   SAMPLE_COUNT - 1;
-    CJC0.Count.Channel_Enable       =   1;
-
-    CJC0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_RTD_2W_PT100;
-    CJC0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-    CJC0.Type.Sensor_Load_Defaults  =   0;
-
-    CJC0.Details.CJC_Publish                =   1;
-    CJC0.Details.Vbias                      =   0;
-    CJC0.Details.Reference_Buffer_Disable   =   0;
-    CJC0.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_RINT1;
-    CJC0.Details.PGA_Gain                   =   3; /* G=8 */
-
-    CJC0.Excitation.IOUT_Excitation_Current     =   4; /* 500uA */
-    CJC0.Excitation.IOUT0_Disable               =   0;
-
-    CJC0.DigitalCoding.VALUE16  =   0;
-
-    CJC0.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    CJC0.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
-
-
-void setupSENSOR0(void)
-{
-    SENSOR0.Count.Channel_Count        =   SAMPLE_COUNT - 1;
-    SENSOR0.Count.Channel_Enable       =   1;
-
-    SENSOR0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_THERMOCOUPLE_K;
-    SENSOR0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-    SENSOR0.Type.Sensor_Load_Defaults  =   0;
-
-    SENSOR0.Details.Vbias                      =   1;
-    SENSOR0.Details.Reference_Buffer_Disable   =   1;
-    SENSOR0.Details.Compensation_Channel       =   0; /* CJC0 */
-    SENSOR0.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
-    SENSOR0.Details.PGA_Gain                   =   5; /* G=32 */
-
-    SENSOR0.Excitation.VALUE8      =   0;
-    SENSOR0.DigitalCoding.VALUE16  =   0;
-
-    SENSOR0.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    SENSOR0.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
\ No newline at end of file