Example program for EVAL-ADMX2001

Dependencies:   ADMX2001

Committer:
nsheth
Date:
Wed Oct 27 06:58:57 2021 +0000
Revision:
5:746e78113d7d
Child:
8:bd0b93e35392
Changes for measurement and calibration using different test loads

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nsheth 5:746e78113d7d 1 /* Copyright (c) 2021 Analog Devices, Inc. All rights reserved.
nsheth 5:746e78113d7d 2
nsheth 5:746e78113d7d 3 Redistribution and use in source and binary forms, with or without modification,
nsheth 5:746e78113d7d 4 are permitted provided that the following conditions are met:
nsheth 5:746e78113d7d 5 - Redistributions of source code must retain the above copyright notice,
nsheth 5:746e78113d7d 6 this list of conditions and the following disclaimer.
nsheth 5:746e78113d7d 7 - Redistributions in binary form must reproduce the above copyright notice,
nsheth 5:746e78113d7d 8 this list of conditions and the following disclaimer in the documentation
nsheth 5:746e78113d7d 9 and/or other materials provided with the distribution.
nsheth 5:746e78113d7d 10 - Modified versions of the software must be conspicuously marked as such.
nsheth 5:746e78113d7d 11 - This software is licensed solely and exclusively for use with processors/products
nsheth 5:746e78113d7d 12 manufactured by or for Analog Devices, Inc.
nsheth 5:746e78113d7d 13 - This software may not be combined or merged with other code in any manner
nsheth 5:746e78113d7d 14 that would cause the software to become subject to terms and conditions which
nsheth 5:746e78113d7d 15 differ from those listed here.
nsheth 5:746e78113d7d 16 - Neither the name of Analog Devices, Inc. nor the names of its contributors
nsheth 5:746e78113d7d 17 may be used to endorse or promote products derived from this software without
nsheth 5:746e78113d7d 18 specific prior written permission.
nsheth 5:746e78113d7d 19 - The use of this software may or may not infringe the patent rights of one or
nsheth 5:746e78113d7d 20 more patent holders. This license does not release you from the requirement
nsheth 5:746e78113d7d 21 that you obtain separate licenses from these patent holders to use this software.
nsheth 5:746e78113d7d 22
nsheth 5:746e78113d7d 23 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND
nsheth 5:746e78113d7d 24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
nsheth 5:746e78113d7d 25 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
nsheth 5:746e78113d7d 26 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
nsheth 5:746e78113d7d 27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
nsheth 5:746e78113d7d 28 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
nsheth 5:746e78113d7d 29 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
nsheth 5:746e78113d7d 30 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nsheth 5:746e78113d7d 31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
nsheth 5:746e78113d7d 32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
nsheth 5:746e78113d7d 33 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nsheth 5:746e78113d7d 34
nsheth 5:746e78113d7d 35 2021-01-10-7CBSD SLA
nsheth 5:746e78113d7d 36 */
nsheth 5:746e78113d7d 37
nsheth 5:746e78113d7d 38
nsheth 5:746e78113d7d 39 /**
nsheth 5:746e78113d7d 40 * @file: calibrate.h
nsheth 5:746e78113d7d 41 * @brief: This file contains type definitions and function prototype
nsheth 5:746e78113d7d 42 * for calibrate.c
nsheth 5:746e78113d7d 43 * @details: Provides function definitions for command actions
nsheth 5:746e78113d7d 44 * @defgroup CAL_AND_COMP Calibration and compensation routines
nsheth 5:746e78113d7d 45 */
nsheth 5:746e78113d7d 46
nsheth 5:746e78113d7d 47 #ifndef __CALIBRATE_H__
nsheth 5:746e78113d7d 48 #define __CALIBRATE_H__
nsheth 5:746e78113d7d 49
nsheth 5:746e78113d7d 50 /*============= I N C L U D E S =============*/
nsheth 5:746e78113d7d 51 #include <stdint.h>
nsheth 5:746e78113d7d 52
nsheth 5:746e78113d7d 53 /*============= D E F I N E S =============*/
nsheth 5:746e78113d7d 54 #define DEFAULT_CAL_COEFF_INDEX (0)
nsheth 5:746e78113d7d 55 /**< Default calibration coefficient index */
nsheth 5:746e78113d7d 56 #define DEFAULT_DC_COEFF_INDEX (0)
nsheth 5:746e78113d7d 57 /**< Default dc calibration coefficient index */
nsheth 5:746e78113d7d 58 #define DEFAULT_COMPN_COEFF_INDEX (0)
nsheth 5:746e78113d7d 59 /**< Default compensation coefficient index */
nsheth 5:746e78113d7d 60 #define NUM_CALIBRATION_SETS (16 + 1)
nsheth 5:746e78113d7d 61 /**< Max number of cal coefficient sets */
nsheth 5:746e78113d7d 62
nsheth 5:746e78113d7d 63 /** @brief password array size */
nsheth 5:746e78113d7d 64 #define MAX_PASSWORD_SIZE (12)
nsheth 5:746e78113d7d 65 /** @brief timestamp array size */
nsheth 5:746e78113d7d 66 #define TIMESTAMP_SIZE (128)
nsheth 5:746e78113d7d 67 /** @brief
nsheth 5:746e78113d7d 68 * Calibration states
nsheth 5:746e78113d7d 69 * */
nsheth 5:746e78113d7d 70
nsheth 5:746e78113d7d 71 /** No calibration done*/
nsheth 5:746e78113d7d 72 #define CAL_STAT_NO_CAL (0)
nsheth 5:746e78113d7d 73 /** calibration status is short - Rs, Xs, Gs, Bs*/
nsheth 5:746e78113d7d 74 #define CAL_STAT_SHORT (0xF << 0)
nsheth 5:746e78113d7d 75 /** calibration status is open - Ro, Xo, Go, Bo*/
nsheth 5:746e78113d7d 76 #define CAL_STAT_OPEN (0xF << 4)
nsheth 5:746e78113d7d 77 /** calibration status is Load, Rg, xG, Gg, Bg*/
nsheth 5:746e78113d7d 78 #define CAL_STAT_LOAD (0xF << 8)
nsheth 5:746e78113d7d 79 /** calibration status dirty */
nsheth 5:746e78113d7d 80 #define CAL_STAT_DIRTY (1 << 15)
nsheth 5:746e78113d7d 81 /** Success */
nsheth 5:746e78113d7d 82 #define CAL_STATUS_SUCCESS 0
nsheth 5:746e78113d7d 83 /** Operation Failed */
nsheth 5:746e78113d7d 84 #define CAL_STATUS_FAILURE 1
nsheth 5:746e78113d7d 85 /** Password incorrect in calibration commit*/
nsheth 5:746e78113d7d 86 #define CAL_STATUS_INVALID_PASSWORD 5
nsheth 5:746e78113d7d 87 /** CRC error while reading coeffs from flash */
nsheth 5:746e78113d7d 88 #define CAL_STATUS_CRC_ERROR 3
nsheth 5:746e78113d7d 89 /** Number of calibration modes */
nsheth 5:746e78113d7d 90 #define CAL_NUM_MODES 4
nsheth 5:746e78113d7d 91 /** Number of calibration coeffcients */
nsheth 5:746e78113d7d 92 #define CAL_NUM_COEFFS 12
nsheth 5:746e78113d7d 93 /** Number of dc calibration coeffcients */
nsheth 5:746e78113d7d 94 #define CAL_NUM_DC_COEFFS 2
nsheth 5:746e78113d7d 95
nsheth 5:746e78113d7d 96 /**
nsheth 5:746e78113d7d 97 * @brief enumeration for all calibration Modes
nsheth 5:746e78113d7d 98 *
nsheth 5:746e78113d7d 99 */
nsheth 5:746e78113d7d 100 typedef enum
nsheth 5:746e78113d7d 101 {
nsheth 5:746e78113d7d 102 CAL_MODE_NONE = 0, /**< No correction applied */
nsheth 5:746e78113d7d 103 CAL_MODE_CAL, /**< Correction applied using calibration coefficients */
nsheth 5:746e78113d7d 104 CAL_MODE_COMP, /**< Corrections are applied using both calibration and \
nsheth 5:746e78113d7d 105 compensation coeffcients */
nsheth 5:746e78113d7d 106 } CAL_MODE;
nsheth 5:746e78113d7d 107
nsheth 5:746e78113d7d 108 /**
nsheth 5:746e78113d7d 109 * @brief enumeration for all calibration coeffs
nsheth 5:746e78113d7d 110 *
nsheth 5:746e78113d7d 111 */
nsheth 5:746e78113d7d 112 typedef enum
nsheth 5:746e78113d7d 113 {
nsheth 5:746e78113d7d 114 CAL_TYPE_NO_CAL = 0, /**< No Calibration */
nsheth 5:746e78113d7d 115 CAL_TYPE_OPEN, /**< OPEN Calibration*/
nsheth 5:746e78113d7d 116 CAL_TYPE_SHORT, /**< SHORT Calibration */
nsheth 5:746e78113d7d 117 CAL_TYPE_LOAD, /**< LOAD Calibration */
nsheth 5:746e78113d7d 118 } CAL_TYPE;
nsheth 5:746e78113d7d 119
nsheth 5:746e78113d7d 120 /**
nsheth 5:746e78113d7d 121 * @brief enumeration for all calibration coefficients
nsheth 5:746e78113d7d 122 *
nsheth 5:746e78113d7d 123 */
nsheth 5:746e78113d7d 124 typedef enum
nsheth 5:746e78113d7d 125 {
nsheth 5:746e78113d7d 126 Ro = 0, /**< Open Resistance */
nsheth 5:746e78113d7d 127 Xo, /**< Open Reactance */
nsheth 5:746e78113d7d 128 Go, /**< Open Conductance */
nsheth 5:746e78113d7d 129 Bo, /**< Open Susceptance */
nsheth 5:746e78113d7d 130 Rs, /**< Short Resistance */
nsheth 5:746e78113d7d 131 Xs, /**< Short Reactance */
nsheth 5:746e78113d7d 132 Gs, /**< Short Conductance */
nsheth 5:746e78113d7d 133 Bs, /**< Short Susceptance */
nsheth 5:746e78113d7d 134 Rg, /**< Resistance gain calibration coefficient */
nsheth 5:746e78113d7d 135 Xg, /**< Reactance gain calibration coefficient */
nsheth 5:746e78113d7d 136 Gg, /**< Conductance gain calibration coefficient */
nsheth 5:746e78113d7d 137 Bg /**< Susceptance gain calibration coefficient */
nsheth 5:746e78113d7d 138 } CAL_COEFFICIENT;
nsheth 5:746e78113d7d 139
nsheth 5:746e78113d7d 140 /**
nsheth 5:746e78113d7d 141 * @brief enumeration for Dc calibration coefficients
nsheth 5:746e78113d7d 142 *
nsheth 5:746e78113d7d 143 */
nsheth 5:746e78113d7d 144 typedef enum
nsheth 5:746e78113d7d 145 {
nsheth 5:746e78113d7d 146 Rdg = 0, /**< gain coefficient */
nsheth 5:746e78113d7d 147 Rdo, /**< offset coefficient */
nsheth 5:746e78113d7d 148 } DC_CAL_COEFFICIENT;
nsheth 5:746e78113d7d 149
nsheth 5:746e78113d7d 150 /*============= D A T A T Y P E S =============*/
nsheth 5:746e78113d7d 151 /**
nsheth 5:746e78113d7d 152 *
nsheth 5:746e78113d7d 153 * @brief structure for all calibration coefficients
nsheth 5:746e78113d7d 154 *
nsheth 5:746e78113d7d 155 */
nsheth 5:746e78113d7d 156 typedef struct
nsheth 5:746e78113d7d 157 {
nsheth 5:746e78113d7d 158 uint32_t status; /**< status for Open/Load/Short */
nsheth 5:746e78113d7d 159 uint32_t voltageGain; /**< voltage gain for calibration */
nsheth 5:746e78113d7d 160 uint32_t currentGain; /**< current gain for calibration */
nsheth 5:746e78113d7d 161 float frequency; /**< input frequency */
nsheth 5:746e78113d7d 162 float temperature; /**< input temperature */
nsheth 5:746e78113d7d 163 double Rs; /**< Short Resistance */
nsheth 5:746e78113d7d 164 double Rdg; /**< gain coefficient */
nsheth 5:746e78113d7d 165 double Rdo; /**< offset coefficient */
nsheth 5:746e78113d7d 166 } DcCalibrationCoeffs;
nsheth 5:746e78113d7d 167
nsheth 5:746e78113d7d 168 /**
nsheth 5:746e78113d7d 169 *
nsheth 5:746e78113d7d 170 * @brief structure for all calibration coefficients
nsheth 5:746e78113d7d 171 *
nsheth 5:746e78113d7d 172 */
nsheth 5:746e78113d7d 173 typedef struct
nsheth 5:746e78113d7d 174 {
nsheth 5:746e78113d7d 175 uint32_t status; /**< status for Open/Load/Short */
nsheth 5:746e78113d7d 176 uint32_t voltageGain; /**< voltage gain for calibration */
nsheth 5:746e78113d7d 177 uint32_t currentGain; /**< current gain for calibration */
nsheth 5:746e78113d7d 178 float frequency; /**< input frequency */
nsheth 5:746e78113d7d 179 float temperature; /**< input temperature */
nsheth 5:746e78113d7d 180 double Ro; /**< Open Resistance */
nsheth 5:746e78113d7d 181 double Xo; /**< Open Reactance */
nsheth 5:746e78113d7d 182 double Go; /**< Open Conductance */
nsheth 5:746e78113d7d 183 double Bo; /**< Open Susceptance */
nsheth 5:746e78113d7d 184 double Rs; /**< Short Resistance */
nsheth 5:746e78113d7d 185 double Xs; /**< Short Reactance */
nsheth 5:746e78113d7d 186 double Gs; /**< Short Conductance */
nsheth 5:746e78113d7d 187 double Bs; /**< Short Susceptance */
nsheth 5:746e78113d7d 188 double Rg; /**< Resistance gain calibration coefficient */
nsheth 5:746e78113d7d 189 double Xg; /**< Reactance gain calibration coefficient */
nsheth 5:746e78113d7d 190 double Gg; /**< Conductance gain calibration coefficient */
nsheth 5:746e78113d7d 191 double Bg; /**< Susceptance gain calibration coefficient */
nsheth 5:746e78113d7d 192 } CalibrationCoeffs;
nsheth 5:746e78113d7d 193
nsheth 5:746e78113d7d 194 /**
nsheth 5:746e78113d7d 195 *
nsheth 5:746e78113d7d 196 * @brief structure for calibration data
nsheth 5:746e78113d7d 197 *
nsheth 5:746e78113d7d 198 */
nsheth 5:746e78113d7d 199 typedef struct
nsheth 5:746e78113d7d 200 {
nsheth 5:746e78113d7d 201 uint16_t crc;
nsheth 5:746e78113d7d 202 /**< crc value for this structure */
nsheth 5:746e78113d7d 203 uint16_t numSets;
nsheth 5:746e78113d7d 204 /**< number of sets filled +1 for \0 */
nsheth 5:746e78113d7d 205 uint16_t numDcSets;
nsheth 5:746e78113d7d 206 /**< number of Dc coeffs filled +1 for \0 */
nsheth 5:746e78113d7d 207 /**FIXME: better to keep seperate count??*/
nsheth 5:746e78113d7d 208 uint8_t timestamp[TIMESTAMP_SIZE + 1];
nsheth 5:746e78113d7d 209 /**< time stamp +1 for \0 */
nsheth 5:746e78113d7d 210 uint8_t password[MAX_PASSWORD_SIZE + 1];
nsheth 5:746e78113d7d 211 /**< commit password */
nsheth 5:746e78113d7d 212 CalibrationCoeffs coeffs[NUM_CALIBRATION_SETS];
nsheth 5:746e78113d7d 213 /**< array of calibration coefficients*/
nsheth 5:746e78113d7d 214 DcCalibrationCoeffs dcCoeffs[NUM_CALIBRATION_SETS];
nsheth 5:746e78113d7d 215 /**< array of DC calibration coefficients */
nsheth 5:746e78113d7d 216 } CalibrationData;
nsheth 5:746e78113d7d 217
nsheth 5:746e78113d7d 218 /*============= F U N C T I O N P R O T O T Y P E S =============*/
nsheth 5:746e78113d7d 219
nsheth 5:746e78113d7d 220
nsheth 5:746e78113d7d 221 /**
nsheth 5:746e78113d7d 222 * @details perform specified cal type calibration .
nsheth 5:746e78113d7d 223 * @param [in] calType - type of calibration
nsheth 5:746e78113d7d 224 * @param [in] stdR - load value for Rt/Load calibration
nsheth 5:746e78113d7d 225 * @param [in] stdX - load value for Xt/Load calibration
nsheth 5:746e78113d7d 226 * @return ADMX_LCR_STATUS_SUCCESS - Success
nsheth 5:746e78113d7d 227 *
nsheth 5:746e78113d7d 228 */
nsheth 5:746e78113d7d 229 int32_t Calibrate(CAL_TYPE calType, float stdR, float stdX);
nsheth 5:746e78113d7d 230
nsheth 5:746e78113d7d 231 #endif /* __CALIBRATE_H__ */