Ted Grosch / Mbed 2 deprecated Nucleo_TOF_I2C

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OPT3101Crosstalk.h Source File

OPT3101Crosstalk.h

Go to the documentation of this file.
00001 /*!
00002 * \file OPT3101Crosstalk.h
00003 * \author  Karthik Rajagopal <krthik@ti.com>
00004 * \version 0.9.1
00005 *
00006 * \section COPYRIGHT
00007 * TEXAS INSTRUMENTS TEXT FILE LICENSE
00008 * Copyright (c) 2018 Texas Instruments Incorporated
00009 * All rights reserved not granted herein.
00010 * Limited License.
00011 * 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.
00012 * 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
00013 * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met:
00014 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form.
00015 * * any redistribution and use are licensed by TI for use only with TI Devices.
00016 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
00017 * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met:
00018 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices.
00019 * * 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.
00020 * 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.
00021 * DISCLAIMER.
00022 * 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.
00023 *
00024 * \section DESCRIPTION
00025 * This file contains the OPT3101::crosstalkC class declaration 
00026 */
00027 
00028 #ifndef OPT3101CROSSTALK_H_
00029 #define OPT3101CROSSTALK_H_
00030 
00031 #include <stdint.h>
00032 #include <cmath>
00033 
00034 //#include "definitions.h"
00035 
00036 #ifdef OPT3101_USE_STREAMLIB
00037 #include <fstream>
00038 #include <iostream>
00039 #include <istream>
00040 #include <string>
00041 #endif
00042 
00043 //#include <windows.h>
00044 
00045 
00046 namespace OPT3101 {
00047     /** \brief OPT3101::device declaration
00048     This is declared here to avoid cyclic reference of classes
00049     */
00050     class device;
00051 
00052     /*! \class OPT3101::crosstalkC
00053     \brief Class that holds crosstalk related registers and values.
00054 
00055     This is a class container that can hold crosstalk values.  OPT3101 device has different crosstalk phenomenon which needs to be calibrated and compensated<br>
00056     There are primarily 2 types of crosstalk phenomenon that need to be compensated or calibrated out to achieve good system performance. <br>
00057     -# Internal crosstalk
00058         -#  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>
00059         -#  This phenomenon is independent of TX channel or configuration since the TX channels are off.
00060     -# Illum crosstalk
00061         -#  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.
00062         -#  This phenomenon is highly dependent on TX channel and the current settings on each TX.
00063 
00064     OPT3101 device has internal registers to correct and compensate for different crosstalk phenomenon. This class acts as a temporary storage of crosstalk values measured.
00065     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.
00066     */
00067     class crosstalkC {
00068     public:
00069         int16_t I; ///< 16bit register setting for In phase component of the crosstalk 
00070         int16_t Q; ///< 16bit register setting for Quadrature phase component of the crosstalk 
00071         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
00072         bool illumXtalk; ///< flag to capture if the crosstalk values belong to internal crosstalk (false) or illum crosstalk (true)
00073         uint8_t illumScale; ///< Member that captures the snapshot of illumination current multiplier scale register  during crosstalk measurement for analysis 
00074         uint8_t illumDac; ///< Member that captures the snapshot of illumination current setting register  during crosstalk measurement for analysis 
00075         uint8_t illumDCdac; ///< Member that captures the snapshot of illumination DC current setting register  during crosstalk measurement for analysis 
00076         uint16_t tmain; ///< Member that captures the snapshot of temperature of main temp sensor during crosstalk measurement
00077         uint16_t tillum; ///< Member that captures the snapshot of temperature of external temp sensor during crosstalk measurement
00078         uint8_t shiftIllumPhase; ///< Member that captures the snapshot of shift illum phase during crosstalk measurement
00079         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
00080         /*!
00081         * \brief Constructor for class OPT3101::crosstalkC
00082         *  Constructor initializes the OPT3101::crosstalkC::illumXtalk parameter to a default false
00083         */
00084         crosstalkC();
00085         /*!
00086         * \brief calculates magnitude
00087         *  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.
00088         * \returns magnitude of crosstalk;
00089         */
00090         double magnitude();
00091         /*!
00092         * \brief reads the device 24 bit crosstalk registers
00093         *  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
00094         * \param[in] dev; The dev is pointer to class OPT3101::device . This is required to realize I2C transactions and register map
00095         * \returns Nothing;
00096         */
00097         void readCrosstalkRegisters(device *dev);
00098         /*!
00099         * \brief reads the temperature reading from main temp sensor
00100         *  This method reads the main temp sensor  register OPT3101Register::tmain and captures to  OPT3101::crosstalkC::tmain
00101         * \param[in] dev; The dev is pointer to class OPT3101::device . This is required to realize I2C transactions and register map
00102         * \returns Nothing;
00103         */
00104         void readTemperatureMain(device *dev);
00105         /*!
00106         * \brief reads the temperature reading from external temp sensor
00107         *  This method reads the main temp sensor  register OPT3101Register::tillum and captures to  OPT3101::crosstalkC::tillum
00108         * \param[in] dev; The dev is pointer to class OPT3101::device . This is required to realize I2C transactions and register map
00109         * \returns Nothing;
00110         */
00111         void readTemperatureIllum(device *dev);
00112 #ifdef OPT3101_USE_STDIOLIB     
00113         /*!
00114         * \brief store crosstalk values to file
00115         *  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
00116         * \param[in] fileName; Path and name of the file to capture the crosstalk values to
00117         * \returns Nothing;
00118         */
00119         void storeToFile(char *fileName);
00120         /*!
00121         * \brief load crosstalk values from file
00122         *  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
00123         * \param[in] fileName; Path and name of the file from where the crosstalk values are loaded
00124         * \returns Nothing;
00125         */
00126         void loadFromFile(char *fileName);
00127 #endif
00128         /*!
00129         * \brief reports members of the instance
00130         *  Print the members of the class instance on screen 
00131         * \returns Nothing;
00132         */
00133         void report();
00134         /*!
00135         * \brief prints the contents on screen
00136         *  Print the members of the class instance on screen
00137         * \returns Nothing;
00138         */
00139         void print();
00140         /*!
00141         * \brief prints a header
00142         *  Prints a csv header
00143         * \returns Nothing;
00144         */
00145         void printHeader();
00146 
00147 
00148 #ifdef OPT3101_USE_STREAMLIB
00149         /*!
00150         * \brief Operator overload to store class contents to a file 
00151         *  Casts all the class members for file storage
00152         * \param[out] os; os is data stream to serialize data
00153         * \param[in] data; data is pointer to the class to be serialzied and stored
00154         * \returns std::ostream; Serialized std::ostream to be written to a file 
00155         */
00156         friend std::ostream& operator<<(std::ostream& os, const crosstalkC *data);
00157         /*!
00158         * \brief Operator overload to load class contents to from a file
00159         *  Retreives all the class members from a stored file 
00160         * \param[in] is; is input stream from where the data is loaded
00161         * \param[out] data; data is pointer to the class to be restored
00162         * \returns std::istream; Serialized Input stream loaded from file 
00163         */
00164         friend std::istream& operator>>(std::istream& is,       crosstalkC *data);
00165 #endif
00166     };
00167 
00168 }
00169 
00170 #endif /* OPT3101CROSSTALK_H_ */
00171