(Working) Code to interface 3 LoadCells to ADISense1000 and display values using the Labview code.

Fork of 4Bridge_ADISense1000_Example_copy by CAC_smartcushion

Committer:
RGurav
Date:
Wed Aug 08 08:08:53 2018 +0000
Revision:
3:83d10123d1cd
Parent:
2:2f9f9f7f0243
(Working); Code to interface 3 loadCell to ADISense1000 and display using Labview code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
seanwilson10 0:76fed7dd9235 1 /*
seanwilson10 0:76fed7dd9235 2 ******************************************************************************
seanwilson10 0:76fed7dd9235 3 * file: main.cpp
seanwilson10 0:76fed7dd9235 4 *-----------------------------------------------------------------------------
seanwilson10 0:76fed7dd9235 5 *
seanwilson10 0:76fed7dd9235 6 Copyright 2017 (c) Analog Devices, Inc.
seanwilson10 0:76fed7dd9235 7
seanwilson10 0:76fed7dd9235 8 All rights reserved.
seanwilson10 0:76fed7dd9235 9
seanwilson10 0:76fed7dd9235 10 Redistribution and use in source and binary forms, with or without
seanwilson10 0:76fed7dd9235 11 modification, are permitted provided that the following conditions are met:
seanwilson10 0:76fed7dd9235 12 - Redistributions of source code must retain the above copyright
seanwilson10 0:76fed7dd9235 13 notice, this list of conditions and the following disclaimer.
seanwilson10 0:76fed7dd9235 14 - Redistributions in binary form must reproduce the above copyright
seanwilson10 0:76fed7dd9235 15 notice, this list of conditions and the following disclaimer in
seanwilson10 0:76fed7dd9235 16 the documentation and/or other materials provided with the
seanwilson10 0:76fed7dd9235 17 distribution.
seanwilson10 0:76fed7dd9235 18 - Neither the name of Analog Devices, Inc. nor the names of its
seanwilson10 0:76fed7dd9235 19 contributors may be used to endorse or promote products derived
seanwilson10 0:76fed7dd9235 20 from this software without specific prior written permission.
seanwilson10 0:76fed7dd9235 21 - The use of this software may or may not infringe the patent rights
seanwilson10 0:76fed7dd9235 22 of one or more patent holders. This license does not release you
seanwilson10 0:76fed7dd9235 23 from the requirement that you obtain separate licenses from these
seanwilson10 0:76fed7dd9235 24 patent holders to use this software.
seanwilson10 0:76fed7dd9235 25 - Use of the software either in source or binary form, must be run
seanwilson10 0:76fed7dd9235 26 on or directly connected to an Analog Devices Inc. component.
seanwilson10 0:76fed7dd9235 27
seanwilson10 0:76fed7dd9235 28 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
seanwilson10 0:76fed7dd9235 29 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
seanwilson10 0:76fed7dd9235 30 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
seanwilson10 0:76fed7dd9235 31 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
seanwilson10 0:76fed7dd9235 32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
seanwilson10 0:76fed7dd9235 33 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
seanwilson10 0:76fed7dd9235 34 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
seanwilson10 0:76fed7dd9235 35 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
seanwilson10 0:76fed7dd9235 36 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
seanwilson10 0:76fed7dd9235 37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
seanwilson10 0:76fed7dd9235 38 *
seanwilson10 0:76fed7dd9235 39 *****************************************************************************/
seanwilson10 0:76fed7dd9235 40 #include "mbed.h"
seanwilson10 0:76fed7dd9235 41 #include "inc/adi_sense_api.h"
seanwilson10 0:76fed7dd9235 42 #include "inc/adi_sense_1000/adi_sense_1000_api.h"
seanwilson10 0:76fed7dd9235 43 #include "inc/adi_sense_log.h"
seanwilson10 0:76fed7dd9235 44 #include "common/utils.h"
seanwilson10 0:76fed7dd9235 45
RGurav 2:2f9f9f7f0243 46 extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config;
RGurav 2:2f9f9f7f0243 47
RGurav 2:2f9f9f7f0243 48 extern ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[];
RGurav 2:2f9f9f7f0243 49 extern ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[];
RGurav 2:2f9f9f7f0243 50 extern unsigned sample_lut_num_tables;
seanwilson10 0:76fed7dd9235 51
seanwilson10 0:76fed7dd9235 52 /* Change the following pointer to select any of the configurations above */
RGurav 2:2f9f9f7f0243 53 static ADI_SENSE_CONFIG *pSelectedConfig = &sensor2_bridge_6w_pressure_config;
seanwilson10 0:76fed7dd9235 54
seanwilson10 0:76fed7dd9235 55 static ADI_SENSE_CONNECTION connectionInfo = {
seanwilson10 0:76fed7dd9235 56 .type = ADI_SENSE_CONNECTION_TYPE_SPI,
seanwilson10 0:76fed7dd9235 57 .spi = {
seanwilson10 0:76fed7dd9235 58 .mosiPin = SPI_MOSI,
seanwilson10 0:76fed7dd9235 59 .misoPin = SPI_MISO,
seanwilson10 0:76fed7dd9235 60 .sckPin = SPI_SCK,
seanwilson10 0:76fed7dd9235 61 .csPin = D10,
seanwilson10 0:76fed7dd9235 62 .maxSpeedHz = 2000000,
seanwilson10 0:76fed7dd9235 63 },
seanwilson10 0:76fed7dd9235 64 .gpio = {
seanwilson10 0:76fed7dd9235 65 .resetPin = D6,
seanwilson10 0:76fed7dd9235 66 .errorPin = D3,
seanwilson10 0:76fed7dd9235 67 .alertPin = D4,
seanwilson10 0:76fed7dd9235 68 .datareadyPin = D5,
seanwilson10 0:76fed7dd9235 69 },
seanwilson10 0:76fed7dd9235 70 };
seanwilson10 0:76fed7dd9235 71
seanwilson10 0:76fed7dd9235 72 int main()
seanwilson10 0:76fed7dd9235 73 {
seanwilson10 0:76fed7dd9235 74 ADI_SENSE_RESULT res;
seanwilson10 0:76fed7dd9235 75 ADI_SENSE_DEVICE_HANDLE hDevice;
seanwilson10 0:76fed7dd9235 76 ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL;
seanwilson10 0:76fed7dd9235 77 bool_t bDeviceReady;
seanwilson10 0:76fed7dd9235 78
seanwilson10 0:76fed7dd9235 79 /*
seanwilson10 0:76fed7dd9235 80 * Open an ADI Sense device instance.
seanwilson10 0:76fed7dd9235 81 */
seanwilson10 0:76fed7dd9235 82 res = adi_sense_Open(0, &connectionInfo, &hDevice);
seanwilson10 0:76fed7dd9235 83 if (res != ADI_SENSE_SUCCESS)
seanwilson10 0:76fed7dd9235 84 {
seanwilson10 0:76fed7dd9235 85 ADI_SENSE_LOG_ERROR("Failed to open device instance");
seanwilson10 0:76fed7dd9235 86 return res;
seanwilson10 0:76fed7dd9235 87 }
seanwilson10 0:76fed7dd9235 88
seanwilson10 0:76fed7dd9235 89 /*
seanwilson10 0:76fed7dd9235 90 * Reset the given ADI Sense device....
seanwilson10 0:76fed7dd9235 91 */
seanwilson10 0:76fed7dd9235 92 ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait...");
seanwilson10 0:76fed7dd9235 93 res = adi_sense_Reset(hDevice);
seanwilson10 0:76fed7dd9235 94 if (res != ADI_SENSE_SUCCESS)
seanwilson10 0:76fed7dd9235 95 {
seanwilson10 0:76fed7dd9235 96 ADI_SENSE_LOG_ERROR("Failed to reset device");
seanwilson10 0:76fed7dd9235 97 return res;
seanwilson10 0:76fed7dd9235 98 }
seanwilson10 0:76fed7dd9235 99 /*
seanwilson10 0:76fed7dd9235 100 * ...and wait until the device is ready.
seanwilson10 0:76fed7dd9235 101 */
seanwilson10 0:76fed7dd9235 102 do {
seanwilson10 0:76fed7dd9235 103 wait_ms(100);
seanwilson10 0:76fed7dd9235 104 res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady);
seanwilson10 0:76fed7dd9235 105 if (res != ADI_SENSE_SUCCESS)
seanwilson10 0:76fed7dd9235 106 {
seanwilson10 0:76fed7dd9235 107 ADI_SENSE_LOG_ERROR("Failed to get device ready-state");
seanwilson10 0:76fed7dd9235 108 return res;
seanwilson10 0:76fed7dd9235 109 }
seanwilson10 0:76fed7dd9235 110 } while (! bDeviceReady);
seanwilson10 0:76fed7dd9235 111 ADI_SENSE_LOG_INFO("ADI Sense device ready");
seanwilson10 0:76fed7dd9235 112
seanwilson10 0:76fed7dd9235 113 /*
seanwilson10 0:76fed7dd9235 114 * Write configuration settings to the device registers.
seanwilson10 0:76fed7dd9235 115 * Settings are not applied until adi_sense_ApplyConfigUpdates() is called.
seanwilson10 0:76fed7dd9235 116 */
seanwilson10 0:76fed7dd9235 117 ADI_SENSE_LOG_INFO("Setting device configuration");
seanwilson10 0:76fed7dd9235 118 res = adi_sense_SetConfig(hDevice, pSelectedConfig);
seanwilson10 0:76fed7dd9235 119 if (res != ADI_SENSE_SUCCESS)
seanwilson10 0:76fed7dd9235 120 {
seanwilson10 0:76fed7dd9235 121 ADI_SENSE_LOG_ERROR("Failed to set device configuration");
seanwilson10 0:76fed7dd9235 122 return res;
seanwilson10 0:76fed7dd9235 123 }
RGurav 2:2f9f9f7f0243 124
RGurav 2:2f9f9f7f0243 125
RGurav 2:2f9f9f7f0243 126 /*
RGurav 2:2f9f9f7f0243 127 * Assemble the list of user-defined Look-Up Tables from sample_lut_data.c
RGurav 2:2f9f9f7f0243 128 * into the single contiguous data format required by the device.
RGurav 2:2f9f9f7f0243 129 */
RGurav 2:2f9f9f7f0243 130 unsigned lutBufferSize = ADI_SENSE_LUT_MAX_SIZE;
RGurav 2:2f9f9f7f0243 131 ADI_SENSE_1000_LUT *pLutBuffer = (ADI_SENSE_1000_LUT *) ::operator new (lutBufferSize);
RGurav 2:2f9f9f7f0243 132 if (pLutBuffer == NULL)
RGurav 2:2f9f9f7f0243 133 {
RGurav 2:2f9f9f7f0243 134 ADI_SENSE_LOG_ERROR("Failed to allocate memory for user-defined LUT data buffer");
RGurav 2:2f9f9f7f0243 135 return ADI_SENSE_NO_MEM;
RGurav 2:2f9f9f7f0243 136 }
RGurav 2:2f9f9f7f0243 137
RGurav 2:2f9f9f7f0243 138 ADI_SENSE_LOG_INFO("Assembling LUT data");
RGurav 2:2f9f9f7f0243 139 res = adi_sense_1000_AssembleLutData(pLutBuffer, lutBufferSize,
RGurav 2:2f9f9f7f0243 140 sample_lut_num_tables,
RGurav 2:2f9f9f7f0243 141 sample_lut_desc_list,
RGurav 2:2f9f9f7f0243 142 sample_lut_data_list);
RGurav 2:2f9f9f7f0243 143 if (res != ADI_SENSE_SUCCESS)
RGurav 2:2f9f9f7f0243 144 {
RGurav 2:2f9f9f7f0243 145 ADI_SENSE_LOG_ERROR("Failed to assemble user-defined LUT data");
RGurav 2:2f9f9f7f0243 146 return res;
RGurav 2:2f9f9f7f0243 147 }
RGurav 2:2f9f9f7f0243 148
RGurav 2:2f9f9f7f0243 149 /*
RGurav 2:2f9f9f7f0243 150 * Write assembled user-defined Look-Up Table data structure to the device
RGurav 2:2f9f9f7f0243 151 * User-defined LUT data is not applied until adi_sense_ApplyConfigUpdates() is called.
RGurav 2:2f9f9f7f0243 152 */
RGurav 2:2f9f9f7f0243 153 ADI_SENSE_LOG_INFO("Setting LUT data");
RGurav 2:2f9f9f7f0243 154 res = adi_sense_1000_SetLutData(hDevice, pLutBuffer);
RGurav 2:2f9f9f7f0243 155 if (res != ADI_SENSE_SUCCESS)
RGurav 2:2f9f9f7f0243 156 {
RGurav 2:2f9f9f7f0243 157 ADI_SENSE_LOG_ERROR("Failed to set user-defined LUT data");
RGurav 2:2f9f9f7f0243 158 return res;
RGurav 2:2f9f9f7f0243 159 }
RGurav 2:2f9f9f7f0243 160
RGurav 2:2f9f9f7f0243 161 delete pLutBuffer;
RGurav 2:2f9f9f7f0243 162
seanwilson10 0:76fed7dd9235 163 res = adi_sense_ApplyConfigUpdates(hDevice);
seanwilson10 0:76fed7dd9235 164 if (res != ADI_SENSE_SUCCESS)
seanwilson10 0:76fed7dd9235 165 {
seanwilson10 0:76fed7dd9235 166 ADI_SENSE_LOG_ERROR("Failed to apply device configuration");
seanwilson10 0:76fed7dd9235 167 return res;
seanwilson10 0:76fed7dd9235 168 }
seanwilson10 0:76fed7dd9235 169 /*
seanwilson10 0:76fed7dd9235 170 * Kick off the measurement cycle here
seanwilson10 0:76fed7dd9235 171 */
seanwilson10 0:76fed7dd9235 172 ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles");
seanwilson10 0:76fed7dd9235 173 utils_runMeasurement(hDevice, eMeasurementMode);
seanwilson10 0:76fed7dd9235 174
seanwilson10 0:76fed7dd9235 175 /*
seanwilson10 0:76fed7dd9235 176 * Clean up and exit
seanwilson10 0:76fed7dd9235 177 */
seanwilson10 0:76fed7dd9235 178 res = adi_sense_Close(hDevice);
seanwilson10 0:76fed7dd9235 179 if (res != ADI_SENSE_SUCCESS)
seanwilson10 0:76fed7dd9235 180 {
seanwilson10 0:76fed7dd9235 181 ADI_SENSE_LOG_ERROR("Failed to close device instance");
seanwilson10 0:76fed7dd9235 182 return res;
seanwilson10 0:76fed7dd9235 183 }
seanwilson10 0:76fed7dd9235 184
seanwilson10 0:76fed7dd9235 185 return 0;
seanwilson10 0:76fed7dd9235 186 }
seanwilson10 0:76fed7dd9235 187