ADISense1000 Version 2.1 code base

Fork of AdiSense1000_V21 by Sean Wilson

Committer:
kevin1990
Date:
Fri Aug 25 12:52:52 2017 +0000
Revision:
3:3796776e2c27
Parent:
2:625a45555a85
Child:
5:dbb2b71a59ed
adding function  test code to demonstrate printing calibration table

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kevin1990 3:3796776e2c27 1 /*!
kevin1990 3:3796776e2c27 2 ******************************************************************************
kevin1990 3:3796776e2c27 3 * @file: main.cpp
kevin1990 3:3796776e2c27 4 * @brief:
kevin1990 3:3796776e2c27 5 *-----------------------------------------------------------------------------
kevin1990 3:3796776e2c27 6 *
kevin1990 3:3796776e2c27 7 Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc.
kevin1990 3:3796776e2c27 8
kevin1990 3:3796776e2c27 9 All rights reserved.
kevin1990 3:3796776e2c27 10
kevin1990 3:3796776e2c27 11 Redistribution and use in source and binary forms, with or without modification,
kevin1990 3:3796776e2c27 12 are permitted provided that the following conditions are met:
kevin1990 3:3796776e2c27 13 - Redistributions of source code must retain the above copyright notice,
kevin1990 3:3796776e2c27 14 this list of conditions and the following disclaimer.
kevin1990 3:3796776e2c27 15 - Redistributions in binary form must reproduce the above copyright notice,
kevin1990 3:3796776e2c27 16 this list of conditions and the following disclaimer in the documentation
kevin1990 3:3796776e2c27 17 and/or other materials provided with the distribution.
kevin1990 3:3796776e2c27 18 - Modified versions of the software must be conspicuously marked as such.
kevin1990 3:3796776e2c27 19 - This software is licensed solely and exclusively for use with processors
kevin1990 3:3796776e2c27 20 manufactured by or for Analog Devices, Inc.
kevin1990 3:3796776e2c27 21 - This software may not be combined or merged with other code in any manner
kevin1990 3:3796776e2c27 22 that would cause the software to become subject to terms and conditions
kevin1990 3:3796776e2c27 23 which differ from those listed here.
kevin1990 3:3796776e2c27 24 - Neither the name of Analog Devices, Inc. nor the names of its
kevin1990 3:3796776e2c27 25 contributors may be used to endorse or promote products derived
kevin1990 3:3796776e2c27 26 from this software without specific prior written permission.
kevin1990 3:3796776e2c27 27 - The use of this software may or may not infringe the patent rights of one
kevin1990 3:3796776e2c27 28 or more patent holders. This license does not release you from the
kevin1990 3:3796776e2c27 29 requirement that you obtain separate licenses from these patent holders
kevin1990 3:3796776e2c27 30 to use this software.
kevin1990 3:3796776e2c27 31
kevin1990 3:3796776e2c27 32 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
kevin1990 3:3796776e2c27 33 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
kevin1990 3:3796776e2c27 34 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
kevin1990 3:3796776e2c27 35 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
kevin1990 3:3796776e2c27 36 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
kevin1990 3:3796776e2c27 37 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
kevin1990 3:3796776e2c27 38 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
kevin1990 3:3796776e2c27 39 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
kevin1990 3:3796776e2c27 40 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
kevin1990 3:3796776e2c27 41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
kevin1990 3:3796776e2c27 42 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kevin1990 3:3796776e2c27 43 *
kevin1990 3:3796776e2c27 44 *****************************************************************************/
kevin1990 3:3796776e2c27 45 /******************************************************************************/
kevin1990 3:3796776e2c27 46 /* Include Files */
kevin1990 3:3796776e2c27 47 /******************************************************************************/
kevin1990 3:3796776e2c27 48 #include "mbed.h"
kevin1990 3:3796776e2c27 49 #include "inc/adisense1000.h"
kevin1990 3:3796776e2c27 50
kevin1990 3:3796776e2c27 51 #define BITP_VALID_DATA (7)
kevin1990 3:3796776e2c27 52 #define SAMPLE_COUNT (10)
kevin1990 3:3796776e2c27 53
kevin1990 3:3796776e2c27 54 void setupCJC0(void);
kevin1990 3:3796776e2c27 55 void setupSENSOR0(void);
kevin1990 3:3796776e2c27 56 void setVoltage(void);
kevin1990 3:3796776e2c27 57 void printCalTable(void);
kevin1990 3:3796776e2c27 58
kevin1990 3:3796776e2c27 59 Serial pc(PA_11, PA_12, 115200);
kevin1990 3:3796776e2c27 60
kevin1990 3:3796776e2c27 61 ADI_Channel_Config_t CJC0;
kevin1990 3:3796776e2c27 62 ADI_Channel_Config_t SENSOR0;
kevin1990 3:3796776e2c27 63
kevin1990 3:3796776e2c27 64 int main() {
kevin1990 3:3796776e2c27 65 uint8_t chStatus = 0;
kevin1990 3:3796776e2c27 66 uint16_t deviceID = 0;
kevin1990 3:3796776e2c27 67 uint32_t rawSample = 0;
kevin1990 3:3796776e2c27 68 float temperature = 0;
kevin1990 3:3796776e2c27 69 bool validSample = 0;
kevin1990 3:3796776e2c27 70 ADI_CORE_Status_t devStatus;
kevin1990 3:3796776e2c27 71 ADI_SENSE_RESULT retValue;
kevin1990 3:3796776e2c27 72
kevin1990 3:3796776e2c27 73 pc.printf("\r\n\r\n\r\n\r\n");
kevin1990 3:3796776e2c27 74
kevin1990 3:3796776e2c27 75 retValue = ADISense1000_Open();
kevin1990 3:3796776e2c27 76 pc.printf("Host - Device Comms Opened with return: %d\r\n", retValue);
kevin1990 3:3796776e2c27 77
kevin1990 3:3796776e2c27 78 retValue = ADISense1000_GetID(&deviceID);
kevin1990 3:3796776e2c27 79 pc.printf("Read device ID 0x%lx with return %d\r\n", deviceID, retValue);
kevin1990 3:3796776e2c27 80
kevin1990 3:3796776e2c27 81 retValue = ADISense1000_GetStatus(&devStatus);
kevin1990 3:3796776e2c27 82 pc.printf("Read Status 0x%lx with return %d\r\n", devStatus, retValue);
kevin1990 3:3796776e2c27 83
kevin1990 3:3796776e2c27 84 retValue = ADISense1000_ConfigureModule();
kevin1990 3:3796776e2c27 85 pc.printf("Configure Module with return %d\r\n", retValue);
kevin1990 3:3796776e2c27 86
kevin1990 3:3796776e2c27 87 printCalTable();
kevin1990 3:3796776e2c27 88
kevin1990 3:3796776e2c27 89 setupCJC0();
kevin1990 3:3796776e2c27 90 pc.printf("\r\nStart CJC0 Channel Config \r\n");
kevin1990 3:3796776e2c27 91 retValue = ADISense1000_ConfigureChannel(ADI_SENSE_CJC0, &CJC0);
kevin1990 3:3796776e2c27 92 pc.printf("Channel setup complete with return: %d\r\n", retValue);
kevin1990 3:3796776e2c27 93
kevin1990 3:3796776e2c27 94 setupSENSOR0();
kevin1990 3:3796776e2c27 95 pc.printf("\r\nStart SENSOR0 Channel Config \r\n");
kevin1990 3:3796776e2c27 96 retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_0, &SENSOR0);
kevin1990 3:3796776e2c27 97 pc.printf("Channel setup complete with return: %d\r\n", retValue);
kevin1990 3:3796776e2c27 98
kevin1990 3:3796776e2c27 99 retValue = ADISense1000_StartMeasurement(CORE_COMMAND_CONVERT_WITH_RAW);
kevin1990 3:3796776e2c27 100 pc.printf("Measurement started with return: %d\r\n\r\n", retValue);
kevin1990 3:3796776e2c27 101
kevin1990 3:3796776e2c27 102
kevin1990 3:3796776e2c27 103 while(!ADISense1000_SampleReady()) {
kevin1990 3:3796776e2c27 104 }
kevin1990 3:3796776e2c27 105
kevin1990 3:3796776e2c27 106
kevin1990 3:3796776e2c27 107 for(uint8_t i=0; i<(SAMPLE_COUNT*2); i++)
kevin1990 3:3796776e2c27 108 {
kevin1990 3:3796776e2c27 109 /* Read data from the enabled channels */
kevin1990 3:3796776e2c27 110 retValue = ADISense1000_GetData(&rawSample, &temperature, &chStatus);
kevin1990 3:3796776e2c27 111 validSample = (chStatus >> BITP_VALID_DATA)&0x01;
kevin1990 3:3796776e2c27 112 pc.printf("-%s- :: Sample # %2d Channel # %2d :: -%s- :: Raw %8d :: Temperature %.7f\r\n",
kevin1990 3:3796776e2c27 113 ((retValue>0) ? "ERROR" : "OK") , (i+1), (chStatus&0x0f), (validSample ? "VALID" : "INVALID"), rawSample, temperature);
kevin1990 3:3796776e2c27 114 }
kevin1990 3:3796776e2c27 115
kevin1990 3:3796776e2c27 116 while (true) {
kevin1990 3:3796776e2c27 117 pc.printf("()\r");
kevin1990 3:3796776e2c27 118 wait(1);
kevin1990 3:3796776e2c27 119 pc.printf("[]\r");
kevin1990 3:3796776e2c27 120 wait(1);
kevin1990 3:3796776e2c27 121 }
kevin1990 3:3796776e2c27 122
kevin1990 3:3796776e2c27 123 }
kevin1990 3:3796776e2c27 124
kevin1990 3:3796776e2c27 125
kevin1990 3:3796776e2c27 126 void setupCJC0(void)
kevin1990 3:3796776e2c27 127 {
kevin1990 3:3796776e2c27 128 CJC0.Count.Channel_Count = SAMPLE_COUNT - 1;
kevin1990 3:3796776e2c27 129 CJC0.Count.Channel_Enable = 1;
kevin1990 3:3796776e2c27 130
kevin1990 3:3796776e2c27 131 CJC0.Type.Sensor_Type = CORE_SENSOR_TYPE_SENSOR_RTD_2W_PT100;
kevin1990 3:3796776e2c27 132 CJC0.Type.Sensor_Category = CORE_SENSOR_TYPE_ANALOG;
kevin1990 3:3796776e2c27 133 CJC0.Type.Sensor_Load_Defaults = 0;
kevin1990 3:3796776e2c27 134
kevin1990 3:3796776e2c27 135 CJC0.Details.CJC_Publish = 1;
kevin1990 3:3796776e2c27 136 CJC0.Details.Vbias = 0;
kevin1990 3:3796776e2c27 137 CJC0.Details.Reference_Buffer_Disable = 0;
kevin1990 3:3796776e2c27 138 CJC0.Details.Reference_Select = CORE_SENSOR_DETAILS_REF_RINT1;
kevin1990 3:3796776e2c27 139 CJC0.Details.PGA_Gain = 3; /* G=8 */
kevin1990 3:3796776e2c27 140
kevin1990 3:3796776e2c27 141 CJC0.Excitation.IOUT_Excitation_Current = 4; /* 500uA */
kevin1990 3:3796776e2c27 142 CJC0.Excitation.IOUT0_Disable = 0;
kevin1990 3:3796776e2c27 143
kevin1990 3:3796776e2c27 144 CJC0.DigitalCoding.VALUE16 = 0;
kevin1990 3:3796776e2c27 145
kevin1990 3:3796776e2c27 146 CJC0.FilterSelect.ADC_Filter_Type = CORE_FILTER_SELECT_FIR;
kevin1990 3:3796776e2c27 147 CJC0.FilterSelect.ADC_FIR_Sel = 3; /* 25 SPS */;
kevin1990 3:3796776e2c27 148 }
kevin1990 3:3796776e2c27 149
kevin1990 3:3796776e2c27 150
kevin1990 3:3796776e2c27 151 void setupSENSOR0(void)
kevin1990 3:3796776e2c27 152 {
kevin1990 3:3796776e2c27 153 SENSOR0.Count.Channel_Count = SAMPLE_COUNT - 1;
kevin1990 3:3796776e2c27 154 SENSOR0.Count.Channel_Enable = 1;
kevin1990 3:3796776e2c27 155
kevin1990 3:3796776e2c27 156 SENSOR0.Type.Sensor_Type = CORE_SENSOR_TYPE_SENSOR_THERMOCOUPLE_K;
kevin1990 3:3796776e2c27 157 SENSOR0.Type.Sensor_Category = CORE_SENSOR_TYPE_ANALOG;
kevin1990 3:3796776e2c27 158 SENSOR0.Type.Sensor_Load_Defaults = 0;
kevin1990 3:3796776e2c27 159
kevin1990 3:3796776e2c27 160 SENSOR0.Details.Vbias = 1;
kevin1990 3:3796776e2c27 161 SENSOR0.Details.Reference_Buffer_Disable = 1;
kevin1990 3:3796776e2c27 162 SENSOR0.Details.Compensation_Channel = 0; /* CJC0 */
kevin1990 3:3796776e2c27 163 SENSOR0.Details.Reference_Select = CORE_SENSOR_DETAILS_REF_INT;
kevin1990 3:3796776e2c27 164 SENSOR0.Details.PGA_Gain = 5; /* G=32 */
kevin1990 3:3796776e2c27 165
kevin1990 3:3796776e2c27 166 SENSOR0.Excitation.VALUE8 = 0;
kevin1990 3:3796776e2c27 167 SENSOR0.DigitalCoding.VALUE16 = 0;
kevin1990 3:3796776e2c27 168
kevin1990 3:3796776e2c27 169 SENSOR0.FilterSelect.ADC_Filter_Type = CORE_FILTER_SELECT_FIR;
kevin1990 3:3796776e2c27 170 SENSOR0.FilterSelect.ADC_FIR_Sel = 3; /* 25 SPS */;
kevin1990 3:3796776e2c27 171 }
kevin1990 3:3796776e2c27 172
kevin1990 3:3796776e2c27 173 static float calDataBuffer[56 * 3];
kevin1990 3:3796776e2c27 174 void printCalTable(void)
kevin1990 3:3796776e2c27 175 {
kevin1990 3:3796776e2c27 176 ADI_SENSE_RESULT retValue;
kevin1990 3:3796776e2c27 177 unsigned dataLen, nRows, nColumns;
kevin1990 3:3796776e2c27 178
kevin1990 3:3796776e2c27 179 retValue = ADISense1000_ReadCalTable(calDataBuffer, sizeof(calDataBuffer),
kevin1990 3:3796776e2c27 180 &dataLen, &nRows, &nColumns);
kevin1990 3:3796776e2c27 181 pc.printf("Cal table read complete with return: %d\r\n", retValue);
kevin1990 3:3796776e2c27 182
kevin1990 3:3796776e2c27 183 pc.printf("Calibration Table:\r\n");
kevin1990 3:3796776e2c27 184 pc.printf("%6s| %10s | %10s | %10s |\r\n", "index", "25", "-40", "85");
kevin1990 3:3796776e2c27 185 for (unsigned row = 0; row < nRows; row++)
kevin1990 3:3796776e2c27 186 {
kevin1990 3:3796776e2c27 187 pc.printf("%6d", row);
kevin1990 3:3796776e2c27 188 for (unsigned col = 0; col < nColumns; col++)
kevin1990 3:3796776e2c27 189 pc.printf("| %10f ", calDataBuffer[(row * nColumns) + col]);
kevin1990 3:3796776e2c27 190 pc.printf("|\r\n");
kevin1990 3:3796776e2c27 191 }
kevin1990 3:3796776e2c27 192 }
kevin1990 2:625a45555a85 193