![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Export to MBED Studio for DISCO Board
OPT3101Crosstalk.h@3:4e641a32e087, 2020-10-25 (annotated)
- Committer:
- tgrosch
- Date:
- Sun Oct 25 10:43:09 2020 +0000
- Revision:
- 3:4e641a32e087
- Parent:
- 0:62b846b3988a
New Version with OS5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tgrosch | 0:62b846b3988a | 1 | /*! |
tgrosch | 0:62b846b3988a | 2 | * \file OPT3101Crosstalk.h |
tgrosch | 0:62b846b3988a | 3 | * \author Karthik Rajagopal <krthik@ti.com> |
tgrosch | 0:62b846b3988a | 4 | * \version 0.9.1 |
tgrosch | 0:62b846b3988a | 5 | * |
tgrosch | 0:62b846b3988a | 6 | * \section COPYRIGHT |
tgrosch | 0:62b846b3988a | 7 | * TEXAS INSTRUMENTS TEXT FILE LICENSE |
tgrosch | 0:62b846b3988a | 8 | * Copyright (c) 2018 Texas Instruments Incorporated |
tgrosch | 0:62b846b3988a | 9 | * All rights reserved not granted herein. |
tgrosch | 0:62b846b3988a | 10 | * Limited License. |
tgrosch | 0:62b846b3988a | 11 | * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive license under copyrights and patents it now or hereafter owns or controls to make, have made, use, import, offer to sell and sell ("Utilize") this software subject to the terms herein. With respect to the foregoing patent license, such license is granted solely to the extent that any such patent is necessary to Utilize the software alone. The patent license shall not apply to any combinations which include this software, other than combinations with devices manufactured by or for TI ("TI Devices"). No hardware patent is licensed hereunder. |
tgrosch | 0:62b846b3988a | 12 | * Redistributions must preserve existing copyright notices and reproduce this license (including the above copyright notice and the disclaimer and (if applicable) source code license limitations below) in the documentation and/or other materials provided with the distribution |
tgrosch | 0:62b846b3988a | 13 | * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met: |
tgrosch | 0:62b846b3988a | 14 | * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form. |
tgrosch | 0:62b846b3988a | 15 | * * any redistribution and use are licensed by TI for use only with TI Devices. |
tgrosch | 0:62b846b3988a | 16 | * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code. |
tgrosch | 0:62b846b3988a | 17 | * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met: |
tgrosch | 0:62b846b3988a | 18 | * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices. |
tgrosch | 0:62b846b3988a | 19 | * * any redistribution and use of any object code compiled from the source code and any resulting derivative works, are licensed by TI for use only with TI Devices. |
tgrosch | 0:62b846b3988a | 20 | * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or promote products derived from this software without specific prior written permission. |
tgrosch | 0:62b846b3988a | 21 | * DISCLAIMER. |
tgrosch | 0:62b846b3988a | 22 | * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 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. |
tgrosch | 0:62b846b3988a | 23 | * |
tgrosch | 0:62b846b3988a | 24 | * \section DESCRIPTION |
tgrosch | 0:62b846b3988a | 25 | * This file contains the OPT3101::crosstalkC class declaration |
tgrosch | 0:62b846b3988a | 26 | */ |
tgrosch | 0:62b846b3988a | 27 | |
tgrosch | 0:62b846b3988a | 28 | #ifndef OPT3101CROSSTALK_H_ |
tgrosch | 0:62b846b3988a | 29 | #define OPT3101CROSSTALK_H_ |
tgrosch | 0:62b846b3988a | 30 | |
tgrosch | 0:62b846b3988a | 31 | #include <stdint.h> |
tgrosch | 0:62b846b3988a | 32 | #include <cmath> |
tgrosch | 0:62b846b3988a | 33 | |
tgrosch | 0:62b846b3988a | 34 | //#include "definitions.h" |
tgrosch | 0:62b846b3988a | 35 | |
tgrosch | 0:62b846b3988a | 36 | #ifdef OPT3101_USE_STREAMLIB |
tgrosch | 0:62b846b3988a | 37 | #include <fstream> |
tgrosch | 0:62b846b3988a | 38 | #include <iostream> |
tgrosch | 0:62b846b3988a | 39 | #include <istream> |
tgrosch | 0:62b846b3988a | 40 | #include <string> |
tgrosch | 0:62b846b3988a | 41 | #endif |
tgrosch | 0:62b846b3988a | 42 | |
tgrosch | 0:62b846b3988a | 43 | //#include <windows.h> |
tgrosch | 0:62b846b3988a | 44 | |
tgrosch | 0:62b846b3988a | 45 | |
tgrosch | 0:62b846b3988a | 46 | namespace OPT3101 { |
tgrosch | 0:62b846b3988a | 47 | /** \brief OPT3101::device declaration |
tgrosch | 0:62b846b3988a | 48 | This is declared here to avoid cyclic reference of classes |
tgrosch | 0:62b846b3988a | 49 | */ |
tgrosch | 0:62b846b3988a | 50 | class device; |
tgrosch | 0:62b846b3988a | 51 | |
tgrosch | 0:62b846b3988a | 52 | /*! \class OPT3101::crosstalkC |
tgrosch | 0:62b846b3988a | 53 | \brief Class that holds crosstalk related registers and values. |
tgrosch | 0:62b846b3988a | 54 | |
tgrosch | 0:62b846b3988a | 55 | This is a class container that can hold crosstalk values. OPT3101 device has different crosstalk phenomenon which needs to be calibrated and compensated<br> |
tgrosch | 0:62b846b3988a | 56 | There are primarily 2 types of crosstalk phenomenon that need to be compensated or calibrated out to achieve good system performance. <br> |
tgrosch | 0:62b846b3988a | 57 | -# Internal crosstalk |
tgrosch | 0:62b846b3988a | 58 | -# This is defined as the amount of signal measured by AFE when there the TX channels are turned OFF. Internal crosstalk phenomenon occurs due to coupling from power supply and ground.<br> |
tgrosch | 0:62b846b3988a | 59 | -# This phenomenon is independent of TX channel or configuration since the TX channels are off. |
tgrosch | 0:62b846b3988a | 60 | -# Illum crosstalk |
tgrosch | 0:62b846b3988a | 61 | -# This is defined as the amount of signal measured by AFE when the TX channels are turned ON and the system is pointing to infinity or with photo diode covered. |
tgrosch | 0:62b846b3988a | 62 | -# This phenomenon is highly dependent on TX channel and the current settings on each TX. |
tgrosch | 0:62b846b3988a | 63 | |
tgrosch | 0:62b846b3988a | 64 | OPT3101 device has internal registers to correct and compensate for different crosstalk phenomenon. This class acts as a temporary storage of crosstalk values measured. |
tgrosch | 0:62b846b3988a | 65 | Calculations have to be made on the crosstalk values to transform them to register settings. Besides that other calibrationC coefficients like OPT3101::crosstalkTempCoffC will be calculated. |
tgrosch | 0:62b846b3988a | 66 | */ |
tgrosch | 0:62b846b3988a | 67 | class crosstalkC { |
tgrosch | 0:62b846b3988a | 68 | public: |
tgrosch | 0:62b846b3988a | 69 | int16_t I; ///< 16bit register setting for In phase component of the crosstalk |
tgrosch | 0:62b846b3988a | 70 | int16_t Q; ///< 16bit register setting for Quadrature phase component of the crosstalk |
tgrosch | 0:62b846b3988a | 71 | uint8_t xtalkScale; ///< Crosstalk registers in OPT3101 device are 24 bit where as compensation registers are 16 bit. The scale parameter captures the scaling of the 24bit register to fit in to 16 bits |
tgrosch | 0:62b846b3988a | 72 | bool illumXtalk; ///< flag to capture if the crosstalk values belong to internal crosstalk (false) or illum crosstalk (true) |
tgrosch | 0:62b846b3988a | 73 | uint8_t illumScale; ///< Member that captures the snapshot of illumination current multiplier scale register during crosstalk measurement for analysis |
tgrosch | 0:62b846b3988a | 74 | uint8_t illumDac; ///< Member that captures the snapshot of illumination current setting register during crosstalk measurement for analysis |
tgrosch | 0:62b846b3988a | 75 | uint8_t illumDCdac; ///< Member that captures the snapshot of illumination DC current setting register during crosstalk measurement for analysis |
tgrosch | 0:62b846b3988a | 76 | uint16_t tmain; ///< Member that captures the snapshot of temperature of main temp sensor during crosstalk measurement |
tgrosch | 0:62b846b3988a | 77 | uint16_t tillum; ///< Member that captures the snapshot of temperature of external temp sensor during crosstalk measurement |
tgrosch | 0:62b846b3988a | 78 | uint8_t shiftIllumPhase; ///< Member that captures the snapshot of shift illum phase during crosstalk measurement |
tgrosch | 0:62b846b3988a | 79 | uint8_t commonScale; ///< Member that captures the common scale to be applied to all the crosstalk values to be applied OPT3101 device during facotry calibrationC. This value is calculated as a common value based on a bunch of OPT3101::crosstalkC instances |
tgrosch | 0:62b846b3988a | 80 | /*! |
tgrosch | 0:62b846b3988a | 81 | * \brief Constructor for class OPT3101::crosstalkC |
tgrosch | 0:62b846b3988a | 82 | * Constructor initializes the OPT3101::crosstalkC::illumXtalk parameter to a default false |
tgrosch | 0:62b846b3988a | 83 | */ |
tgrosch | 0:62b846b3988a | 84 | crosstalkC(); |
tgrosch | 0:62b846b3988a | 85 | /*! |
tgrosch | 0:62b846b3988a | 86 | * \brief calculates magnitude |
tgrosch | 0:62b846b3988a | 87 | * This method calculates the magnitude of crosstalk represented in codes. Typical and good values for internal crosstalk is around 30. Typical and good values for illum crosstalk for highest current (170mA) < 300 codes. |
tgrosch | 0:62b846b3988a | 88 | * \returns magnitude of crosstalk; |
tgrosch | 0:62b846b3988a | 89 | */ |
tgrosch | 0:62b846b3988a | 90 | double magnitude(); |
tgrosch | 0:62b846b3988a | 91 | /*! |
tgrosch | 0:62b846b3988a | 92 | * \brief reads the device 24 bit crosstalk registers |
tgrosch | 0:62b846b3988a | 93 | * This method reads the 24 bit crosstalk registers OPT3101::registers::iphase_xtalk and OPT3101::registers::qphase_xtalk. Translates them to 16 bit values and captures to OPT3101::crosstalkC::I OPT3101::crosstalkC::Q and OPT3101::crosstalkC::xtalkScale |
tgrosch | 0:62b846b3988a | 94 | * \param[in] dev; The dev is pointer to class OPT3101::device . This is required to realize I2C transactions and register map |
tgrosch | 0:62b846b3988a | 95 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 96 | */ |
tgrosch | 0:62b846b3988a | 97 | void readCrosstalkRegisters(device *dev); |
tgrosch | 0:62b846b3988a | 98 | /*! |
tgrosch | 0:62b846b3988a | 99 | * \brief reads the temperature reading from main temp sensor |
tgrosch | 0:62b846b3988a | 100 | * This method reads the main temp sensor register OPT3101Register::tmain and captures to OPT3101::crosstalkC::tmain |
tgrosch | 0:62b846b3988a | 101 | * \param[in] dev; The dev is pointer to class OPT3101::device . This is required to realize I2C transactions and register map |
tgrosch | 0:62b846b3988a | 102 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 103 | */ |
tgrosch | 0:62b846b3988a | 104 | void readTemperatureMain(device *dev); |
tgrosch | 0:62b846b3988a | 105 | /*! |
tgrosch | 0:62b846b3988a | 106 | * \brief reads the temperature reading from external temp sensor |
tgrosch | 0:62b846b3988a | 107 | * This method reads the main temp sensor register OPT3101Register::tillum and captures to OPT3101::crosstalkC::tillum |
tgrosch | 0:62b846b3988a | 108 | * \param[in] dev; The dev is pointer to class OPT3101::device . This is required to realize I2C transactions and register map |
tgrosch | 0:62b846b3988a | 109 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 110 | */ |
tgrosch | 0:62b846b3988a | 111 | void readTemperatureIllum(device *dev); |
tgrosch | 0:62b846b3988a | 112 | #ifdef OPT3101_USE_STDIOLIB |
tgrosch | 0:62b846b3988a | 113 | /*! |
tgrosch | 0:62b846b3988a | 114 | * \brief store crosstalk values to file |
tgrosch | 0:62b846b3988a | 115 | * This methods stores the crosstalk values to a non-volatile memory. Storage to non-volatile memory is important to be able to calculate temperature coefficient OPT3101::crosstalkTempCoffC |
tgrosch | 0:62b846b3988a | 116 | * \param[in] fileName; Path and name of the file to capture the crosstalk values to |
tgrosch | 0:62b846b3988a | 117 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 118 | */ |
tgrosch | 0:62b846b3988a | 119 | void storeToFile(char *fileName); |
tgrosch | 0:62b846b3988a | 120 | /*! |
tgrosch | 0:62b846b3988a | 121 | * \brief load crosstalk values from file |
tgrosch | 0:62b846b3988a | 122 | * This methods loads the crosstalk values to a non-volatile memory. Storage/Restoration to/from non-volatile memory is important to be able to calculate temperature coefficient OPT3101::crosstalkTempCoffC |
tgrosch | 0:62b846b3988a | 123 | * \param[in] fileName; Path and name of the file from where the crosstalk values are loaded |
tgrosch | 0:62b846b3988a | 124 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 125 | */ |
tgrosch | 0:62b846b3988a | 126 | void loadFromFile(char *fileName); |
tgrosch | 0:62b846b3988a | 127 | #endif |
tgrosch | 0:62b846b3988a | 128 | /*! |
tgrosch | 0:62b846b3988a | 129 | * \brief reports members of the instance |
tgrosch | 0:62b846b3988a | 130 | * Print the members of the class instance on screen |
tgrosch | 0:62b846b3988a | 131 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 132 | */ |
tgrosch | 0:62b846b3988a | 133 | void report(); |
tgrosch | 0:62b846b3988a | 134 | /*! |
tgrosch | 0:62b846b3988a | 135 | * \brief prints the contents on screen |
tgrosch | 0:62b846b3988a | 136 | * Print the members of the class instance on screen |
tgrosch | 0:62b846b3988a | 137 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 138 | */ |
tgrosch | 0:62b846b3988a | 139 | void print(); |
tgrosch | 0:62b846b3988a | 140 | /*! |
tgrosch | 0:62b846b3988a | 141 | * \brief prints a header |
tgrosch | 0:62b846b3988a | 142 | * Prints a csv header |
tgrosch | 0:62b846b3988a | 143 | * \returns Nothing; |
tgrosch | 0:62b846b3988a | 144 | */ |
tgrosch | 0:62b846b3988a | 145 | void printHeader(); |
tgrosch | 0:62b846b3988a | 146 | |
tgrosch | 0:62b846b3988a | 147 | |
tgrosch | 0:62b846b3988a | 148 | #ifdef OPT3101_USE_STREAMLIB |
tgrosch | 0:62b846b3988a | 149 | /*! |
tgrosch | 0:62b846b3988a | 150 | * \brief Operator overload to store class contents to a file |
tgrosch | 0:62b846b3988a | 151 | * Casts all the class members for file storage |
tgrosch | 0:62b846b3988a | 152 | * \param[out] os; os is data stream to serialize data |
tgrosch | 0:62b846b3988a | 153 | * \param[in] data; data is pointer to the class to be serialzied and stored |
tgrosch | 0:62b846b3988a | 154 | * \returns std::ostream; Serialized std::ostream to be written to a file |
tgrosch | 0:62b846b3988a | 155 | */ |
tgrosch | 0:62b846b3988a | 156 | friend std::ostream& operator<<(std::ostream& os, const crosstalkC *data); |
tgrosch | 0:62b846b3988a | 157 | /*! |
tgrosch | 0:62b846b3988a | 158 | * \brief Operator overload to load class contents to from a file |
tgrosch | 0:62b846b3988a | 159 | * Retreives all the class members from a stored file |
tgrosch | 0:62b846b3988a | 160 | * \param[in] is; is input stream from where the data is loaded |
tgrosch | 0:62b846b3988a | 161 | * \param[out] data; data is pointer to the class to be restored |
tgrosch | 0:62b846b3988a | 162 | * \returns std::istream; Serialized Input stream loaded from file |
tgrosch | 0:62b846b3988a | 163 | */ |
tgrosch | 0:62b846b3988a | 164 | friend std::istream& operator>>(std::istream& is, crosstalkC *data); |
tgrosch | 0:62b846b3988a | 165 | #endif |
tgrosch | 0:62b846b3988a | 166 | }; |
tgrosch | 0:62b846b3988a | 167 | |
tgrosch | 0:62b846b3988a | 168 | } |
tgrosch | 0:62b846b3988a | 169 | |
tgrosch | 0:62b846b3988a | 170 | #endif /* OPT3101CROSSTALK_H_ */ |
tgrosch | 0:62b846b3988a | 171 |