Nisarg Sheth / Mbed OS EVAL-ADMX2001

Dependencies:   ADMX2001

Committer:
nsheth
Date:
Wed Oct 27 06:58:57 2021 +0000
Revision:
5:746e78113d7d
Parent:
4:e7e194f58f65
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.
Kjansen45 0:a74ad5b8dc7b 2
Kjansen45 0:a74ad5b8dc7b 3 Redistribution and use in source and binary forms, with or without modification,
Kjansen45 0:a74ad5b8dc7b 4 are permitted provided that the following conditions are met:
Kjansen45 0:a74ad5b8dc7b 5 - Redistributions of source code must retain the above copyright notice,
Kjansen45 0:a74ad5b8dc7b 6 this list of conditions and the following disclaimer.
Kjansen45 0:a74ad5b8dc7b 7 - Redistributions in binary form must reproduce the above copyright notice,
Kjansen45 0:a74ad5b8dc7b 8 this list of conditions and the following disclaimer in the documentation
Kjansen45 0:a74ad5b8dc7b 9 and/or other materials provided with the distribution.
Kjansen45 0:a74ad5b8dc7b 10 - Modified versions of the software must be conspicuously marked as such.
Kjansen45 0:a74ad5b8dc7b 11 - This software is licensed solely and exclusively for use with processors/products
Kjansen45 0:a74ad5b8dc7b 12 manufactured by or for Analog Devices, Inc.
Kjansen45 0:a74ad5b8dc7b 13 - This software may not be combined or merged with other code in any manner
Kjansen45 0:a74ad5b8dc7b 14 that would cause the software to become subject to terms and conditions which
Kjansen45 0:a74ad5b8dc7b 15 differ from those listed here.
Kjansen45 0:a74ad5b8dc7b 16 - Neither the name of Analog Devices, Inc. nor the names of its contributors
Kjansen45 0:a74ad5b8dc7b 17 may be used to endorse or promote products derived from this software without
Kjansen45 0:a74ad5b8dc7b 18 specific prior written permission.
Kjansen45 0:a74ad5b8dc7b 19 - The use of this software may or may not infringe the patent rights of one or
Kjansen45 0:a74ad5b8dc7b 20 more patent holders. This license does not release you from the requirement
Kjansen45 0:a74ad5b8dc7b 21 that you obtain separate licenses from these patent holders to use this software.
Kjansen45 0:a74ad5b8dc7b 22
Kjansen45 0:a74ad5b8dc7b 23 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND
Kjansen45 0:a74ad5b8dc7b 24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
Kjansen45 0:a74ad5b8dc7b 25 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
Kjansen45 0:a74ad5b8dc7b 26 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Kjansen45 0:a74ad5b8dc7b 27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
Kjansen45 0:a74ad5b8dc7b 28 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
Kjansen45 0:a74ad5b8dc7b 29 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
Kjansen45 0:a74ad5b8dc7b 30 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Kjansen45 0:a74ad5b8dc7b 31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Kjansen45 0:a74ad5b8dc7b 32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
Kjansen45 0:a74ad5b8dc7b 33 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kjansen45 0:a74ad5b8dc7b 34
nsheth 5:746e78113d7d 35 2021-01-10-7CBSD SLA
nsheth 5:746e78113d7d 36 */
nsheth 3:7954489d9f8a 37
Kjansen45 0:a74ad5b8dc7b 38
nsheth 3:7954489d9f8a 39 /*============= I N C L U D E S =============*/
nsheth 4:e7e194f58f65 40 #include "ADMX2001.h"
nsheth 5:746e78113d7d 41 #include "ADMX2001_commands.h"
nsheth 3:7954489d9f8a 42 #include "platform_drivers.h"
nsheth 4:e7e194f58f65 43 #include "app_config.h"
nsheth 3:7954489d9f8a 44 #include "spi_extra.h"
nsheth 5:746e78113d7d 45 #include "message.h"
nsheth 5:746e78113d7d 46 #include "gpio_config.h"
nsheth 5:746e78113d7d 47 #include "measure.h"
nsheth 5:746e78113d7d 48 #include "calibrate.h"
nsheth 3:7954489d9f8a 49 #include <stdint.h>
nsheth 3:7954489d9f8a 50 #include <stdio.h>
nsheth 3:7954489d9f8a 51 #include <stdlib.h>
Kjansen45 0:a74ad5b8dc7b 52
nsheth 3:7954489d9f8a 53 /** This is kept global and non-static because as test codes require this*/
nsheth 3:7954489d9f8a 54 Admx200xDev admx200xDev;
nsheth 3:7954489d9f8a 55
nsheth 3:7954489d9f8a 56 static int32_t SPIInit(spi_desc **pSpiDesc);
Kjansen45 0:a74ad5b8dc7b 57
nsheth 3:7954489d9f8a 58 /**
nsheth 3:7954489d9f8a 59 * Function to initialize SPI
nsheth 3:7954489d9f8a 60 */
nsheth 3:7954489d9f8a 61 int32_t SPIInit(spi_desc **pSpiDesc)
nsheth 3:7954489d9f8a 62 {
nsheth 3:7954489d9f8a 63 int32_t status;
Kjansen45 0:a74ad5b8dc7b 64
nsheth 3:7954489d9f8a 65 // Init SPI extra parameters structure
nsheth 3:7954489d9f8a 66 mbed_spi_init_param spiInitExtraParams = {.spi_clk_pin = SPI_SCK,
nsheth 3:7954489d9f8a 67 .spi_miso_pin = SPI_MISO,
nsheth 3:7954489d9f8a 68 .spi_mosi_pin = SPI_MOSI};
nsheth 3:7954489d9f8a 69
nsheth 3:7954489d9f8a 70 spi_init_param spiInit = {
nsheth 3:7954489d9f8a 71 25000000, // Max SPI Speed
nsheth 3:7954489d9f8a 72 SPI_SS, // Chip Select pin
nsheth 3:7954489d9f8a 73 SPI_MODE_0,
nsheth 3:7954489d9f8a 74 &spiInitExtraParams, // SPI extra configurations
nsheth 3:7954489d9f8a 75 };
nsheth 3:7954489d9f8a 76
nsheth 3:7954489d9f8a 77 status = spi_init(pSpiDesc, &spiInit);
nsheth 3:7954489d9f8a 78
nsheth 3:7954489d9f8a 79 return status;
Kjansen45 0:a74ad5b8dc7b 80 }
Kjansen45 0:a74ad5b8dc7b 81
nsheth 5:746e78113d7d 82 /**
nsheth 5:746e78113d7d 83 * @brief Measures Impedance
nsheth 5:746e78113d7d 84 * \ref CmdZ
nsheth 5:746e78113d7d 85 */
nsheth 5:746e78113d7d 86 int32_t CmdZ()
nsheth 5:746e78113d7d 87 {
nsheth 5:746e78113d7d 88 int32_t status = ADMX_STATUS_SUCCESS;
nsheth 5:746e78113d7d 89
nsheth 5:746e78113d7d 90 status = TriggerAndMeasure();
nsheth 5:746e78113d7d 91
nsheth 5:746e78113d7d 92 PrintMeasureStatusMessage(status);
nsheth 5:746e78113d7d 93
nsheth 5:746e78113d7d 94 if (status != ADMX_STATUS_SUCCESS)
nsheth 5:746e78113d7d 95 {
nsheth 5:746e78113d7d 96 status = ADMX_STATUS_FAILED;
nsheth 5:746e78113d7d 97 }
nsheth 5:746e78113d7d 98
nsheth 5:746e78113d7d 99 return status;
nsheth 5:746e78113d7d 100 }
nsheth 5:746e78113d7d 101
Kjansen45 0:a74ad5b8dc7b 102 int main()
Kjansen45 0:a74ad5b8dc7b 103 {
nsheth 3:7954489d9f8a 104 int32_t status = 0;
nsheth 3:7954489d9f8a 105 static spi_desc spiDesc;
nsheth 5:746e78113d7d 106 float stdLoad = 51;
nsheth 5:746e78113d7d 107 float Xt = 0;
nsheth 5:746e78113d7d 108 CAL_TYPE calType;
nsheth 3:7954489d9f8a 109 spi_desc *pSpi = &spiDesc;
nsheth 3:7954489d9f8a 110 Admx200xDev *pADmx2001 = &admx200xDev;
nsheth 3:7954489d9f8a 111 status |= SPIInit(&pSpi);
nsheth 3:7954489d9f8a 112 status |= Admx200xInit(pADmx2001, pSpi);
nsheth 3:7954489d9f8a 113
nsheth 3:7954489d9f8a 114 mdelay(100);
nsheth 3:7954489d9f8a 115
nsheth 3:7954489d9f8a 116 /* Initialize the ADMX200x application */
nsheth 3:7954489d9f8a 117 if (status != 0)
nsheth 3:7954489d9f8a 118 {
nsheth 3:7954489d9f8a 119 printf("Error setting up ADMX200X \r\n\r\n");
Kjansen45 0:a74ad5b8dc7b 120 }
nsheth 3:7954489d9f8a 121 else
nsheth 3:7954489d9f8a 122 {
nsheth 5:746e78113d7d 123 printf("Setting test load to 1k ohms\r\n");
nsheth 5:746e78113d7d 124 EnableMuxLine(2);
nsheth 5:746e78113d7d 125 printf("Starting measurement commands\r\n");
nsheth 5:746e78113d7d 126 CmdZ();
nsheth 5:746e78113d7d 127 printf("Measurement completed\r\n");
nsheth 5:746e78113d7d 128 printf("Setting test load to short\r\n");
nsheth 5:746e78113d7d 129 EnableMuxLine(0);
nsheth 5:746e78113d7d 130 printf("Starting Calibration\r\n");
nsheth 5:746e78113d7d 131 calType = CAL_TYPE_OPEN;
nsheth 5:746e78113d7d 132 status = Calibrate(calType, stdLoad, Xt);
nsheth 5:746e78113d7d 133 printf("Calibration completed\r\n");
nsheth 3:7954489d9f8a 134 }
nsheth 3:7954489d9f8a 135
nsheth 3:7954489d9f8a 136 status = spi_remove(pSpi);
nsheth 3:7954489d9f8a 137
nsheth 3:7954489d9f8a 138 return status;
Kjansen45 0:a74ad5b8dc7b 139 }