Export to MBED Studio for DISCO Board

Dependencies:   mbed

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?

UserRevisionLine numberNew contents of line
tgrosch 0:62b846b3988a 1 /*!
tgrosch 0:62b846b3988a 2 * \file OPT3101device_Calibration.cpp
tgrosch 0:62b846b3988a 3 * \author Karthik Rajagopal <krthik@ti.com>
tgrosch 0:62b846b3988a 4 * \version 0.9
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 * The file contains methods definitions for top level calibration methods for OPT3101::device
tgrosch 0:62b846b3988a 26 */
tgrosch 0:62b846b3988a 27
tgrosch 0:62b846b3988a 28 #include "OPT3101device.h"
tgrosch 0:62b846b3988a 29
tgrosch 0:62b846b3988a 30 void OPT3101::device::calibrationSession_firstTimeBringUp() {
tgrosch 0:62b846b3988a 31 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 32 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 33 host.printf("INFO::Writing Initialization sequence I2C registers\r\n");
tgrosch 0:62b846b3988a 34 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 35 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 36 this->calibration->internalCrosstalk[0].printHeader(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 37 this->calibration->internalCrosstalk[0].print(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 38 host.printf("\r\n");
tgrosch 0:62b846b3988a 39 // The folowing step is to perfrom illum crosstalk measurements
tgrosch 0:62b846b3988a 40 this->measureIllumCrosstalkSet();
tgrosch 0:62b846b3988a 41 this->loadIllumCrosstalkSet();
tgrosch 0:62b846b3988a 42 this->measurePhaseOffsetSet();
tgrosch 0:62b846b3988a 43 this->loadPhaseOffsetSet();
tgrosch 0:62b846b3988a 44 host.printf("INFO::Completed First Time bring up\r\n");
tgrosch 0:62b846b3988a 45
tgrosch 0:62b846b3988a 46
tgrosch 0:62b846b3988a 47 }
tgrosch 0:62b846b3988a 48
tgrosch 0:62b846b3988a 49 void OPT3101::device::calibrationSession_perUnitFactoryCalibrationWriteRegisterDataToNonVolatileMemory(bool DEBUG_dry_run)
tgrosch 0:62b846b3988a 50 {
tgrosch 0:62b846b3988a 51 uint16_t c0;
tgrosch 0:62b846b3988a 52 uint8_t regStore[11], c1;
tgrosch 0:62b846b3988a 53 uint32_t data;
tgrosch 0:62b846b3988a 54 uint8_t datar;
tgrosch 0:62b846b3988a 55
tgrosch 0:62b846b3988a 56 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 57 if (!this->calibration->EEPROM_connected){///* Method returns without doing any operation when the device configuration flag OPT3101::device::EEPROM_connected is false. User needs to implement their own function if no EEPROM is present
tgrosch 0:62b846b3988a 58 host.printfSetColor(0b110);
tgrosch 0:62b846b3988a 59 host.printf("WARN::NO EEPROM connected to h/w.\r\n");
tgrosch 0:62b846b3988a 60 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 61 host.printf("INFO::Listing all registers to be written to host non-volatile memory\r\n");
tgrosch 0:62b846b3988a 62 host.printfSetColor(0b001);
tgrosch 0:62b846b3988a 63 host.printf("regAddr,regValues\r\n");
tgrosch 0:62b846b3988a 64 for(c0=0;c0<this->calibration->registerAddressListSize;c0++){
tgrosch 0:62b846b3988a 65 data=host.readI2C(this->calibration->registerAddressList[c0]);
tgrosch 0:62b846b3988a 66 host.printf(" 0x%02x,",this->calibration->registerAddressList[c0]);
tgrosch 0:62b846b3988a 67 host.printf(" 0x%06lx\r\n",data);
tgrosch 0:62b846b3988a 68 }
tgrosch 0:62b846b3988a 69 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 70 host.printf("INFO::User is expected to program these values to non-volatile memory in host\r\n");
tgrosch 0:62b846b3988a 71 return;
tgrosch 0:62b846b3988a 72 }
tgrosch 0:62b846b3988a 73 regStore[0] = this->reg.tsens_slave0.read();
tgrosch 0:62b846b3988a 74 regStore[1] = this->reg.i2c_en.read();
tgrosch 0:62b846b3988a 75 regStore[2] = this->reg.i2c_num_tran.read();
tgrosch 0:62b846b3988a 76 regStore[3] = this->reg.i2c_rw.read();
tgrosch 0:62b846b3988a 77 regStore[4] = this->reg.i2c_num_bytes_tran1.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily bufferd to local variables.
tgrosch 0:62b846b3988a 78 regStore[5] = this->reg.en_tx_switch.read();
tgrosch 0:62b846b3988a 79 regStore[6] = this->reg.sel_tx_ch.read();
tgrosch 0:62b846b3988a 80 regStore[7] = this->reg.frame_vd_trig.read();
tgrosch 0:62b846b3988a 81 regStore[8] = this->reg.en_processor_values.read();
tgrosch 0:62b846b3988a 82 regStore[9] = this->reg.en_sequencer.read();
tgrosch 0:62b846b3988a 83 regStore[10] = this->reg.en_adaptive_hdr.read();
tgrosch 0:62b846b3988a 84
tgrosch 0:62b846b3988a 85 this->reg.tsens_slave0 = 0x50;
tgrosch 0:62b846b3988a 86 this->reg.i2c_num_tran = 0;
tgrosch 0:62b846b3988a 87 this->reg.i2c_rw = 0;
tgrosch 0:62b846b3988a 88 this->reg.frame_vd_trig = 0;
tgrosch 0:62b846b3988a 89 this->reg.i2c_num_bytes_tran1 = 1; ///* OPT3101 device is configured to write desired data though the SDA_M/SCL_M lines to the connected external EEPROM
tgrosch 0:62b846b3988a 90 this->reg.en_tx_switch = 0;
tgrosch 0:62b846b3988a 91 this->reg.sel_tx_ch = 0;
tgrosch 0:62b846b3988a 92 this->reg.i2c_en = 1;
tgrosch 0:62b846b3988a 93 this->reg.en_processor_values = 0;
tgrosch 0:62b846b3988a 94 this->reg.en_sequencer = 0;
tgrosch 0:62b846b3988a 95 this->reg.en_adaptive_hdr = 0;
tgrosch 0:62b846b3988a 96 // This portions clears all the element in EEPROM to 0xFF
tgrosch 0:62b846b3988a 97 if(!DEBUG_dry_run) {
tgrosch 0:62b846b3988a 98 host.printf("INFO::Clearing EEPROM contents\r\n");
tgrosch 0:62b846b3988a 99 for (c0 = 0; c0 < 256; c0++)
tgrosch 0:62b846b3988a 100 this->writeDataToEEPROM((uint8_t) c0, 0xFF); ///* Erases the EEPROM with 0xFF data in all lcoations.
tgrosch 0:62b846b3988a 101 } else {
tgrosch 0:62b846b3988a 102 host.printf("INFO::Dry Run, Skipped Clear EEPROM contents\r\n");
tgrosch 0:62b846b3988a 103 }
tgrosch 0:62b846b3988a 104
tgrosch 0:62b846b3988a 105 for (c0 = 0; c0 < this->calibration->registerAddressListSize; c0++) {
tgrosch 0:62b846b3988a 106 if(!DEBUG_dry_run)
tgrosch 0:62b846b3988a 107 this->writeDataToEEPROM( (uint8_t) ((c0&0xFF)<<2), this->calibration->registerAddressList[c0]);
tgrosch 0:62b846b3988a 108 data = host.readI2C(this->calibration->registerAddressList[c0]); ///* Reads all the registers from the list OPT3101::calibrationC::registerAddressList from h/w and writes the address and data to the connected external EEPROM
tgrosch 0:62b846b3988a 109 host.printf("INFO::Writing reg:0x%02x ",this->calibration->registerAddressList[c0]);
tgrosch 0:62b846b3988a 110 host.printf("data:0x%06lx to EEPROM\r\n",data);
tgrosch 0:62b846b3988a 111 if(!DEBUG_dry_run) {
tgrosch 0:62b846b3988a 112 for (c1 = 0; c1<3; c1++){
tgrosch 0:62b846b3988a 113 this->writeDataToEEPROM((uint8_t) ((((uint8_t)(c0&0xFF))<<2)+c1+1), (uint8_t) ((data >> ((c1 << 3)) & 0xFF)));
tgrosch 0:62b846b3988a 114 }
tgrosch 0:62b846b3988a 115 }
tgrosch 0:62b846b3988a 116 }
tgrosch 0:62b846b3988a 117
tgrosch 0:62b846b3988a 118 this->reg.tsens_slave0 = regStore[0];
tgrosch 0:62b846b3988a 119 this->reg.i2c_num_tran = regStore[2];
tgrosch 0:62b846b3988a 120 this->reg.i2c_rw = regStore[3];
tgrosch 0:62b846b3988a 121 this->reg.i2c_num_bytes_tran1 = regStore[4]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
tgrosch 0:62b846b3988a 122 this->reg.en_tx_switch = regStore[5];
tgrosch 0:62b846b3988a 123 this->reg.sel_tx_ch = regStore[6];
tgrosch 0:62b846b3988a 124 this->reg.frame_vd_trig = regStore[6];
tgrosch 0:62b846b3988a 125 this->reg.i2c_en = regStore[1];
tgrosch 0:62b846b3988a 126 this->reg.en_processor_values = regStore[8];
tgrosch 0:62b846b3988a 127 this->reg.en_sequencer = regStore[9];
tgrosch 0:62b846b3988a 128 this->reg.en_adaptive_hdr = regStore[10];
tgrosch 0:62b846b3988a 129 }
tgrosch 0:62b846b3988a 130
tgrosch 0:62b846b3988a 131 void OPT3101::device::readAndPrintEEPROMContents(bool rawFormat)
tgrosch 0:62b846b3988a 132 {
tgrosch 0:62b846b3988a 133 /* This section will be updated in the next revision of the SDK
tgrosch 0:62b846b3988a 134 * uint8_t c1;
tgrosch 0:62b846b3988a 135 uint16_t c0;
tgrosch 0:62b846b3988a 136 uint8_t regStore[8],data[4];
tgrosch 0:62b846b3988a 137 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 138 if (!this->calibration->EEPROM_connected) ///* Method returns without doing any operation when the device configuration flag OPT3101::device::EEPROM_connected is false. User needs to implement their own function if no EEPROM is present
tgrosch 0:62b846b3988a 139 return;
tgrosch 0:62b846b3988a 140 regStore[0] = this->reg.tsens_slave0.read();
tgrosch 0:62b846b3988a 141 regStore[1] = this->reg.i2c_en.read();
tgrosch 0:62b846b3988a 142 regStore[2] = this->reg.i2c_num_tran.read();
tgrosch 0:62b846b3988a 143 regStore[3] = this->reg.i2c_rw.read();
tgrosch 0:62b846b3988a 144 regStore[4] = this->reg.i2c_num_bytes_tran1.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily bufferd to local variables.
tgrosch 0:62b846b3988a 145 regStore[5] = this->reg.en_tx_switch.read();
tgrosch 0:62b846b3988a 146 regStore[6] = this->reg.sel_tx_ch.read();
tgrosch 0:62b846b3988a 147 regStore[7] = this->reg.frame_vd_trig.read();
tgrosch 0:62b846b3988a 148
tgrosch 0:62b846b3988a 149 this->reg.tsens_slave0 = 0x50;
tgrosch 0:62b846b3988a 150 this->reg.i2c_num_tran = 0;
tgrosch 0:62b846b3988a 151 this->reg.i2c_rw = 1;
tgrosch 0:62b846b3988a 152 this->reg.i2c_num_bytes_tran1 = 0; ///* OPT3101 device is configured to read desired data though the SDA_M/SCL_M lines to the connected external EEPROM
tgrosch 0:62b846b3988a 153 this->reg.en_tx_switch = 0;
tgrosch 0:62b846b3988a 154 this->reg.frame_vd_trig = 0;
tgrosch 0:62b846b3988a 155 this->reg.sel_tx_ch = 0;
tgrosch 0:62b846b3988a 156 this->reg.i2c_en = 1;
tgrosch 0:62b846b3988a 157
tgrosch 0:62b846b3988a 158 // This portions reads the data from the EERPOM and displays the same
tgrosch 0:62b846b3988a 159 for (c0 = 0; c0 < 256; c0++){
tgrosch 0:62b846b3988a 160 host.printf("S:0x%02x,",c0);
tgrosch 0:62b846b3988a 161 host.printf("0x%02x\r\n",this->readDataFromEEPROM((uint8_t) c0)); ///* Erases the EEPROM with 0xFF data in all lcoations.
tgrosch 0:62b846b3988a 162 }
tgrosch 0:62b846b3988a 163
tgrosch 0:62b846b3988a 164 for (c0 = 0; c0 < 64; c0++) {
tgrosch 0:62b846b3988a 165 for(c1=0;c1<4;c1++){
tgrosch 0:62b846b3988a 166 data[c1] = this->readDataFromEEPROM((c0<<2)+c1); ///* Reads the data from EEPROM For all locations.
tgrosch 0:62b846b3988a 167 if(rawFormat)
tgrosch 0:62b846b3988a 168 host.printf("INFO::Loc:0x%02x Data:0x%02x\r\n",(c0<<2)+c1,data[c1]);
tgrosch 0:62b846b3988a 169 }
tgrosch 0:62b846b3988a 170 if(!rawFormat){
tgrosch 0:62b846b3988a 171 host.printf("INFO:: regAddr:0x%02x regData:0x",data[0]);
tgrosch 0:62b846b3988a 172 for(c1=1;c1<4;c1++)
tgrosch 0:62b846b3988a 173 host.printf("%02x",data[c1]);
tgrosch 0:62b846b3988a 174 host.printf("\r\n");
tgrosch 0:62b846b3988a 175 }
tgrosch 0:62b846b3988a 176 }
tgrosch 0:62b846b3988a 177
tgrosch 0:62b846b3988a 178 this->reg.tsens_slave0 = regStore[0];
tgrosch 0:62b846b3988a 179 this->reg.i2c_en = regStore[1];
tgrosch 0:62b846b3988a 180 this->reg.i2c_num_tran = regStore[2];
tgrosch 0:62b846b3988a 181 this->reg.i2c_rw = regStore[3];
tgrosch 0:62b846b3988a 182 this->reg.i2c_num_bytes_tran1 = regStore[4]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
tgrosch 0:62b846b3988a 183 this->reg.en_tx_switch = regStore[5];
tgrosch 0:62b846b3988a 184 this->reg.sel_tx_ch = regStore[6];
tgrosch 0:62b846b3988a 185 this->reg.frame_vd_trig = regStore[6];
tgrosch 0:62b846b3988a 186 */
tgrosch 0:62b846b3988a 187
tgrosch 0:62b846b3988a 188 }
tgrosch 0:62b846b3988a 189
tgrosch 0:62b846b3988a 190 void OPT3101::device::calibrationSession_perDesignTx2IllumXtalkCorrection() {
tgrosch 0:62b846b3988a 191 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 192 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 193 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 194 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 195 ///* Ensure all calibrations are zeroed.
tgrosch 0:62b846b3988a 196 this->reg.use_xtalk_reg_illum = 0;
tgrosch 0:62b846b3988a 197 this->reg.en_temp_xtalk_corr = 0;
tgrosch 0:62b846b3988a 198 this->reg.en_temp_corr = 0;
tgrosch 0:62b846b3988a 199 this->reg.en_phase_corr = 0;
tgrosch 0:62b846b3988a 200 this->reg.amb_phase_corr_pwl_coeff0 = 0;
tgrosch 0:62b846b3988a 201 this->reg.amb_phase_corr_pwl_coeff1 = 0;
tgrosch 0:62b846b3988a 202 this->reg.amb_phase_corr_pwl_coeff2 = 0;
tgrosch 0:62b846b3988a 203 this->reg.amb_phase_corr_pwl_coeff3 = 0;
tgrosch 0:62b846b3988a 204 OPT3101::crosstalkC illumXtalk; ///* Declares temporary variable of OPT3101::crosstalkC class to hold internal crosstalk data across temperature, TX channel and register settings
tgrosch 0:62b846b3988a 205 ///* print header for data table
tgrosch 0:62b846b3988a 206 host.printf(" I,rS,rI,rD");
tgrosch 0:62b846b3988a 207 illumXtalk.printHeader();
tgrosch 0:62b846b3988a 208 ///* print baseline original xtalk
tgrosch 0:62b846b3988a 209 host.printf("-%02d,%02d,%02d,%02d,",0,-1,-1,-1);
tgrosch 0:62b846b3988a 210 this->measureIllumCrosstalk(&illumXtalk, 2, 1 ? 'h' : 'l'); ///* Calls method OPT3101::device::measureIllumCrosstalk with temporary variable of OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 211 illumXtalk.print(); ///* Calls OPT3101::crosstalkC::report method to report the crosstalk on screen
tgrosch 0:62b846b3988a 212 ///* enable current on tx2
tgrosch 0:62b846b3988a 213 this->reg.EN_CTALK_FB_CLK=1;
tgrosch 0:62b846b3988a 214 this->reg.EN_CALIB_CLK=1;
tgrosch 0:62b846b3988a 215 this->reg.calib_curr1_en_I=1;
tgrosch 0:62b846b3988a 216 ///* loop through all currents and print rest of the data as shown below
tgrosch 0:62b846b3988a 217 for(uint8_t scale = 0; scale < 4; scale++) {
tgrosch 0:62b846b3988a 218 for(uint8_t current = 0; current < 16; current++) {
tgrosch 0:62b846b3988a 219 for(uint8_t direction = 0; direction < 2; direction++) {
tgrosch 0:62b846b3988a 220 ///* set current on tx2
tgrosch 0:62b846b3988a 221 this->reg.calib_curr1_gain_sel=scale; //2 bits
tgrosch 0:62b846b3988a 222 this->reg.calib_curr1_DAC_I=current; //4 bits
tgrosch 0:62b846b3988a 223 this->reg.calib_curr1_inv_CLK_I=direction; //1 bit
tgrosch 0:62b846b3988a 224 ///* print current
tgrosch 0:62b846b3988a 225 if(direction==0)
tgrosch 0:62b846b3988a 226 host.printf("-%02d,%02d,%02d,%02d,",current*(scale+1),scale,current,direction);
tgrosch 0:62b846b3988a 227 else
tgrosch 0:62b846b3988a 228 host.printf("+%02d,%02d,%02d,%02d,",current*(scale+1),scale,current,direction);
tgrosch 0:62b846b3988a 229 // tx2,hdr1
tgrosch 0:62b846b3988a 230 this->measureIllumCrosstalk(&illumXtalk, 2, 1 ? 'h' : 'l'); ///* Calls method OPT3101::device::measureIllumCrosstalk with temporary variable of OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 231 illumXtalk.print(); ///* Calls OPT3101::crosstalkC::report method to report the crosstalk on screen
tgrosch 0:62b846b3988a 232 }
tgrosch 0:62b846b3988a 233 }
tgrosch 0:62b846b3988a 234 }
tgrosch 0:62b846b3988a 235 }
tgrosch 0:62b846b3988a 236
tgrosch 0:62b846b3988a 237 void OPT3101::device::calibrationSession_perDesignCalibrationCrosstalkTemp() {
tgrosch 0:62b846b3988a 238 uint8_t c0, c1;
tgrosch 0:62b846b3988a 239 uint16_t count;
tgrosch 0:62b846b3988a 240 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 241 OPT3101::crosstalkC illumXtalk; ///* Declares temporary variable of OPT3101::crosstalkC class to hold internal crosstalk data across temperature, TX channel and register settings
tgrosch 0:62b846b3988a 242 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 243 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 244 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 245 envController.setTargetToInfinity_OR_coverPhotodiode(); ///* Calls the method environmentalController::setTargetToInfinity_OR_coverPhotodiode , which is expected to set the environment so as to be able to measure illumination crosstalk
tgrosch 0:62b846b3988a 246 envController.setChamberTemperature(70); ///* Calls the method environmentalController::setChamberTemperature , which is expected to set the chamber to desired temperature
tgrosch 0:62b846b3988a 247
tgrosch 0:62b846b3988a 248 host.printf("Count,TX ,HDR,");
tgrosch 0:62b846b3988a 249 illumXtalk.printHeader();
tgrosch 0:62b846b3988a 250 for (count = 0; count<TEMP_CYCLE_TOTAL_NUMBER_OF_DATA_POINTS_PER_SETTING; count++) { ///* Loops through total number of points to be data printed
tgrosch 0:62b846b3988a 251 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 252 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 253 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 254 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 255 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 256 this->measureIllumCrosstalk(&illumXtalk, c0, c1 ? 'h' : 'l'); ///* Calls method OPT3101::device::measureIllumCrosstalk with temporary variable of OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 257 host.printf("%05d, %d, %d,",count,c0,c1);
tgrosch 0:62b846b3988a 258 illumXtalk.print(); ///* Calls OPT3101::crosstalkC::report method to report the crosstalk on screen
tgrosch 0:62b846b3988a 259 }
tgrosch 0:62b846b3988a 260 }
tgrosch 0:62b846b3988a 261 }
tgrosch 0:62b846b3988a 262 }
tgrosch 0:62b846b3988a 263 host.sleep(TEMP_CYCLE_DELAY_IN_SECONDS_BETWEEN_DATA_POINTS<<10);
tgrosch 0:62b846b3988a 264 }
tgrosch 0:62b846b3988a 265 }
tgrosch 0:62b846b3988a 266
tgrosch 0:62b846b3988a 267 void OPT3101::device::calibrationSession_perDesignCalibrationPhaseTemp() {
tgrosch 0:62b846b3988a 268 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 269 uint8_t c0, c1;
tgrosch 0:62b846b3988a 270 OPT3101::frameData data;
tgrosch 0:62b846b3988a 271 uint16_t count;
tgrosch 0:62b846b3988a 272 uint16_t refDistanceInCodes;
tgrosch 0:62b846b3988a 273 OPT3101::phaseOffsetC phaseOffset; ///* Declares temporary variable of OPT3101::phaseOffsetC class to hold phase offset data across temperature, TX channel and register settings
tgrosch 0:62b846b3988a 274 uint32_t refDistanceInMM;
tgrosch 0:62b846b3988a 275 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 276 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 277 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 278 this->loadIllumCrosstalkSet(true);
tgrosch 0:62b846b3988a 279
tgrosch 0:62b846b3988a 280 this->manuallySetIllumCrosstalkTempCoffs();
tgrosch 0:62b846b3988a 281 this->loadIllumCrosstalkTempCoffSet();
tgrosch 0:62b846b3988a 282
tgrosch 0:62b846b3988a 283 envController.manuallySetReferenceDistances();
tgrosch 0:62b846b3988a 284
tgrosch 0:62b846b3988a 285
tgrosch 0:62b846b3988a 286 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 287 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 288 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 289 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 290 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 291 refDistanceInMM = envController.refDistancesInMM[c0][c1]; ///* <b>Warning</b> User is expected to select and set reference distance so that the amplitude of the system for this particular TX and register set configurations measures between 16K and 24K. Default is set to 0 in the SDK
tgrosch 0:62b846b3988a 292 envController.setTargetDistance(refDistanceInMM); ///* Calls environmentalController::setTargetDistance method with the specified distance
tgrosch 0:62b846b3988a 293 envController.setChamberTemperature(70); ///* Calls the method environmentalController::setChamberTemperature , which is expected to set the chamber to desired temperature
tgrosch 0:62b846b3988a 294 refDistanceInCodes = (refDistanceInMM * 4477) >> 10; ///* Converts the reference distance specified in codes related to OPT3101::frameData::phase ADC codes
tgrosch 0:62b846b3988a 295 host.printf("DataCt,TX,HDR,");
tgrosch 0:62b846b3988a 296 phaseOffset.data.printHeader();
tgrosch 0:62b846b3988a 297 for (count = 0; count < TEMP_CYCLE_TOTAL_NUMBER_OF_DATA_POINTS_PER_SETTING; count++) { ///* Loops through chamber temperature settings to get temp coff
tgrosch 0:62b846b3988a 298 host.printf("%06d, %d, %d,",count,c0,c1);
tgrosch 0:62b846b3988a 299 this->measurePhaseOffset(&phaseOffset, c0, c1 ? 'h' : 'l', refDistanceInCodes, 0);
tgrosch 0:62b846b3988a 300 phaseOffset.data.print();
tgrosch 0:62b846b3988a 301 host.sleep(TEMP_CYCLE_DELAY_IN_SECONDS_BETWEEN_DATA_POINTS<<10);
tgrosch 0:62b846b3988a 302 }
tgrosch 0:62b846b3988a 303 }
tgrosch 0:62b846b3988a 304 }
tgrosch 0:62b846b3988a 305 }
tgrosch 0:62b846b3988a 306 }
tgrosch 0:62b846b3988a 307 }
tgrosch 0:62b846b3988a 308
tgrosch 0:62b846b3988a 309 void OPT3101::device::calibrationSession_perDesignCalibrationPhaseAmbient() {
tgrosch 0:62b846b3988a 310 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 311 uint8_t c0, c1;
tgrosch 0:62b846b3988a 312 OPT3101::frameData data;
tgrosch 0:62b846b3988a 313 uint16_t count;
tgrosch 0:62b846b3988a 314 uint16_t refDistanceInCodes;
tgrosch 0:62b846b3988a 315 OPT3101::phaseOffsetC phaseOffset; ///* Declares temporary variable of OPT3101::phaseOffsetC class to hold phase offset data across temperature, TX channel and register settings
tgrosch 0:62b846b3988a 316 uint32_t refDistanceInMM;
tgrosch 0:62b846b3988a 317 bool breakFlag;
tgrosch 0:62b846b3988a 318
tgrosch 0:62b846b3988a 319 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 320
tgrosch 0:62b846b3988a 321 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 322 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 323 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 324 this->manuallySetIllumCrosstalkTempCoffs();
tgrosch 0:62b846b3988a 325 this->manuallySetPhaseTempCoffs();
tgrosch 0:62b846b3988a 326
tgrosch 0:62b846b3988a 327 this->loadIllumCrosstalkSet(true);
tgrosch 0:62b846b3988a 328 this->loadIllumCrosstalkTempCoffSet();
tgrosch 0:62b846b3988a 329
tgrosch 0:62b846b3988a 330 this->loadPhaseOffsetSet(true);
tgrosch 0:62b846b3988a 331 this->loadPhaseOffsetTempCoffSet();
tgrosch 0:62b846b3988a 332 envController.manuallySetReferenceDistances();
tgrosch 0:62b846b3988a 333
tgrosch 0:62b846b3988a 334 breakFlag = false;
tgrosch 0:62b846b3988a 335 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 336 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 337 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 338 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 339 c1 = 0;
tgrosch 0:62b846b3988a 340 c0 = 1;
tgrosch 0:62b846b3988a 341 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 342 refDistanceInMM = envController.refDistancesInMM[c0][c1]; ///* <b>Warning</b> User is expected to select and set reference distance so that the amplitude of the system for this particular TX and register set configurations measures between 16K and 24K. Default is set to 0 in the SDK
tgrosch 0:62b846b3988a 343 envController.setTargetDistance(refDistanceInMM); ///* Calls environmentalController::setTargetDistance method with the specified distance
tgrosch 0:62b846b3988a 344 envController.setAmbientLight(0); ///* Calls the method environmentalController::setChamberTemperature , which is expected to set the chamber to desired temperature
tgrosch 0:62b846b3988a 345 refDistanceInCodes = (refDistanceInMM * 4477) >> 10; ///* Converts the reference distance specified in codes related to OPT3101::frameData::phase ADC codes
tgrosch 0:62b846b3988a 346 host.printf("DataCt,TX,HDR,");
tgrosch 0:62b846b3988a 347 phaseOffset.data.printHeader();
tgrosch 0:62b846b3988a 348 for (count = 0; count < TEMP_CYCLE_TOTAL_NUMBER_OF_DATA_POINTS_PER_SETTING; count++) { ///* Loops through chamber temperature settings to get temp coff
tgrosch 0:62b846b3988a 349 host.printf("%06d, %d, %d,",count,c0,c1);
tgrosch 0:62b846b3988a 350 this->measurePhaseOffset(&phaseOffset, c0, c1 ? 'h' : 'l', refDistanceInCodes, 0);
tgrosch 0:62b846b3988a 351 phaseOffset.data.print();
tgrosch 0:62b846b3988a 352 host.sleep(TEMP_CYCLE_DELAY_IN_SECONDS_BETWEEN_DATA_POINTS<<10);
tgrosch 0:62b846b3988a 353 }
tgrosch 0:62b846b3988a 354 breakFlag = true; ///* Since Phase ambient coff is required to be done only for one TX configuration the the method breaks from the loop after 1 ambient sweep
tgrosch 0:62b846b3988a 355 break; // This is required only for one TX and 1 of the registers since this is property of photo diode.
tgrosch 0:62b846b3988a 356 // Measure and populate Ambient Coefficients
tgrosch 0:62b846b3988a 357 }
tgrosch 0:62b846b3988a 358 if (breakFlag)
tgrosch 0:62b846b3988a 359 break;
tgrosch 0:62b846b3988a 360 }
tgrosch 0:62b846b3988a 361 if (breakFlag)
tgrosch 0:62b846b3988a 362 break;
tgrosch 0:62b846b3988a 363 }
tgrosch 0:62b846b3988a 364 if (breakFlag)
tgrosch 0:62b846b3988a 365 break;
tgrosch 0:62b846b3988a 366 }
tgrosch 0:62b846b3988a 367 }
tgrosch 0:62b846b3988a 368
tgrosch 0:62b846b3988a 369 void OPT3101::device::calibrationSession_perUnitFactoryCalibration()
tgrosch 0:62b846b3988a 370 {
tgrosch 0:62b846b3988a 371
tgrosch 0:62b846b3988a 372 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 373
tgrosch 0:62b846b3988a 374 host.printf("INFO::Writing Initialization sequence I2C registers\r\n");
tgrosch 0:62b846b3988a 375 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 376 host.printf("INFO::Device Initialization Completed\r\n");
tgrosch 0:62b846b3988a 377 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 378 this->calibration->internalCrosstalk[0].report(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 379
tgrosch 0:62b846b3988a 380 this->manuallySetIllumCrosstalkTempCoffs();
tgrosch 0:62b846b3988a 381 this->manuallySetPhaseTempCoffs();
tgrosch 0:62b846b3988a 382 this->manuallySetPhaseAmbientCoffs();
tgrosch 0:62b846b3988a 383
tgrosch 0:62b846b3988a 384 this->measureIllumCrosstalkSet(false);
tgrosch 0:62b846b3988a 385 this->loadIllumCrosstalkSet(false); ///* Calls the OPT3101::device::loadIllumCrosstalkSet with false argument so that method to load all illum crosstalk settings from the OPT3101::device::crosstalk::illumCrosstalk member
tgrosch 0:62b846b3988a 386 this->loadIllumCrosstalkTempCoffSet();
tgrosch 0:62b846b3988a 387
tgrosch 0:62b846b3988a 388 this->measurePhaseOffsetSet(false);
tgrosch 0:62b846b3988a 389 this->loadPhaseOffsetSet(false); ///* Calls the OPT3101::device::loadPhaseOffsetSet method with false argument so as to load all the phase offset registers from the OPT3101::device::calibration::phaseOffset instance instead of files
tgrosch 0:62b846b3988a 390 this->loadPhaseOffsetTempCoffSet();
tgrosch 0:62b846b3988a 391
tgrosch 0:62b846b3988a 392 this->loadPhaseAmbientCoffSet(); ///* Calls the OPT3101::device::loadPhaseAmbientCoffSet method to load all the phase offset temp coff
tgrosch 0:62b846b3988a 393
tgrosch 0:62b846b3988a 394 this->calibrationSession_perUnitFactoryCalibrationWriteRegisterDataToNonVolatileMemory(); ///* Calls the OPT3101::device::calibrationSession_perUnitFactoryCalibrationWriteRegisterDataToNonVolatileMemory to store the calibration data to a non-volatile memory
tgrosch 0:62b846b3988a 395 }
tgrosch 0:62b846b3988a 396
tgrosch 0:62b846b3988a 397 void OPT3101::device::perUnitFactoryUpdateIllumXtalk()
tgrosch 0:62b846b3988a 398 {
tgrosch 0:62b846b3988a 399
tgrosch 0:62b846b3988a 400 this->reset(); ///* Resets the device calling OPT3101::device::reset method
tgrosch 0:62b846b3988a 401
tgrosch 0:62b846b3988a 402 host.printf("INFO::Writing Initialization sequence I2C registers\r\n");
tgrosch 0:62b846b3988a 403 this->initialize(); ///* Initializes the OPT3101 device by calling OPT3101::device::initialize method
tgrosch 0:62b846b3988a 404 host.printf("INFO::Device Initialization Completed\r\n");
tgrosch 0:62b846b3988a 405 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 406 this->calibration->internalCrosstalk[0].report(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 407
tgrosch 0:62b846b3988a 408 this->measureIllumCrosstalkSet(false);
tgrosch 0:62b846b3988a 409 this->loadIllumCrosstalkSet(false); ///* Calls the OPT3101::device::loadIllumCrosstalkSet with false argument so that method to load all illum crosstalk settings from the OPT3101::device::crosstalk::illumCrosstalk member
tgrosch 0:62b846b3988a 410
tgrosch 0:62b846b3988a 411 this->calibrationSession_perUnitFactoryCalibrationWriteRegisterDataToNonVolatileMemory(); ///* Calls the OPT3101::device::calibrationSession_perUnitFactoryCalibrationWriteRegisterDataToNonVolatileMemory to store the calibration data to a non-volatile memory
tgrosch 0:62b846b3988a 412 }
tgrosch 0:62b846b3988a 413