Test, please delete

Committer:
kevin1990
Date:
Fri Aug 25 11:17:37 2017 +0000
Revision:
2:625a45555a85
Child:
3:3796776e2c27
Sensor Channel 0 Type K example

Who changed what in which revision?

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