Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ADISense1000_Example_FW by
Revision 2:2f9f9f7f0243, committed 2018-07-19
- Comitter:
- RGurav
- Date:
- Thu Jul 19 13:25:33 2018 +0000
- Parent:
- 1:ae66eccef75f
- Commit message:
- (Working); Code to read values from bridge load cell
Changed in this revision
--- a/main.cpp Wed Jul 18 11:40:48 2018 +0000 +++ b/main.cpp Thu Jul 19 13:25:33 2018 +0000 @@ -43,10 +43,14 @@ #include "inc/adi_sense_log.h" #include "common/utils.h" -extern ADI_SENSE_CONFIG config; +extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config; + +extern ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[]; +extern ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[]; +extern unsigned sample_lut_num_tables; /* Change the following pointer to select any of the configurations above */ -static ADI_SENSE_CONFIG *pSelectedConfig = &config; +static ADI_SENSE_CONFIG *pSelectedConfig = &sensor2_bridge_6w_pressure_config; static ADI_SENSE_CONNECTION connectionInfo = { .type = ADI_SENSE_CONNECTION_TYPE_SPI, @@ -117,13 +121,51 @@ ADI_SENSE_LOG_ERROR("Failed to set device configuration"); return res; } + + + /* + * Assemble the list of user-defined Look-Up Tables from sample_lut_data.c + * into the single contiguous data format required by the device. + */ + unsigned lutBufferSize = ADI_SENSE_LUT_MAX_SIZE; + ADI_SENSE_1000_LUT *pLutBuffer = (ADI_SENSE_1000_LUT *) ::operator new (lutBufferSize); + if (pLutBuffer == NULL) + { + ADI_SENSE_LOG_ERROR("Failed to allocate memory for user-defined LUT data buffer"); + return ADI_SENSE_NO_MEM; + } + + ADI_SENSE_LOG_INFO("Assembling LUT data"); + res = adi_sense_1000_AssembleLutData(pLutBuffer, lutBufferSize, + sample_lut_num_tables, + sample_lut_desc_list, + sample_lut_data_list); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to assemble user-defined LUT data"); + return res; + } + + /* + * Write assembled user-defined Look-Up Table data structure to the device + * User-defined LUT data is not applied until adi_sense_ApplyConfigUpdates() is called. + */ + ADI_SENSE_LOG_INFO("Setting LUT data"); + res = adi_sense_1000_SetLutData(hDevice, pLutBuffer); + if (res != ADI_SENSE_SUCCESS) + { + ADI_SENSE_LOG_ERROR("Failed to set user-defined LUT data"); + return res; + } + + delete pLutBuffer; + res = adi_sense_ApplyConfigUpdates(hDevice); if (res != ADI_SENSE_SUCCESS) { ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); return res; } - /* * Kick off the measurement cycle here */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sample_lut_data.c Thu Jul 19 13:25:33 2018 +0000 @@ -0,0 +1,57 @@ +#include "adi_sense_1000_lut_data.h" +#include "adi_sense_1000_sensor_types.h" + +/* + * The following example illustrates how individual tables can be declared, and + * later assembled into a complete LUT data structure using + * adi_sense_1000_AssembleLutData(). That LUT data structure can then be + * written to the ADI Sense 1000 device using adi_sense_1000_SetLutData(). + */ + + + +/* + * The following table provide linearisation data for a 4-wire bridge sensor + * identified with the ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_1_DEF_L2 + * sensor type. The Look-Up Table provided maps a range of input (X) + * values to a corresponding range of output (Y) values. In this example, + * the bridge sensor input in millivolts is effectively translated to volts. + */ +ADI_SENSE_1000_LUT_DESCRIPTOR bridge_4wire_1_def_l2_range1_desc = { + .geometry = ADI_SENSE_1000_LUT_GEOMETRY_NES_1D, + .equation = ADI_SENSE_1000_LUT_EQUATION_LUT, + .dir = ADI_SENSE_1000_LUT_TC_DIRECTION_FORWARD, + .sensor = ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2, + .dataType = ADI_SENSE_1000_LUT_DATA_TYPE_FLOAT32, + .length = 0, /* Filled by adi_sense_1000_AssembleLutData() */ + .crc16 = 0 /* Filled by adi_sense_1000_AssembleLutData() */ +}; +ADI_SENSE_1000_LUT_1D_NES bridge_4wire_1_def_l2_range1_data = { + .nElements = 2, + .lut = { + -3300.0f, /* x(min) */ + +3300.0f, /* x(max) */ + -3.3f, /* y(min) */ + +3.3f, /* y(max) */ + }, +}; + +/* + * The following variables can be passed as parameters to + * adi_sense_1000_AssembleLutData() + */ +ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[] = { + + &bridge_4wire_1_def_l2_range1_desc, + +}; + +ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[] = { + + (ADI_SENSE_1000_LUT_TABLE_DATA *) &bridge_4wire_1_def_l2_range1_data, + +}; + +unsigned sample_lut_num_tables = + (sizeof(sample_lut_desc_list) / sizeof(sample_lut_desc_list[0])); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensor2_bridge-6w-pressure_config.c Thu Jul 19 13:25:33 2018 +0000 @@ -0,0 +1,79 @@ +/* +Copyright 2017 (c) 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. + - 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. + - Use of the software either in source or binary form, must be run + on or directly connected to an Analog Devices Inc. component. + +THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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. + * + *****************************************************************************/ + +/*! + ****************************************************************************** + * @file: + * @brief: + *----------------------------------------------------------------------------- + */ +#include "adi_sense_config_types.h" + +ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config = { + .versionId = { .major = 1, .minor = 4 }, + .productId = ADI_SENSE_PRODUCT_ID_1000, + .adisense1000 = { + .power = { + .powerMode = ADI_SENSE_1000_POWER_MODE_FULL, + }, + .measurement = { + .operatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS, + .dataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE, + }, + .channels = { + [ADI_SENSE_1000_CHANNEL_ID_SENSOR_2] = { + .enableChannel = true, + .disablePublishing = false, + .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE, + .measurementsPerCycle = 1, + .extraSettlingTime = 20000, + .adcChannelConfig = { + .sensor = ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2, + .gain = ADI_SENSE_1000_ADC_GAIN_1X, + .filter = { + .type = ADI_SENSE_1000_ADC_FILTER_FIR_25SPS, + }, + .reference = { + .type = ADI_SENSE_1000_ADC_REFERENCE_BRIDGE_EXCITATION, + .disableBuffer = false, + }, + .enableVbias = false, + }, + }, + }, + }, +}; +