ADISense1000 Version 2.1 code base

Fork of AdiSense1000_V21 by Sean Wilson

Files at this revision

API Documentation at this revision

Comitter:
RGurav
Date:
Tue Sep 18 16:46:40 2018 +0000
Parent:
32:262fc8aeb486
Commit message:
ADISense1000 Version 2.1 code base

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
sample_lut_data.c Show annotated file Show diff for this revision Revisions of this file
sensor2_bridge-6w-pressure_config.c Show annotated file Show diff for this revision Revisions of this file
diff -r 262fc8aeb486 -r 640b6bebda17 main.cpp
--- a/main.cpp	Tue Jul 24 11:49:57 2018 +0000
+++ b/main.cpp	Tue Sep 18 16:46:40 2018 +0000
@@ -62,10 +62,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,
@@ -143,6 +147,41 @@
         ADI_SENSE_LOG_ERROR("Failed to set device configuration");
         return res;
     }
+    
+    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)
     {
diff -r 262fc8aeb486 -r 640b6bebda17 sample_lut_data.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sample_lut_data.c	Tue Sep 18 16:46:40 2018 +0000
@@ -0,0 +1,202 @@
+/*
+ * File: sample_lut_data.c
+ * 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().
+ */
+
+#include "adi_sense_1000_lut_data.h"
+#include "adi_sense_1000_sensor_types.h"
+
+/*
+ * 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 loadcell_1 = 
+{
+    .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_3_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 loadcell_1_data = 
+{
+    .nElements = 10,
+    .lut = 
+    {
+        -3300.0f, /* x(min) || mV */
+        -0.7556152f,
+        -0.626709f,
+        -0.5058594f,
+        -0.3776855f,
+        -0.1120605f,
+        0.5334473f,
+        1.1896973f,
+        13.340413f,
+        +3300.0f, /* x(max) || mV */
+        -0.001f,    /* y(min) || kg */
+        0.0f,
+        0.1f,
+        0.2f,
+        0.3f,
+        0.5f,
+        1.0f,
+        1.5f,
+        10.0f,
+        +100.0f,    /* y(max) || kg */
+    },
+};
+
+ADI_SENSE_1000_LUT_DESCRIPTOR loadcell_2 = 
+{
+    .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 loadcell_2_data = 
+{
+    .nElements = 10,
+    .lut = 
+    {
+        -3300.0f, /* x(min) || mV */
+        0.2766113f,   
+        0.4162598f,
+        0.5400391f,
+        0.6694336f,
+        0.9326172f,
+        1.5837402f,
+        2.2387695f,
+        12.25284823f,
+        +3300.0f, /* x(max) || mV */
+        -0.001f,    /* y(min) || kg */
+        0.0f,
+        0.1f,
+        0.2f,
+        0.3f,
+        0.5f,
+        1.0f,
+        1.5f,
+        10.0f,
+        +100.0f,    /* y(max) || kg */
+    },
+};
+
+ADI_SENSE_1000_LUT_DESCRIPTOR loadcell_3 = 
+{
+    .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_1_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 loadcell_3_data = 
+{
+    .nElements = 10,
+    .lut = 
+    {
+        -3300.0f, /* x(min) || mV */
+        0.2521973f,
+        0.3740234f,
+        0.5178223f,
+        0.6574707f,
+        0.9311523f,
+        1.6118164f,
+        2.3029785f,
+        13.96175153f,
+        +3300.0f, /* x(max) || mV */
+        -0.001f,    /* y(min) || kg */
+        0.0f,
+        0.1f,
+        0.2f,
+        0.3f,
+        0.5f,
+        1.0f,
+        1.5f,
+        10.0f,
+        +100.0f,    /* y(max) || kg */
+    },
+};
+
+ADI_SENSE_1000_LUT_DESCRIPTOR loadcell_4 = 
+{
+    .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_4_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 loadcell_4_data = 
+{
+    .nElements = 10,
+    .lut = 
+    {
+        -3300.0f, /* x(min) || mV */
+        0.4609375f,
+        0.5895996f,
+        0.7226562f,
+        0.857666f,
+        1.1184082f,
+        1.7749023f,
+        2.432373f,
+        13.60091103f,
+        +3300.0f, /* x(max) || mV */
+        -0.001f,    /* y(min) || kg */
+        0.0f,
+        0.1f,
+        0.2f,
+        0.3f,
+        0.5f,
+        1.0f,
+        1.5f,
+        10.0f,
+        +100.0f,    /* y(max) || kg */
+    },
+};
+
+
+/*
+ * The following variables can be passed as parameters to
+ * adi_sense_1000_AssembleLutData()
+ */
+ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[] = 
+{
+    &loadcell_1,
+    &loadcell_2,
+    &loadcell_3,
+    &loadcell_4,
+    
+};
+
+ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[] = 
+{
+    
+    (ADI_SENSE_1000_LUT_TABLE_DATA *) &loadcell_1_data,
+    (ADI_SENSE_1000_LUT_TABLE_DATA *) &loadcell_2_data,
+    (ADI_SENSE_1000_LUT_TABLE_DATA *) &loadcell_3_data,
+    (ADI_SENSE_1000_LUT_TABLE_DATA *) &loadcell_4_data,
+    
+};
+
+unsigned sample_lut_num_tables =
+    (sizeof(sample_lut_desc_list) / sizeof(sample_lut_desc_list[0]));
+
diff -r 262fc8aeb486 -r 640b6bebda17 sensor2_bridge-6w-pressure_config.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensor2_bridge-6w-pressure_config.c	Tue Sep 18 16:46:40 2018 +0000
@@ -0,0 +1,130 @@
+
+/*!
+ ******************************************************************************
+ * @file: sensor2_bridge_6w_pressure_config
+ * @brief: Initilize the sensor configuration
+ *-----------------------------------------------------------------------------
+ */
+#include "adi_sense_config_types.h"
+
+ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config = 
+{
+    .versionId = { .major = 1, .minor = 4 },
+    .productId = ADI_SENSE_PRODUCT_ID_ADSNS1000,
+    .adisense1000 = 
+        {
+        .power = 
+        {
+            .powerMode = ADI_SENSE_1000_POWER_MODE_FULL,
+        },
+        .measurement = 
+        {
+            .operatingMode = ADI_SENSE_1000_OPERATING_MODE_CONTINUOUS,
+            .dataReadyMode = ADI_SENSE_1000_DATAREADY_PER_CYCLE,
+        },
+    
+    /*
+        Define the channels and operating mode
+    */
+        .channels = 
+        {
+            [ADI_SENSE_1000_CHANNEL_ID_SENSOR_3] = 
+            {
+                .enableChannel = true,
+                .disablePublishing = false,
+                .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE,
+                .measurementsPerCycle = 1,
+                .extraSettlingTime = 20000,
+                .adcChannelConfig = 
+                {
+                    .sensor = ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_1_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,
+                },
+            },
+            
+            [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,
+                },
+            },
+            
+            [ADI_SENSE_1000_CHANNEL_ID_SENSOR_1] = 
+            {
+                .enableChannel = true,
+                .disablePublishing = false,
+                .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE,
+                .measurementsPerCycle = 1,
+                .extraSettlingTime = 20000,
+                .adcChannelConfig = 
+                {
+                    .sensor = ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_3_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,
+                },
+            },
+            
+            [ADI_SENSE_1000_CHANNEL_ID_SENSOR_0] = 
+            {
+                .enableChannel = true,
+                .disablePublishing = false,
+                .compensationChannel = ADI_SENSE_1000_CHANNEL_ID_NONE,
+                .measurementsPerCycle = 1,
+                .extraSettlingTime = 20000,
+                .adcChannelConfig = 
+                {
+                    .sensor = ADI_SENSE_1000_ADC_SENSOR_BRIDGE_4WIRE_4_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,
+                },
+            },
+            
+        },
+    },
+};
+