Export to MBED Studio

Dependencies:   mbed

Committer:
tgrosch
Date:
Sun Oct 25 00:58:24 2020 +0000
Revision:
0:62b846b3988a
First successful compile.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tgrosch 0:62b846b3988a 1 /*!
tgrosch 0:62b846b3988a 2 * \file OPT3101device_Functions.cpp
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 * The file contains methods definitions for classes OPT3101::device OPT3101::frameData OPT3101::calibrationC
tgrosch 0:62b846b3988a 26 */
tgrosch 0:62b846b3988a 27 #include "OPT3101device.h"
tgrosch 0:62b846b3988a 28 //#include "definitions.h"
tgrosch 0:62b846b3988a 29
tgrosch 0:62b846b3988a 30 void OPT3101::device::reset() {
tgrosch 0:62b846b3988a 31 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 32 host.printf("INFO::Resetting Host\r\n");
tgrosch 0:62b846b3988a 33 host.resetDevice(); ///* Invokes the hostController::reset method
tgrosch 0:62b846b3988a 34 host.sleep(100);
tgrosch 0:62b846b3988a 35
tgrosch 0:62b846b3988a 36 }
tgrosch 0:62b846b3988a 37
tgrosch 0:62b846b3988a 38 void OPT3101::device::liveDataView(uint32_t nFrames,uint32_t refreshDelayinms,bool scroll){
tgrosch 0:62b846b3988a 39 uint32_t c0;
tgrosch 0:62b846b3988a 40 uint8_t c1;
tgrosch 0:62b846b3988a 41 OPT3101::frameData data;
tgrosch 0:62b846b3988a 42 host.printf("\r\n");
tgrosch 0:62b846b3988a 43 for(c1=0;c1<3;c1++)
tgrosch 0:62b846b3988a 44 host.printf("|Distmm, Phase,Amplud,SigS,AmbS,HDR|--");
tgrosch 0:62b846b3988a 45 host.printf("|Amb,Cntr,Tmain,Tillum | Count/Total |");
tgrosch 0:62b846b3988a 46 host.printf("\r\n");
tgrosch 0:62b846b3988a 47 for(c0=0;c0<nFrames;c0++){
tgrosch 0:62b846b3988a 48 data.capture(&host, this,this->calibration->extTempSensor_connected);
tgrosch 0:62b846b3988a 49 this->data[data.ledChannel]=data;
tgrosch 0:62b846b3988a 50 for(c1=0;c1<3;c1++){
tgrosch 0:62b846b3988a 51 if(this->data[c1].sigovl || this->data[c1].ambovl)
tgrosch 0:62b846b3988a 52 host.printfSetColor(0b100);
tgrosch 0:62b846b3988a 53 else
tgrosch 0:62b846b3988a 54 host.printfSetColor(0b010);
tgrosch 0:62b846b3988a 55 host.printf("|%06u,",(this->data[c1].phase*14989)>>16);
tgrosch 0:62b846b3988a 56 host.printf("%06u,",this->data[c1].phase);
tgrosch 0:62b846b3988a 57 host.printf("%06u,",this->data[c1].amplitude);
tgrosch 0:62b846b3988a 58 host.printf(" %1u,",this->data[c1].sigovl);
tgrosch 0:62b846b3988a 59 host.printf(" %1u,",this->data[c1].ambovl);
tgrosch 0:62b846b3988a 60 host.printf(" %1u|--",this->data[c1].illumDac);
tgrosch 0:62b846b3988a 61 }
tgrosch 0:62b846b3988a 62 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 63 host.printf("|%03d,",data.ambient);
tgrosch 0:62b846b3988a 64 host.printf("0x%02x,",data.frameCounter);
tgrosch 0:62b846b3988a 65 host.printf(" %+03d,",(int32_t) (((int32_t)data.tmain>>3)-256));
tgrosch 0:62b846b3988a 66 host.printf("%+07.4f|",((double)data.tillum/16-128));
tgrosch 0:62b846b3988a 67 host.printf("%07u",c0);
tgrosch 0:62b846b3988a 68 host.printf("/%07u|\r",nFrames);
tgrosch 0:62b846b3988a 69 if(scroll)
tgrosch 0:62b846b3988a 70 host.printf("\n");
tgrosch 0:62b846b3988a 71 host.sleep(refreshDelayinms);
tgrosch 0:62b846b3988a 72 }
tgrosch 0:62b846b3988a 73 host.printf("\n");
tgrosch 0:62b846b3988a 74 }
tgrosch 0:62b846b3988a 75
tgrosch 0:62b846b3988a 76 void OPT3101::device::resetInitAndViewData(uint32_t nFrames,bool loadCalibration){
tgrosch 0:62b846b3988a 77 this->reset();
tgrosch 0:62b846b3988a 78 host.sleep(5000);
tgrosch 0:62b846b3988a 79 this->initialize();
tgrosch 0:62b846b3988a 80 this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
tgrosch 0:62b846b3988a 81 this->calibration->internalCrosstalk[0].printHeader(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 82 this->calibration->internalCrosstalk[0].print(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 83 host.printf("\r\n");
tgrosch 0:62b846b3988a 84 if(loadCalibration){
tgrosch 0:62b846b3988a 85 this->manuallySetIllumCrosstalkTempCoffs();
tgrosch 0:62b846b3988a 86 this->manuallySetPhaseTempCoffs();
tgrosch 0:62b846b3988a 87 this->manuallySetPhaseAmbientCoffs();
tgrosch 0:62b846b3988a 88
tgrosch 0:62b846b3988a 89 this->loadIllumCrosstalkSet(true);
tgrosch 0:62b846b3988a 90 this->loadIllumCrosstalkTempCoffSet();
tgrosch 0:62b846b3988a 91
tgrosch 0:62b846b3988a 92 this->loadPhaseOffsetSet(true);
tgrosch 0:62b846b3988a 93 this->loadPhaseOffsetTempCoffSet();
tgrosch 0:62b846b3988a 94
tgrosch 0:62b846b3988a 95 this->loadPhaseAmbientCoffSet();
tgrosch 0:62b846b3988a 96 }
tgrosch 0:62b846b3988a 97 this->liveDataView(nFrames, this->configurationFlags_frameTimeInMilliSeconds, false);
tgrosch 0:62b846b3988a 98 }
tgrosch 0:62b846b3988a 99
tgrosch 0:62b846b3988a 100 bool OPT3101::device::validateI2C() {
tgrosch 0:62b846b3988a 101 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 102 uint32_t data;
tgrosch 0:62b846b3988a 103 bool status;
tgrosch 0:62b846b3988a 104 //0x8001A0
tgrosch 0:62b846b3988a 105 //data=0xA001802E
tgrosch 0:62b846b3988a 106 //data[0]=0x8;
tgrosch 0:62b846b3988a 107 //data[1]=001A0
tgrosch 0:62b846b3988a 108 status = 0;
tgrosch 0:62b846b3988a 109 host.printf("INFO::Validating I2C Transaction\r\n");
tgrosch 0:62b846b3988a 110 //#ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 111 status=host.i2c.read(0x2E,&data);
tgrosch 0:62b846b3988a 112 if(status){
tgrosch 0:62b846b3988a 113 host.printfSetColor(0b010);
tgrosch 0:62b846b3988a 114 host.printf("INFO::I2C Transaction Successful\r\n");
tgrosch 0:62b846b3988a 115 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 116 }
tgrosch 0:62b846b3988a 117 else{
tgrosch 0:62b846b3988a 118 host.printfSetColor(0b100);
tgrosch 0:62b846b3988a 119 host.printf("EROR::I2C Transaction Failed. Please check Connection\r\n");
tgrosch 0:62b846b3988a 120 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 121 }
tgrosch 0:62b846b3988a 122 return status;
tgrosch 0:62b846b3988a 123 //#endif
tgrosch 0:62b846b3988a 124
tgrosch 0:62b846b3988a 125 //#ifndef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 126 // host.printfSetColor(0b110);
tgrosch 0:62b846b3988a 127 // host.printf("WARN::I2C Status checking not implemented\r\n");
tgrosch 0:62b846b3988a 128 // host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 129 // return true;
tgrosch 0:62b846b3988a 130 //#endif
tgrosch 0:62b846b3988a 131
tgrosch 0:62b846b3988a 132 }
tgrosch 0:62b846b3988a 133
tgrosch 0:62b846b3988a 134 bool OPT3101::device::validateDesignID() {
tgrosch 0:62b846b3988a 135 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 136 uint32_t data[2];
tgrosch 0:62b846b3988a 137 bool status;
tgrosch 0:62b846b3988a 138 status = 0;
tgrosch 0:62b846b3988a 139 host.printf("INFO::Validating OPT3101 Design ID\r\n");
tgrosch 0:62b846b3988a 140 this->reg.iq_read_data_sel=4;
tgrosch 0:62b846b3988a 141 data[0]=host.readI2C(0x3b);
tgrosch 0:62b846b3988a 142 this->reg.iq_read_data_sel=5;
tgrosch 0:62b846b3988a 143 data[1]=host.readI2C(0x3b);
tgrosch 0:62b846b3988a 144
tgrosch 0:62b846b3988a 145 if(data[0]==0x100411 && data[1]==0xc01000){
tgrosch 0:62b846b3988a 146 status=true;
tgrosch 0:62b846b3988a 147 host.printfSetColor(0b010);
tgrosch 0:62b846b3988a 148 host.printf("INFO::Design ID 0x%06lx%06lx Verified\r\n",data[1],data[0]);
tgrosch 0:62b846b3988a 149 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 150 }
tgrosch 0:62b846b3988a 151 else{
tgrosch 0:62b846b3988a 152 status=false;
tgrosch 0:62b846b3988a 153 host.printfSetColor(0b110);
tgrosch 0:62b846b3988a 154 host.printf("WARN::Design ID 0x%06lx%06lx Not Maching\r\n",data[1],data[0]);
tgrosch 0:62b846b3988a 155 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 156 }
tgrosch 0:62b846b3988a 157 this->reg.iq_read_data_sel=0;
tgrosch 0:62b846b3988a 158 return status;
tgrosch 0:62b846b3988a 159 }
tgrosch 0:62b846b3988a 160
tgrosch 0:62b846b3988a 161
tgrosch 0:62b846b3988a 162 void OPT3101::device::measureAndCorrectInternalCrosstalk(OPT3101::crosstalkC *internalXtalk){
tgrosch 0:62b846b3988a 163 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 164 uint8_t regStore[5];
tgrosch 0:62b846b3988a 165 regStore[0]=this->reg.en_adaptive_hdr.read();
tgrosch 0:62b846b3988a 166 regStore[1]=this->reg.hdr_mode.read();
tgrosch 0:62b846b3988a 167 regStore[2]=this->reg.en_sequencer.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily buffered to local variables.
tgrosch 0:62b846b3988a 168 regStore[3]=this->reg.en_processor_values.read(); ///* Temporarily buffered register states are restored to the h/w with register writes while exiting this method.
tgrosch 0:62b846b3988a 169
tgrosch 0:62b846b3988a 170 this->reg.tg_en=0;
tgrosch 0:62b846b3988a 171 this->reg.en_adaptive_hdr=0;
tgrosch 0:62b846b3988a 172 this->reg.hdr_mode=0;
tgrosch 0:62b846b3988a 173 this->reg.en_sequencer=0;
tgrosch 0:62b846b3988a 174 this->reg.en_processor_values=0;
tgrosch 0:62b846b3988a 175 this->reg.tg_en=1;
tgrosch 0:62b846b3988a 176
tgrosch 0:62b846b3988a 177 this->reg.use_xtalk_reg_int=0;
tgrosch 0:62b846b3988a 178 this->reg.int_xtalk_calib=1; ///* Enables internal crosstalk measure and correct register OPT3101::registers::int_xtalk_calib
tgrosch 0:62b846b3988a 179 host.printf("INFO::Performing Internal Cross talk Measurement...\r\n");
tgrosch 0:62b846b3988a 180 host.sleep(this->configurationFlags_xtalkSettlingOneTauInMilliSeconds<<3); ///* Sleeps the host for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInMilliSeconds so that device settles
tgrosch 0:62b846b3988a 181 /* host.sleepDataReadyCounts(this->configurationFlags_xtalkSettlingOneTauInDataReadyCounts<<3); */
tgrosch 0:62b846b3988a 182 ///* Sleep delay can be replaced with wait for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInDataReadyCounts data ready pulses.User needs to implement based on host configuration
tgrosch 0:62b846b3988a 183
tgrosch 0:62b846b3988a 184 this->reg.int_xtalk_calib=0; ///* Disables internal crosstalk measure register OPT3101::registers::int_xtalk_calib to complete internal crosstalk measurement
tgrosch 0:62b846b3988a 185
tgrosch 0:62b846b3988a 186 regStore[4]=this->reg.iq_read_data_sel.read();
tgrosch 0:62b846b3988a 187 this->reg.iq_read_data_sel=0;
tgrosch 0:62b846b3988a 188 internalXtalk->readCrosstalkRegisters(this); ///* Reads the internal crosstalk registers OPT3101::registers::iphase_xtalk and OPT3101::registers::qphase_xtalk and assigns to internalXtalk input instance pointer of type OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 189 this->reg.iq_read_data_sel=regStore[4];
tgrosch 0:62b846b3988a 190
tgrosch 0:62b846b3988a 191 this->reg.tg_en=0;
tgrosch 0:62b846b3988a 192 this->reg.en_adaptive_hdr=regStore[0];
tgrosch 0:62b846b3988a 193 this->reg.hdr_mode=regStore[1];
tgrosch 0:62b846b3988a 194 this->reg.en_sequencer=regStore[2];
tgrosch 0:62b846b3988a 195 this->reg.en_processor_values=regStore[3]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
tgrosch 0:62b846b3988a 196 this->reg.tg_en=1;
tgrosch 0:62b846b3988a 197 host.printf("INFO::Internal Cross talk Measurement Completed\r\n");
tgrosch 0:62b846b3988a 198
tgrosch 0:62b846b3988a 199 }
tgrosch 0:62b846b3988a 200
tgrosch 0:62b846b3988a 201 void OPT3101::device::measureIllumCrosstalk(OPT3101::crosstalkC *illumXtalk) {
tgrosch 0:62b846b3988a 202 uint8_t regStore[2];
tgrosch 0:62b846b3988a 203 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 204 regStore[0] = this->reg.use_xtalk_reg_illum.read();
tgrosch 0:62b846b3988a 205 this->reg.use_xtalk_reg_illum = 0;
tgrosch 0:62b846b3988a 206 this->reg.illum_xtalk_calib = 1; ///* Enables illum crosstalk measure register OPT3101::registers::illum_xtalk_calib
tgrosch 0:62b846b3988a 207 host.sleep(this->configurationFlags_xtalkSettlingOneTauInMilliSeconds << 3); ///* Sleeps the host for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInMilliSeconds so that device settles
tgrosch 0:62b846b3988a 208 // The same can be replated with
tgrosch 0:62b846b3988a 209 // host.sleepDataReadyCounts(this->configurationFlags_xtalkSettlingOneTauInDataReadyCounts<<3); // This is for 8 Tau settings
tgrosch 0:62b846b3988a 210 ///* Sleep delay can be replaced with wait for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInDataReadyCounts data ready pulses.User needs to implement based on host configuration
tgrosch 0:62b846b3988a 211
tgrosch 0:62b846b3988a 212 this->reg.illum_xtalk_calib = 0;
tgrosch 0:62b846b3988a 213 //Wait Time
tgrosch 0:62b846b3988a 214
tgrosch 0:62b846b3988a 215 regStore[1] = this->reg.iq_read_data_sel.read(); ///* Reads the internal crosstalk registers OPT3101::registers::iphase_xtalk and OPT3101::registers::qphase_xtalk and assigns to illumXtalk input instance pointer of type OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 216 this->reg.iq_read_data_sel = 1;
tgrosch 0:62b846b3988a 217 illumXtalk->readCrosstalkRegisters(this);
tgrosch 0:62b846b3988a 218 illumXtalk->illumXtalk = true;
tgrosch 0:62b846b3988a 219
tgrosch 0:62b846b3988a 220 this->reg.iq_read_data_sel = regStore[1];
tgrosch 0:62b846b3988a 221 this->reg.use_xtalk_reg_illum = regStore[0];
tgrosch 0:62b846b3988a 222
tgrosch 0:62b846b3988a 223 illumXtalk->readTemperatureMain(this); ///* Reads main temp sensor and captures the same to input argument illumXtalk's OPT3101::crosstalkC::tmain
tgrosch 0:62b846b3988a 224 illumXtalk->readTemperatureIllum(this); ///* Reads external temp sensor and captures the same to input argument illumXtalk's OPT3101::crosstalkC::tillum
tgrosch 0:62b846b3988a 225
tgrosch 0:62b846b3988a 226 }
tgrosch 0:62b846b3988a 227
tgrosch 0:62b846b3988a 228 void OPT3101::device::measureIllumCrosstalkSet(bool saveToFile) {
tgrosch 0:62b846b3988a 229 uint8_t c0, c1;
tgrosch 0:62b846b3988a 230 uint16_t flashLocation;
tgrosch 0:62b846b3988a 231 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 232 char fileName[FILENAME_LENGTH];
tgrosch 0:62b846b3988a 233 #endif
tgrosch 0:62b846b3988a 234
tgrosch 0:62b846b3988a 235 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 236 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 237 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 238 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 239 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 240 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 241 host.printf("INFO:Performing Illum Crosstalk for TX%d HDR %d\r\n",c0,c1);
tgrosch 0:62b846b3988a 242 this->measureIllumCrosstalk(&this->calibration->illumCrosstalk[c0][c1], c0, c1 ? 'h' : 'l'); ///* Calls method OPT3101::device::measureIllumCrosstalk with argument OPT3101::calibrationC::illumCrosstalk
tgrosch 0:62b846b3988a 243 this->calibration->illumCrosstalk[c0][c1].printHeader(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 244 this->calibration->illumCrosstalk[c0][c1].print(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
tgrosch 0:62b846b3988a 245 host.printf("\r\n");
tgrosch 0:62b846b3988a 246
tgrosch 0:62b846b3988a 247 // Provide file name if save to File is implemented eg: illumCrosstalkTX{txChannel}Reg{regSet}_roomTemp
tgrosch 0:62b846b3988a 248 if(saveToFile){
tgrosch 0:62b846b3988a 249 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 250 sprintf(fileName, "%s/illumCrosstalk_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l'); ///* Creates filename illumCrosstalk_TX{channel}_{h/l}.txt in path filePath
tgrosch 0:62b846b3988a 251 this->calibration->illumCrosstalk[c0][c1].storeToFile(fileName); ///* Calls method OPT3101::crosstalkC::storeToFile to store the data
tgrosch 0:62b846b3988a 252 #endif
tgrosch 0:62b846b3988a 253 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 254 flashLocation=(c1+(c0<<1))<<4;
tgrosch 0:62b846b3988a 255 //TODO fix this host.flash.write(flashLocation, (uint8_t*)&this->calibration->illumCrosstalk[c0][c1] ,16);
tgrosch 0:62b846b3988a 256 host.printf("INFO:Writing Illum Cross talk for TX%d HDR %d to Flash location 0x%04x\r\n",c0,c1,flashLocation);
tgrosch 0:62b846b3988a 257 #endif // TIHOST
tgrosch 0:62b846b3988a 258 }
tgrosch 0:62b846b3988a 259 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 260 if(this->calibration->illumCrosstalk[c0][c1].magnitude()>800)
tgrosch 0:62b846b3988a 261 host.printf("WARN:Illumination Cross talk is very high. Check if Photo diode is covered well.. if so increase [force_scale_val] register by 1 count and add it to initialization method\r\n",flashLocation);
tgrosch 0:62b846b3988a 262 #endif // TIHOST
tgrosch 0:62b846b3988a 263 }
tgrosch 0:62b846b3988a 264 }
tgrosch 0:62b846b3988a 265 }
tgrosch 0:62b846b3988a 266 }
tgrosch 0:62b846b3988a 267 host.printf("INFO:Completed Illumination cross talk measurement for all channels\r\n");
tgrosch 0:62b846b3988a 268 }
tgrosch 0:62b846b3988a 269
tgrosch 0:62b846b3988a 270
tgrosch 0:62b846b3988a 271 void OPT3101::device::measureIllumCrosstalk( OPT3101::crosstalkC *illumXtalk, uint8_t txChannel, char registerSet,uint8_t shiftIllumPhase) {
tgrosch 0:62b846b3988a 272 uint8_t regStore[8];
tgrosch 0:62b846b3988a 273 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 274 regStore[0] = this->reg.en_sequencer.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily buffered to local variables.
tgrosch 0:62b846b3988a 275 regStore[1] = this->reg.en_processor_values.read();
tgrosch 0:62b846b3988a 276 regStore[2] = this->reg.sel_hdr_mode.read();
tgrosch 0:62b846b3988a 277 regStore[3] = this->reg.sel_tx_ch.read();
tgrosch 0:62b846b3988a 278 regStore[4] = this->reg.en_adaptive_hdr.read();
tgrosch 0:62b846b3988a 279 regStore[5] = this->reg.en_tx_switch.read();
tgrosch 0:62b846b3988a 280 regStore[6] = this->reg.shift_illum_phase.read();
tgrosch 0:62b846b3988a 281 regStore[7] = this->reg.en_temp_xtalk_corr.read();
tgrosch 0:62b846b3988a 282
tgrosch 0:62b846b3988a 283 this->reg.tg_en = 0;
tgrosch 0:62b846b3988a 284 this->reg.en_sequencer = 0;
tgrosch 0:62b846b3988a 285 this->reg.en_processor_values = 0;
tgrosch 0:62b846b3988a 286 if (registerSet == 'h')
tgrosch 0:62b846b3988a 287 this->reg.sel_hdr_mode = 1; ///* Register set is chosen based on registerSet input to this method by setting OPT3101::registers::sel_hdr_mode
tgrosch 0:62b846b3988a 288 if (registerSet == 'l')
tgrosch 0:62b846b3988a 289 this->reg.sel_hdr_mode = 0;
tgrosch 0:62b846b3988a 290 this->reg.sel_tx_ch = txChannel; ///* TX channel is chosen based on txChannel input to this method by setting OPT3101::registers::sel_tx_ch
tgrosch 0:62b846b3988a 291 this->reg.en_tx_switch = 0;
tgrosch 0:62b846b3988a 292 this->reg.en_adaptive_hdr = 0;
tgrosch 0:62b846b3988a 293 this->reg.shift_illum_phase = shiftIllumPhase; ///* Sets up the OPT3101::registers::shift_illum_phase based on the input to this method shiftIllumPhase
tgrosch 0:62b846b3988a 294 this->reg.tg_en = 1;
tgrosch 0:62b846b3988a 295
tgrosch 0:62b846b3988a 296 this->measureIllumCrosstalk(illumXtalk); ///* Measures illum crosstalk from registers OPT3101::registers::iphase_xtalk , and OPT3101::registers::qphase_xtalk and assigns to illumXtalk instance pointer of type OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 297 illumXtalk->illumDCdac = this->reg.ILLUM_DC_CURR_DAC.read();
tgrosch 0:62b846b3988a 298 illumXtalk->shiftIllumPhase = shiftIllumPhase; ///* Takes snapshot of device TX register configuration and assign them to illumXtalk instance pointer of type OPT3101::crosstalkC class
tgrosch 0:62b846b3988a 299 switch (txChannel) {
tgrosch 0:62b846b3988a 300 case 0:
tgrosch 0:62b846b3988a 301 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 302 illumXtalk->illumDac = this->reg.illum_dac_h_tx0.read();
tgrosch 0:62b846b3988a 303 illumXtalk->illumScale = this->reg.illum_scale_h_tx0.read();
tgrosch 0:62b846b3988a 304 }
tgrosch 0:62b846b3988a 305 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 306 illumXtalk->illumDac = this->reg.illum_dac_l_tx0.read();
tgrosch 0:62b846b3988a 307 illumXtalk->illumScale = this->reg.illum_scale_l_tx0.read();
tgrosch 0:62b846b3988a 308 }
tgrosch 0:62b846b3988a 309 break;
tgrosch 0:62b846b3988a 310 case 1:
tgrosch 0:62b846b3988a 311 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 312 illumXtalk->illumDac = this->reg.illum_dac_h_tx1.read();
tgrosch 0:62b846b3988a 313 illumXtalk->illumScale = this->reg.illum_scale_h_tx1.read();
tgrosch 0:62b846b3988a 314 }
tgrosch 0:62b846b3988a 315 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 316 illumXtalk->illumDac = this->reg.illum_dac_l_tx1.read();
tgrosch 0:62b846b3988a 317 illumXtalk->illumScale = this->reg.illum_scale_l_tx1.read();
tgrosch 0:62b846b3988a 318 }
tgrosch 0:62b846b3988a 319 break;
tgrosch 0:62b846b3988a 320 case 2:
tgrosch 0:62b846b3988a 321 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 322 illumXtalk->illumDac = this->reg.illum_dac_h_tx2.read();
tgrosch 0:62b846b3988a 323 illumXtalk->illumScale = this->reg.illum_scale_h_tx2.read();
tgrosch 0:62b846b3988a 324 }
tgrosch 0:62b846b3988a 325 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 326 illumXtalk->illumDac = this->reg.illum_dac_l_tx2.read();
tgrosch 0:62b846b3988a 327 illumXtalk->illumScale = this->reg.illum_scale_l_tx2.read();
tgrosch 0:62b846b3988a 328 }
tgrosch 0:62b846b3988a 329 break;
tgrosch 0:62b846b3988a 330 default:
tgrosch 0:62b846b3988a 331 break;
tgrosch 0:62b846b3988a 332 }
tgrosch 0:62b846b3988a 333 //printf("Illum Cross-talk for Illum current [%d] Magnitude is %4.2f [%d][%d][%d]\n", i, InternalXtalk.magnitude(), InternalXtalk.I, InternalXtalk.Q, InternalXtalk.xtalkScale);
tgrosch 0:62b846b3988a 334
tgrosch 0:62b846b3988a 335 this->reg.tg_en = 0;
tgrosch 0:62b846b3988a 336 this->reg.en_sequencer = regStore[0];
tgrosch 0:62b846b3988a 337 this->reg.en_processor_values = regStore[1];
tgrosch 0:62b846b3988a 338 this->reg.sel_hdr_mode = regStore[2];
tgrosch 0:62b846b3988a 339 this->reg.sel_tx_ch = regStore[3];
tgrosch 0:62b846b3988a 340 this->reg.en_adaptive_hdr = regStore[4];
tgrosch 0:62b846b3988a 341 this->reg.en_tx_switch = regStore[5];
tgrosch 0:62b846b3988a 342 this->reg.shift_illum_phase = regStore[6];
tgrosch 0:62b846b3988a 343 this->reg.en_temp_xtalk_corr = regStore[7]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
tgrosch 0:62b846b3988a 344
tgrosch 0:62b846b3988a 345 this->reg.tg_en = 1;
tgrosch 0:62b846b3988a 346 }
tgrosch 0:62b846b3988a 347
tgrosch 0:62b846b3988a 348 void OPT3101::device::loadIllumCrosstalk(OPT3101::crosstalkC *illumXtalk, uint8_t txChannel, char registerSet) {
tgrosch 0:62b846b3988a 349 uint8_t maxIllumXtalkScale;
tgrosch 0:62b846b3988a 350
tgrosch 0:62b846b3988a 351 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 352 maxIllumXtalkScale = illumXtalk->commonScale; ///* Load the common to all TX channels/register set registers (like for eg OPT3101::registers::illum_xtalk_reg_scale) to the h/w from the method input argument illumXtalk
tgrosch 0:62b846b3988a 353 this->reg.illum_xtalk_reg_scale = illumXtalk->commonScale;
tgrosch 0:62b846b3988a 354 this->reg.shift_illum_phase = illumXtalk->shiftIllumPhase;
tgrosch 0:62b846b3988a 355
tgrosch 0:62b846b3988a 356 //printf("Scale reduction is [%d] [%d] [%d] \n", illumXtalk->I, maxIllumXtalkScale - illumXtalk->xtalkScale, illumXtalk->I >>(maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 357 switch (txChannel) { ///* Based on txChannel and registerSet argument the the method loads the OPT3101::crosstalkC::I, OPT3101::crosstalkC::Q, OPT3101::crosstalkC::tmain and OPT3101::crosstalkC::tillum to device h/w specified TX channels and register set
tgrosch 0:62b846b3988a 358 case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument illumXtalk's OPT3101::crosstalkC::I to OPT3101::registers::iphase_xtalk_reg_hdr0_tx1 . Similarly the qphase_reg* registers, OPT3101::registers::tmain_calib_hdr0_tx1 and OPT3101::registers::tillum_calib_hdr0_tx1 are loaded from the input argument illumXtalk's OPT3101::crosstalkC::tmain and OPT3101::crosstalkC::tillum
tgrosch 0:62b846b3988a 359 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 360 this->reg.iphase_xtalk_reg_hdr1_tx0 = (uint16_t) (illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 361 this->reg.qphase_xtalk_reg_hdr1_tx0 = (uint16_t) (illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 362 this->reg.tmain_calib_hdr1_tx0 = illumXtalk->tmain;
tgrosch 0:62b846b3988a 363 this->reg.tillum_calib_hdr1_tx0 = illumXtalk->tillum;
tgrosch 0:62b846b3988a 364 }
tgrosch 0:62b846b3988a 365 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 366 this->reg.iphase_xtalk_reg_hdr0_tx0 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 367 this->reg.qphase_xtalk_reg_hdr0_tx0 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 368 this->reg.tmain_calib_hdr0_tx0 = illumXtalk->tmain;
tgrosch 0:62b846b3988a 369 this->reg.tillum_calib_hdr0_tx0 = illumXtalk->tillum;
tgrosch 0:62b846b3988a 370 }
tgrosch 0:62b846b3988a 371 break;
tgrosch 0:62b846b3988a 372 case 1:
tgrosch 0:62b846b3988a 373 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 374 this->reg.iphase_xtalk_reg_hdr1_tx1 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 375 this->reg.qphase_xtalk_reg_hdr1_tx1 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 376 this->reg.tmain_calib_hdr1_tx1 = illumXtalk->tmain;
tgrosch 0:62b846b3988a 377 this->reg.tillum_calib_hdr1_tx1 = illumXtalk->tillum;
tgrosch 0:62b846b3988a 378 }
tgrosch 0:62b846b3988a 379 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 380 this->reg.iphase_xtalk_reg_hdr0_tx1 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 381 this->reg.qphase_xtalk_reg_hdr0_tx1 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 382 this->reg.tmain_calib_hdr0_tx1 = illumXtalk->tmain;
tgrosch 0:62b846b3988a 383 this->reg.tillum_calib_hdr0_tx1 = illumXtalk->tillum;
tgrosch 0:62b846b3988a 384 }
tgrosch 0:62b846b3988a 385 break;
tgrosch 0:62b846b3988a 386 case 2:
tgrosch 0:62b846b3988a 387 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 388 this->reg.iphase_xtalk_reg_hdr1_tx2 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 389 this->reg.qphase_xtalk_reg_hdr1_tx2 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 390 this->reg.tmain_calib_hdr1_tx2 = illumXtalk->tmain;
tgrosch 0:62b846b3988a 391 this->reg.tillum_calib_hdr1_tx2 = illumXtalk->tillum;
tgrosch 0:62b846b3988a 392 }
tgrosch 0:62b846b3988a 393 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 394 this->reg.iphase_xtalk_reg_hdr0_tx2 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 395 this->reg.qphase_xtalk_reg_hdr0_tx2 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 396 this->reg.tmain_calib_hdr0_tx2 = illumXtalk->tmain;
tgrosch 0:62b846b3988a 397 this->reg.tillum_calib_hdr0_tx2 = illumXtalk->tillum;
tgrosch 0:62b846b3988a 398 }
tgrosch 0:62b846b3988a 399 break;
tgrosch 0:62b846b3988a 400 default:
tgrosch 0:62b846b3988a 401 break;
tgrosch 0:62b846b3988a 402 }
tgrosch 0:62b846b3988a 403
tgrosch 0:62b846b3988a 404 }
tgrosch 0:62b846b3988a 405
tgrosch 0:62b846b3988a 406 void OPT3101::device::loadPhaseOffset(OPT3101::phaseOffsetC *phaseOffset, uint8_t txChannel, char registerSet)
tgrosch 0:62b846b3988a 407 {
tgrosch 0:62b846b3988a 408 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 409
tgrosch 0:62b846b3988a 410 //printf("Scale reduction is [%d] [%d] [%d] \n", illumXtalk->I, maxIllumXtalkScale - illumXtalk->xtalkScale, illumXtalk->I >>(maxIllumXtalkScale - illumXtalk->xtalkScale));
tgrosch 0:62b846b3988a 411 this->reg.en_phase_corr = 1; ///* Enables the phase offset correction register OPT3101::registers::en_phase_corr
tgrosch 0:62b846b3988a 412 switch (txChannel) { ///* Based on txChannel and registerSet argument the the method loads the OPT3101::phaseOffsetC::phaseOffset, OPT3101::phaseOffsetC::frameData::tmain and OPT3101::phaseOffsetC::frameData::tillum to device h/w specified TX channels and register set
tgrosch 0:62b846b3988a 413 case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument phaseOffset's OPT3101::phaseOffsetC::phaseOffset to OPT3101::registers::phase_offset_hdr0_tx1 OPT3101::registers::tmain_calib_hdr0_tx1 and OPT3101::registers::tillum_calib_hdr0_tx1 are loaded from the input argument phaseOffset's OPT3101::phaseOffsetC::frameData::tmain and OPT3101::phaseOffsetC::frameData::tillum
tgrosch 0:62b846b3988a 414 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 415 this->reg.phase_offset_hdr1_tx0 = phaseOffset->phaseOffset;
tgrosch 0:62b846b3988a 416 this->reg.tmain_calib_hdr1_tx0 = phaseOffset->data.tmain;
tgrosch 0:62b846b3988a 417 this->reg.tillum_calib_hdr1_tx0 = phaseOffset->data.tillum;
tgrosch 0:62b846b3988a 418 }
tgrosch 0:62b846b3988a 419 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 420 this->reg.phase_offset_hdr0_tx0 = phaseOffset->phaseOffset;
tgrosch 0:62b846b3988a 421 this->reg.tmain_calib_hdr0_tx0 = phaseOffset->data.tmain;
tgrosch 0:62b846b3988a 422 this->reg.tillum_calib_hdr0_tx0 = phaseOffset->data.tillum;
tgrosch 0:62b846b3988a 423 }
tgrosch 0:62b846b3988a 424 break;
tgrosch 0:62b846b3988a 425 case 1:
tgrosch 0:62b846b3988a 426 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 427 this->reg.phase_offset_hdr1_tx1 = phaseOffset->phaseOffset;
tgrosch 0:62b846b3988a 428 this->reg.tmain_calib_hdr1_tx1 = phaseOffset->data.tmain;
tgrosch 0:62b846b3988a 429 this->reg.tillum_calib_hdr1_tx1 = phaseOffset->data.tillum;
tgrosch 0:62b846b3988a 430 }
tgrosch 0:62b846b3988a 431 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 432 this->reg.phase_offset_hdr0_tx1 = phaseOffset->phaseOffset;
tgrosch 0:62b846b3988a 433 this->reg.tmain_calib_hdr0_tx1 = phaseOffset->data.tmain;
tgrosch 0:62b846b3988a 434 this->reg.tillum_calib_hdr0_tx1 = phaseOffset->data.tillum;
tgrosch 0:62b846b3988a 435 }
tgrosch 0:62b846b3988a 436 break;
tgrosch 0:62b846b3988a 437 case 2:
tgrosch 0:62b846b3988a 438 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 439 this->reg.phase_offset_hdr1_tx2 = phaseOffset->phaseOffset;
tgrosch 0:62b846b3988a 440 this->reg.tmain_calib_hdr1_tx2 = phaseOffset->data.tmain;
tgrosch 0:62b846b3988a 441 this->reg.tillum_calib_hdr1_tx2 = phaseOffset->data.tillum;
tgrosch 0:62b846b3988a 442 }
tgrosch 0:62b846b3988a 443 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 444 this->reg.phase_offset_hdr0_tx2 = phaseOffset->phaseOffset;
tgrosch 0:62b846b3988a 445 this->reg.tmain_calib_hdr0_tx2 = phaseOffset->data.tmain;
tgrosch 0:62b846b3988a 446 this->reg.tillum_calib_hdr0_tx2 = phaseOffset->data.tillum;
tgrosch 0:62b846b3988a 447 }
tgrosch 0:62b846b3988a 448 break;
tgrosch 0:62b846b3988a 449 default:
tgrosch 0:62b846b3988a 450 break;
tgrosch 0:62b846b3988a 451 }
tgrosch 0:62b846b3988a 452 }
tgrosch 0:62b846b3988a 453
tgrosch 0:62b846b3988a 454 void OPT3101::device::loadIllumCrosstalkTempCoff(OPT3101::crosstalkTempCoffC *illumXtalkTempCoff, uint8_t txChannel, char registerSet)
tgrosch 0:62b846b3988a 455 {
tgrosch 0:62b846b3988a 456 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 457
tgrosch 0:62b846b3988a 458 this->reg.scale_temp_coeff_xtalk = illumXtalkTempCoff->commonScale; ///* loads common scale OPT3101::crosstalkTempCoffC::commonScale from input argument illumXtalkTempCoff to device register OPT3101::registers::scale_temp_coeff_xtalk
tgrosch 0:62b846b3988a 459 switch (txChannel) { ///* Based on txChannel and registerSet argument the method loads the OPT3101::crosstalkTempCoffC::coffIReg and OPT3101::crosstalkTempCoffC::coffQReg to respective register set and channel registers
tgrosch 0:62b846b3988a 460 case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument illumXtalkTempCoff's OPT3101::crosstalkTempCoffC::coffIReg to OPT3101::registers::temp_coeff_xtalk_iphase_hdr0_tx1 and similarly for the qphase register as well
tgrosch 0:62b846b3988a 461 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 462 this->reg.temp_coeff_xtalk_iphase_hdr1_tx0 = illumXtalkTempCoff->coffIReg;
tgrosch 0:62b846b3988a 463 this->reg.temp_coeff_xtalk_qphase_hdr1_tx0 = illumXtalkTempCoff->coffQReg;
tgrosch 0:62b846b3988a 464 }
tgrosch 0:62b846b3988a 465 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 466 this->reg.temp_coeff_xtalk_iphase_hdr0_tx0 = illumXtalkTempCoff->coffIReg;
tgrosch 0:62b846b3988a 467 this->reg.temp_coeff_xtalk_qphase_hdr0_tx0 = illumXtalkTempCoff->coffQReg;
tgrosch 0:62b846b3988a 468 }
tgrosch 0:62b846b3988a 469 break;
tgrosch 0:62b846b3988a 470 case 1:
tgrosch 0:62b846b3988a 471 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 472 this->reg.temp_coeff_xtalk_iphase_hdr1_tx1 = illumXtalkTempCoff->coffIReg;
tgrosch 0:62b846b3988a 473 this->reg.temp_coeff_xtalk_qphase_hdr1_tx1 = illumXtalkTempCoff->coffQReg;
tgrosch 0:62b846b3988a 474 }
tgrosch 0:62b846b3988a 475 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 476 this->reg.temp_coeff_xtalk_iphase_hdr0_tx1 = illumXtalkTempCoff->coffIReg;
tgrosch 0:62b846b3988a 477 this->reg.temp_coeff_xtalk_qphase_hdr0_tx1 = illumXtalkTempCoff->coffQReg;
tgrosch 0:62b846b3988a 478 }
tgrosch 0:62b846b3988a 479 break;
tgrosch 0:62b846b3988a 480 case 2:
tgrosch 0:62b846b3988a 481 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 482 this->reg.temp_coeff_xtalk_iphase_hdr1_tx2 = illumXtalkTempCoff->coffIReg;
tgrosch 0:62b846b3988a 483 this->reg.temp_coeff_xtalk_qphase_hdr1_tx2 = illumXtalkTempCoff->coffQReg;
tgrosch 0:62b846b3988a 484 }
tgrosch 0:62b846b3988a 485 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 486 this->reg.temp_coeff_xtalk_iphase_hdr0_tx2 = illumXtalkTempCoff->coffIReg;
tgrosch 0:62b846b3988a 487 this->reg.temp_coeff_xtalk_qphase_hdr0_tx2 = illumXtalkTempCoff->coffQReg;
tgrosch 0:62b846b3988a 488 }
tgrosch 0:62b846b3988a 489 break;
tgrosch 0:62b846b3988a 490 default:
tgrosch 0:62b846b3988a 491 break;
tgrosch 0:62b846b3988a 492 }
tgrosch 0:62b846b3988a 493
tgrosch 0:62b846b3988a 494 }
tgrosch 0:62b846b3988a 495
tgrosch 0:62b846b3988a 496 void OPT3101::device::loadPhaseOffsetTempCoff(OPT3101::phaseTempCoffC *phaseTempCoff, uint8_t txChannel, char registerSet)
tgrosch 0:62b846b3988a 497 {
tgrosch 0:62b846b3988a 498 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 499
tgrosch 0:62b846b3988a 500 this->reg.en_temp_corr = 1; ///* Enables the phase temp coefficient register OPT3101::registers::en_temp_corr
tgrosch 0:62b846b3988a 501 this->reg.scale_phase_temp_coeff = phaseTempCoff->commonScale; ///* Sets the common scale register OPT3101::registers::scale_phase_temp_coeff with value from input argument phaseTempCoff's OPT3101::phaseTempCoffC::commonScale
tgrosch 0:62b846b3988a 502 switch (txChannel) { ///* Based on txChannel and registerSet argument the method loads the OPT3101::phaseTempCoffC::coffReg to respective register set and channel registers
tgrosch 0:62b846b3988a 503 case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument phaseTempCoff's OPT3101::phaseTempCoffC::coffReg to OPT3101::registers::temp_coeff_illum_hdr0_tx1 or OPT3101::registers::temp_coeff_main_hdr0_tx1 depending on if phaseTempCoff's OPT3101::phaseTempCoffC::istMainCoff is True or False
tgrosch 0:62b846b3988a 504 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 505 if (phaseTempCoff->istMainCoff)
tgrosch 0:62b846b3988a 506 this->reg.temp_coeff_main_hdr1_tx0 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 507 else
tgrosch 0:62b846b3988a 508 this->reg.temp_coeff_illum_hdr1_tx0 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 509 }
tgrosch 0:62b846b3988a 510 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 511 if (phaseTempCoff->istMainCoff)
tgrosch 0:62b846b3988a 512 this->reg.temp_coeff_main_hdr0_tx0 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 513 else
tgrosch 0:62b846b3988a 514 this->reg.temp_coeff_illum_hdr0_tx0 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 515 }
tgrosch 0:62b846b3988a 516 break;
tgrosch 0:62b846b3988a 517 case 1:
tgrosch 0:62b846b3988a 518 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 519 if (phaseTempCoff->istMainCoff)
tgrosch 0:62b846b3988a 520 this->reg.temp_coeff_main_hdr1_tx1 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 521 else
tgrosch 0:62b846b3988a 522 this->reg.temp_coeff_illum_hdr1_tx1 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 523 }
tgrosch 0:62b846b3988a 524 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 525 if (phaseTempCoff->istMainCoff)
tgrosch 0:62b846b3988a 526 this->reg.temp_coeff_main_hdr0_tx1 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 527 else
tgrosch 0:62b846b3988a 528 this->reg.temp_coeff_illum_hdr0_tx1 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 529 }
tgrosch 0:62b846b3988a 530 break;
tgrosch 0:62b846b3988a 531 case 2:
tgrosch 0:62b846b3988a 532 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 533 if (phaseTempCoff->istMainCoff)
tgrosch 0:62b846b3988a 534 this->reg.temp_coeff_main_hdr1_tx2 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 535 else
tgrosch 0:62b846b3988a 536 this->reg.temp_coeff_illum_hdr1_tx2 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 537 }
tgrosch 0:62b846b3988a 538 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 539 if (phaseTempCoff->istMainCoff)
tgrosch 0:62b846b3988a 540 this->reg.temp_coeff_main_hdr0_tx2 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 541 else
tgrosch 0:62b846b3988a 542 this->reg.temp_coeff_illum_hdr0_tx2 = phaseTempCoff->coffReg;
tgrosch 0:62b846b3988a 543 }
tgrosch 0:62b846b3988a 544 break;
tgrosch 0:62b846b3988a 545 default:
tgrosch 0:62b846b3988a 546 break;
tgrosch 0:62b846b3988a 547 }
tgrosch 0:62b846b3988a 548 }
tgrosch 0:62b846b3988a 549
tgrosch 0:62b846b3988a 550 void OPT3101::device::loadPhaseAmbientCoff(OPT3101::phaseAmbientCoffC *phaseAmbientCoff)
tgrosch 0:62b846b3988a 551 {
tgrosch 0:62b846b3988a 552 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 553
tgrosch 0:62b846b3988a 554 this->reg.scale_amb_phase_corr_coeff = phaseAmbientCoff->commonScale; ///* Assigns all the register entries from phaseAmbientCoff OPT3101::phaseAmbientCoffC to h/w registers
tgrosch 0:62b846b3988a 555 this->reg.amb_phase_corr_pwl_coeff0 = phaseAmbientCoff->coffReg[0]; ///* for eg: input argument phaseAmbientCoff's OPT3101::phaseAmbientCoffC::coffReg is loaded to OPT3101::registers::amb_phase_corr_pwl_coeff0 and other related registers
tgrosch 0:62b846b3988a 556 this->reg.amb_phase_corr_pwl_coeff1 = phaseAmbientCoff->coffReg[1];
tgrosch 0:62b846b3988a 557 this->reg.amb_phase_corr_pwl_coeff2 = phaseAmbientCoff->coffReg[2];
tgrosch 0:62b846b3988a 558 this->reg.amb_phase_corr_pwl_coeff3 = phaseAmbientCoff->coffReg[3];
tgrosch 0:62b846b3988a 559 this->reg.amb_phase_corr_pwl_x0 = phaseAmbientCoff->splitsReg[0];
tgrosch 0:62b846b3988a 560 this->reg.amb_phase_corr_pwl_x1 = phaseAmbientCoff->splitsReg[1];
tgrosch 0:62b846b3988a 561 this->reg.amb_phase_corr_pwl_x2 = phaseAmbientCoff->splitsReg[2];
tgrosch 0:62b846b3988a 562 }
tgrosch 0:62b846b3988a 563
tgrosch 0:62b846b3988a 564 OPT3101::frameData::frameData()
tgrosch 0:62b846b3988a 565 {
tgrosch 0:62b846b3988a 566 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 567
tgrosch 0:62b846b3988a 568 this->phase = 0; ///* Initializes all members to 0
tgrosch 0:62b846b3988a 569 this->phaseovl = false;
tgrosch 0:62b846b3988a 570 this->phaseovlf2 = false;
tgrosch 0:62b846b3988a 571 this->ambovl = false;
tgrosch 0:62b846b3988a 572 this->illumDac = false;
tgrosch 0:62b846b3988a 573 this->ledChannel = 0;
tgrosch 0:62b846b3988a 574 this->frameStatus = false;
tgrosch 0:62b846b3988a 575 this->dealiasFreq = false;
tgrosch 0:62b846b3988a 576 this->frameCounter = 0;
tgrosch 0:62b846b3988a 577 this->amplitude = 0;
tgrosch 0:62b846b3988a 578 this->sigovl = false;
tgrosch 0:62b846b3988a 579 this->dealiasBin = 0;
tgrosch 0:62b846b3988a 580 this->ambient = 0;
tgrosch 0:62b846b3988a 581 this->temp = 0;
tgrosch 0:62b846b3988a 582 this->tmain = 0;
tgrosch 0:62b846b3988a 583 this->tillum = 0;
tgrosch 0:62b846b3988a 584
tgrosch 0:62b846b3988a 585 }
tgrosch 0:62b846b3988a 586
tgrosch 0:62b846b3988a 587 void OPT3101::frameData::capture(hostController *host, OPT3101::device *dev,bool readTillum) {
tgrosch 0:62b846b3988a 588 uint8_t c0;
tgrosch 0:62b846b3988a 589 uint32_t data32[3];
tgrosch 0:62b846b3988a 590 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 591 host->sleep((dev->configurationFlags_frameTimeInMilliSeconds)<<1); ///* Sleep host for a specified time depending on device configuration to OPT3101 AFE can update measurements to the registers.
tgrosch 0:62b846b3988a 592 for (c0 = 8; c0 < 11; c0++) ///* Performs a direct read of I2C registers 0x08 0x09 and 0x0A directly though hostController::readI2C method
tgrosch 0:62b846b3988a 593 data32[c0-8] = (host->readI2C(c0));
tgrosch 0:62b846b3988a 594
tgrosch 0:62b846b3988a 595 this->phase = data32[0] & 0xFFFF; ///* Maps the I2C read values to the class members like OPT3101::frameData::phase, OPT3101::frameData::amplitude etc
tgrosch 0:62b846b3988a 596 this->phaseovl = (data32[0] >> 16) & 0x1;
tgrosch 0:62b846b3988a 597
tgrosch 0:62b846b3988a 598 this->phase |= (((uint32_t) this->phaseovl) << 16);
tgrosch 0:62b846b3988a 599
tgrosch 0:62b846b3988a 600 this->illumDac = (data32[0] >> 17) & 0x01;
tgrosch 0:62b846b3988a 601 this->ledChannel = (data32[0] >> 18) & 0x03;
tgrosch 0:62b846b3988a 602 this->frameStatus = (data32[0] >> 20) & 0x01;
tgrosch 0:62b846b3988a 603 this->dealiasFreq = (data32[0] >> 21) & 0x01;
tgrosch 0:62b846b3988a 604 this->ambovl = (data32[0] >> 22) & 0x01;
tgrosch 0:62b846b3988a 605 this->frameCounter = (data32[0] >> 23) & 0x01;
tgrosch 0:62b846b3988a 606
tgrosch 0:62b846b3988a 607 this->amplitude = data32[1] & 0xFFFF;
tgrosch 0:62b846b3988a 608 this->frameCounter |= ((data32[1] >> 16) & 0x03) << 1;
tgrosch 0:62b846b3988a 609 this->sigovl = (data32[1] >> 18) & 0x01;
tgrosch 0:62b846b3988a 610 this->phaseovlf2 = (data32[1] >> 19) & 0x01;
tgrosch 0:62b846b3988a 611 this->dealiasBin = (data32[1] >> 20) & 0x0F;
tgrosch 0:62b846b3988a 612
tgrosch 0:62b846b3988a 613 this->frameCounter |= (data32[2] & 0x03) << 3;
tgrosch 0:62b846b3988a 614 this->ambient = (data32[2] >> 2) & 0x3FF;
tgrosch 0:62b846b3988a 615 this->temp = (data32[2] >> 12) & 0xFFF;
tgrosch 0:62b846b3988a 616 this->tmain = this->temp;
tgrosch 0:62b846b3988a 617 if (readTillum)
tgrosch 0:62b846b3988a 618 this->tillum = dev->reg.tillum.read(); ///* Based on readIllum flag reads the OPT3101::registers::tillum and assigns to OPT3101::frameData::tillum
tgrosch 0:62b846b3988a 619
tgrosch 0:62b846b3988a 620 }
tgrosch 0:62b846b3988a 621
tgrosch 0:62b846b3988a 622 void OPT3101::frameData::report()
tgrosch 0:62b846b3988a 623 {
tgrosch 0:62b846b3988a 624 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 625 host.printf("-----------------------\r\n");
tgrosch 0:62b846b3988a 626 host.printf("Frame data Class Report\r\n");
tgrosch 0:62b846b3988a 627 host.printf("-----------------------\r\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 628 host.printf("phase=%d\r\n", this->phase);
tgrosch 0:62b846b3988a 629 host.printf("phaseovl=%d\r\n", this->phaseovl);
tgrosch 0:62b846b3988a 630 host.printf("phaseovlf2=%d\r\n", this->phaseovlf2);
tgrosch 0:62b846b3988a 631 host.printf("ambovl=%d\r\n", this->ambovl);
tgrosch 0:62b846b3988a 632 host.printf("illumDac=%d\r\n", this->illumDac);
tgrosch 0:62b846b3988a 633 host.printf("ledChannel=%d\r\n", this->ledChannel);
tgrosch 0:62b846b3988a 634 host.printf("frameStatus=%d\r\n", this->frameStatus);
tgrosch 0:62b846b3988a 635 host.printf("dealiasFreq=%d\r\n", this->dealiasFreq);
tgrosch 0:62b846b3988a 636 host.printf("frameCounter=%d\r\n", this->frameCounter);
tgrosch 0:62b846b3988a 637 host.printf("amplitude=%d\r\n", this->amplitude);
tgrosch 0:62b846b3988a 638 host.printf("sigovl=%d\r\n", this->sigovl);
tgrosch 0:62b846b3988a 639 host.printf("dealiasBin=%d\r\n", this->dealiasBin);
tgrosch 0:62b846b3988a 640 host.printf("ambient=%d\r\n", this->ambient);
tgrosch 0:62b846b3988a 641 host.printf("temp=%d\r\n", this->temp);
tgrosch 0:62b846b3988a 642 host.printf("tmain=%d\r\n", this->tmain);
tgrosch 0:62b846b3988a 643 host.printf("tillum=%d\r\n", this->tillum);
tgrosch 0:62b846b3988a 644 host.printf("-----------------------\r\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 645 }
tgrosch 0:62b846b3988a 646 void OPT3101::frameData::printHeader()
tgrosch 0:62b846b3988a 647 {
tgrosch 0:62b846b3988a 648 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 649 host.printfSetColor(0b001);
tgrosch 0:62b846b3988a 650 host.printf("Phase,");
tgrosch 0:62b846b3988a 651 host.printf("Amplt,");
tgrosch 0:62b846b3988a 652 host.printf("SigOl,");
tgrosch 0:62b846b3988a 653 host.printf("AmbOl,");
tgrosch 0:62b846b3988a 654 host.printf("Amb,");
tgrosch 0:62b846b3988a 655 host.printf("tMain,");
tgrosch 0:62b846b3988a 656 host.printf("tIlum,");
tgrosch 0:62b846b3988a 657 host.printf("tMain(C),");
tgrosch 0:62b846b3988a 658 host.printf(" tIlum(C)\r\n");
tgrosch 0:62b846b3988a 659 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 660 }
tgrosch 0:62b846b3988a 661
tgrosch 0:62b846b3988a 662
tgrosch 0:62b846b3988a 663 void OPT3101::frameData::print()
tgrosch 0:62b846b3988a 664 {
tgrosch 0:62b846b3988a 665 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 666 host.printfSetColor(0b001);
tgrosch 0:62b846b3988a 667 host.printf("%05u,",this->phase);
tgrosch 0:62b846b3988a 668 host.printf("%05u,",this->amplitude);
tgrosch 0:62b846b3988a 669 host.printf(" %1u,",this->sigovl);
tgrosch 0:62b846b3988a 670 host.printf(" %1u,",this->ambovl);
tgrosch 0:62b846b3988a 671 host.printf("%03u,",this->ambient);
tgrosch 0:62b846b3988a 672 host.printf(" %04d,",this->tmain);
tgrosch 0:62b846b3988a 673 host.printf(" %04d,",this->tillum);
tgrosch 0:62b846b3988a 674 host.printf(" %+03d,",(int8_t) ((((int16_t)this->tmain)>>3)-256));
tgrosch 0:62b846b3988a 675 host.printf(" %+07.4f\r\n",((double)(((int16_t)this->tillum)-2048))/16.0);
tgrosch 0:62b846b3988a 676 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 677 }
tgrosch 0:62b846b3988a 678
tgrosch 0:62b846b3988a 679
tgrosch 0:62b846b3988a 680 void OPT3101::frameData::populateWithMean(OPT3101::frameData *inputData, uint16_t nFrames)
tgrosch 0:62b846b3988a 681 {
tgrosch 0:62b846b3988a 682 uint16_t c0;
tgrosch 0:62b846b3988a 683 uint16_t shiftBits;
tgrosch 0:62b846b3988a 684 uint32_t accum;
tgrosch 0:62b846b3988a 685 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 686 shiftBits = 0;
tgrosch 0:62b846b3988a 687 nFrames = nFrames == 0 ? 1 : nFrames; ///* Sets nFrames to 1 when nFrames is 0
tgrosch 0:62b846b3988a 688 if(nFrames>1)
tgrosch 0:62b846b3988a 689 while (((nFrames-1) >> ++shiftBits) > 0); ///* Finds the smallest 2^N number higher than the nFrames provided in the argument of this method
tgrosch 0:62b846b3988a 690 else
tgrosch 0:62b846b3988a 691
tgrosch 0:62b846b3988a 692
tgrosch 0:62b846b3988a 693
tgrosch 0:62b846b3988a 694 // All flags
tgrosch 0:62b846b3988a 695 this->phaseovl = 0;
tgrosch 0:62b846b3988a 696 this->phaseovlf2 = 0;
tgrosch 0:62b846b3988a 697 this->ambovl = 0;
tgrosch 0:62b846b3988a 698 this->illumDac = inputData[0].illumDac;
tgrosch 0:62b846b3988a 699 this->ledChannel = inputData[0].ledChannel;
tgrosch 0:62b846b3988a 700 this->frameStatus = 0;
tgrosch 0:62b846b3988a 701 this->dealiasFreq = inputData[0].dealiasFreq;
tgrosch 0:62b846b3988a 702 this->sigovl = 0;
tgrosch 0:62b846b3988a 703 this->dealiasBin = inputData[0].dealiasBin;
tgrosch 0:62b846b3988a 704 this->frameCounter = 0;
tgrosch 0:62b846b3988a 705
tgrosch 0:62b846b3988a 706 for (c0 = 0; c0 < nFrames; c0++) {
tgrosch 0:62b846b3988a 707 this->phaseovl |= inputData[0].phaseovl;
tgrosch 0:62b846b3988a 708 this->phaseovlf2 |= inputData[0].phaseovlf2;
tgrosch 0:62b846b3988a 709 this->ambovl |= inputData[0].ambovl;
tgrosch 0:62b846b3988a 710 this->sigovl |= inputData[0].sigovl;
tgrosch 0:62b846b3988a 711 }
tgrosch 0:62b846b3988a 712
tgrosch 0:62b846b3988a 713
tgrosch 0:62b846b3988a 714 // Mean of phase if found
tgrosch 0:62b846b3988a 715 accum = 0; ///* Accumulates and measures mean for all the input class instance members and assigns them to the method's class members
tgrosch 0:62b846b3988a 716 for (c0 = 0; c0 < nFrames; c0++)
tgrosch 0:62b846b3988a 717 accum += inputData[c0].phase;
tgrosch 0:62b846b3988a 718 this->phase = accum >> shiftBits;
tgrosch 0:62b846b3988a 719
tgrosch 0:62b846b3988a 720 // Mean of amplitude is found
tgrosch 0:62b846b3988a 721 accum = 0;
tgrosch 0:62b846b3988a 722 for (c0 = 0; c0 < nFrames; c0++)
tgrosch 0:62b846b3988a 723 accum += inputData[c0].amplitude;
tgrosch 0:62b846b3988a 724 this->amplitude = accum >> shiftBits;
tgrosch 0:62b846b3988a 725
tgrosch 0:62b846b3988a 726 // Mean of ambient is found
tgrosch 0:62b846b3988a 727 accum = 0;
tgrosch 0:62b846b3988a 728 for (c0 = 0; c0 < nFrames; c0++)
tgrosch 0:62b846b3988a 729 accum += inputData[c0].ambient;
tgrosch 0:62b846b3988a 730 this->ambient = accum >> shiftBits;
tgrosch 0:62b846b3988a 731
tgrosch 0:62b846b3988a 732 // Mean of temp is found
tgrosch 0:62b846b3988a 733 accum = 0;
tgrosch 0:62b846b3988a 734 for (c0 = 0; c0 < nFrames; c0++)
tgrosch 0:62b846b3988a 735 accum += inputData[c0].temp;
tgrosch 0:62b846b3988a 736 this->temp = accum >> shiftBits;
tgrosch 0:62b846b3988a 737
tgrosch 0:62b846b3988a 738 // Mean of tmain is found
tgrosch 0:62b846b3988a 739 accum = 0;
tgrosch 0:62b846b3988a 740 for (c0 = 0; c0 < nFrames; c0++)
tgrosch 0:62b846b3988a 741 accum += inputData[c0].tmain;
tgrosch 0:62b846b3988a 742
tgrosch 0:62b846b3988a 743 this->tmain = accum >> shiftBits;
tgrosch 0:62b846b3988a 744
tgrosch 0:62b846b3988a 745 // Mean of tillum is found
tgrosch 0:62b846b3988a 746 accum = 0;
tgrosch 0:62b846b3988a 747 for (c0 = 0; c0 < nFrames; c0++)
tgrosch 0:62b846b3988a 748 accum += inputData[c0].tillum;
tgrosch 0:62b846b3988a 749 this->tillum = accum >> shiftBits;
tgrosch 0:62b846b3988a 750 ///* <b>Warning:</b> When nFrames is a non 2^N number the mean results are expected to be lower than actual measurements
tgrosch 0:62b846b3988a 751
tgrosch 0:62b846b3988a 752 }
tgrosch 0:62b846b3988a 753
tgrosch 0:62b846b3988a 754 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 755 std::ostream & OPT3101::operator<<(std::ostream & os, const OPT3101::frameData * data)
tgrosch 0:62b846b3988a 756 {
tgrosch 0:62b846b3988a 757 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 758 os << data->phase << '\n'; ///* Serializes all the members and returns to the stream
tgrosch 0:62b846b3988a 759 os << data->phaseovl << '\n';
tgrosch 0:62b846b3988a 760 os << data->phaseovlf2 << '\n';
tgrosch 0:62b846b3988a 761 os << data->ambovl << '\n';
tgrosch 0:62b846b3988a 762 os << data->illumDac << '\n';
tgrosch 0:62b846b3988a 763 os << data->ledChannel << '\n';
tgrosch 0:62b846b3988a 764 os << data->frameStatus << '\n';
tgrosch 0:62b846b3988a 765 os << data->dealiasFreq << '\n';
tgrosch 0:62b846b3988a 766 os << data->frameCounter << '\n';
tgrosch 0:62b846b3988a 767 os << data->amplitude << '\n';
tgrosch 0:62b846b3988a 768 os << data->sigovl << '\n';
tgrosch 0:62b846b3988a 769 os << data->dealiasBin << '\n';
tgrosch 0:62b846b3988a 770 os << data->temp << '\n';
tgrosch 0:62b846b3988a 771 os << data->tmain << '\n';
tgrosch 0:62b846b3988a 772 os << data->tillum << '\n';
tgrosch 0:62b846b3988a 773 return os;
tgrosch 0:62b846b3988a 774 }
tgrosch 0:62b846b3988a 775 #endif
tgrosch 0:62b846b3988a 776
tgrosch 0:62b846b3988a 777 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 778 std::istream & OPT3101::operator>>(std::istream & is, OPT3101::frameData * data)
tgrosch 0:62b846b3988a 779 {
tgrosch 0:62b846b3988a 780 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 781 is >> data->phase; ///* Serializes all the members and returns to the stream
tgrosch 0:62b846b3988a 782 is >> data->phaseovl;
tgrosch 0:62b846b3988a 783 is >> data->phaseovlf2;
tgrosch 0:62b846b3988a 784 is >> data->ambovl;
tgrosch 0:62b846b3988a 785 is >> data->illumDac;
tgrosch 0:62b846b3988a 786 is >> data->ledChannel;
tgrosch 0:62b846b3988a 787 is >> data->frameStatus;
tgrosch 0:62b846b3988a 788 is >> data->dealiasFreq;
tgrosch 0:62b846b3988a 789 is >> data->frameCounter;
tgrosch 0:62b846b3988a 790 is >> data->amplitude;
tgrosch 0:62b846b3988a 791 is >> data->sigovl;
tgrosch 0:62b846b3988a 792 is >> data->dealiasBin;
tgrosch 0:62b846b3988a 793 is >> data->temp;
tgrosch 0:62b846b3988a 794 is >> data->tmain;
tgrosch 0:62b846b3988a 795 is >> data->tillum;
tgrosch 0:62b846b3988a 796
tgrosch 0:62b846b3988a 797 return is;
tgrosch 0:62b846b3988a 798
tgrosch 0:62b846b3988a 799 }
tgrosch 0:62b846b3988a 800 #endif
tgrosch 0:62b846b3988a 801
tgrosch 0:62b846b3988a 802 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 803 void OPT3101::frameData::storeToFile(char * fileName)
tgrosch 0:62b846b3988a 804 {
tgrosch 0:62b846b3988a 805 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 806 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 807 std::ofstream ofs(fileName);
tgrosch 0:62b846b3988a 808 ofs << this;
tgrosch 0:62b846b3988a 809 ofs.close(); ///* User needs to implement file storage based on host.
tgrosch 0:62b846b3988a 810 #endif
tgrosch 0:62b846b3988a 811 }
tgrosch 0:62b846b3988a 812 #endif
tgrosch 0:62b846b3988a 813
tgrosch 0:62b846b3988a 814 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 815 void OPT3101::frameData::loadFromFile(char * fileName)
tgrosch 0:62b846b3988a 816 {
tgrosch 0:62b846b3988a 817 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 818 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 819 std::ifstream ifs(fileName);
tgrosch 0:62b846b3988a 820 ifs >> this;
tgrosch 0:62b846b3988a 821 ifs.close(); ///* User needs to implement file load/restore based on host.
tgrosch 0:62b846b3988a 822 #endif
tgrosch 0:62b846b3988a 823 }
tgrosch 0:62b846b3988a 824 #endif
tgrosch 0:62b846b3988a 825
tgrosch 0:62b846b3988a 826 void OPT3101::device::measurePhaseOffsetSet(bool saveToFile) {
tgrosch 0:62b846b3988a 827 uint8_t c0, c1;
tgrosch 0:62b846b3988a 828 uint16_t flashLocation;
tgrosch 0:62b846b3988a 829 uint16_t refDistanceInCodes;
tgrosch 0:62b846b3988a 830 uint32_t refDistanceInMM;
tgrosch 0:62b846b3988a 831
tgrosch 0:62b846b3988a 832 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 833 char fileName[FILENAME_LENGTH];
tgrosch 0:62b846b3988a 834 #endif
tgrosch 0:62b846b3988a 835
tgrosch 0:62b846b3988a 836 envController.manuallySetReferenceDistances();
tgrosch 0:62b846b3988a 837
tgrosch 0:62b846b3988a 838 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 839 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 840 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 841 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 842 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 843 refDistanceInMM=envController.refDistancesInMM[c0][c1];
tgrosch 0:62b846b3988a 844 envController.setTargetDistance(refDistanceInMM); ///* Calls environmentalController::setTargetDistance method with the specified distance
tgrosch 0:62b846b3988a 845 refDistanceInCodes = (refDistanceInMM * 4477) >> 10; ///* Converts the reference distance specified in codes related to OPT3101::frameData::phase ADC codes
tgrosch 0:62b846b3988a 846 host.printf("INFO:Performing Phase Offset for TX%d HDR %d @ ref Distance %dmm\r\n",c0,c1,refDistanceInMM);
tgrosch 0:62b846b3988a 847 this->measurePhaseOffset(&this->calibration->phaseOffset[c0][c1], c0, c1 ? 'h' : 'l', refDistanceInCodes); ///* Measures phase offset by calling method OPT3101::device::measurePhaseOffset with specified reference distance and OPT3101::calibrationC::phaseOffset as argument to store the phase offset values
tgrosch 0:62b846b3988a 848 this->calibration->phaseOffset[c0][c1].printHeader();
tgrosch 0:62b846b3988a 849 this->calibration->phaseOffset[c0][c1].print();
tgrosch 0:62b846b3988a 850 host.printf("\r\n");
tgrosch 0:62b846b3988a 851
tgrosch 0:62b846b3988a 852 if(saveToFile){
tgrosch 0:62b846b3988a 853 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 854 sprintf(fileName, "%s/phaseOffset_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l'); ///* Creates filename illumCrosstalk_TX{channel}_{h/l}.txt in path filePath
tgrosch 0:62b846b3988a 855 this->calibration->phaseOffset[c0][c1].storeToFile(fileName); ///* Calls method OPT3101::crosstalkC::storeToFile to store the data
tgrosch 0:62b846b3988a 856 #endif
tgrosch 0:62b846b3988a 857 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 858 flashLocation=96+36*((c0<<1)+c1);
tgrosch 0:62b846b3988a 859 // TODO fix this flash host.flash.write(flashLocation, (uint8_t*)&this->calibration->phaseOffset[c0][c1] ,36);
tgrosch 0:62b846b3988a 860 host.printf("INFO:Writing Phase Offset for TX%d HDR %d to Flash location 0x%04x\r\n",c0,c1,flashLocation);
tgrosch 0:62b846b3988a 861 #endif // TIHOST
tgrosch 0:62b846b3988a 862 }
tgrosch 0:62b846b3988a 863 }
tgrosch 0:62b846b3988a 864 }
tgrosch 0:62b846b3988a 865 }
tgrosch 0:62b846b3988a 866 }
tgrosch 0:62b846b3988a 867
tgrosch 0:62b846b3988a 868 }
tgrosch 0:62b846b3988a 869
tgrosch 0:62b846b3988a 870
tgrosch 0:62b846b3988a 871 void OPT3101::device::measurePhaseOffset(OPT3101::phaseOffsetC *phaseOffset,uint16_t refDistanceInCodes) {
tgrosch 0:62b846b3988a 872 OPT3101::frameData data[32], meanData;
tgrosch 0:62b846b3988a 873 uint16_t nFrames;
tgrosch 0:62b846b3988a 874 int32_t phaseOffsetRegister;
tgrosch 0:62b846b3988a 875 uint16_t c0;
tgrosch 0:62b846b3988a 876 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 877 nFrames = 1 << (this->configurationFlags_avgFrameCountExponentOfTwo <= 5 ? 5 - this->configurationFlags_avgFrameCountExponentOfTwo : 0); ///* Calculates number of frames to average the data. Based on the OPT3101::device::configurationFlags_avgFrameCountExponentOfTwo number of average is decided. More frames are captured and averaged if device configuration has low average frames and vice versa
tgrosch 0:62b846b3988a 878 //data = new OPT3101::frameData[nFrames];
tgrosch 0:62b846b3988a 879 for (c0 = 0; c0<nFrames; c0++)
tgrosch 0:62b846b3988a 880 data[c0].capture(&host, this); ///* Captures all calculated number of frames from the h/w using OPT3101::frameData::capture method
tgrosch 0:62b846b3988a 881
tgrosch 0:62b846b3988a 882 meanData.populateWithMean(&data[0], nFrames); ///* Measures the mean of the captured frames OPT3101::frameData::populateWithMean method
tgrosch 0:62b846b3988a 883 phaseOffsetRegister = (int32_t) (meanData.phase - refDistanceInCodes); ///* Calculates the actual phase offset register value based on the input argument refDistanceInCodes and measured phase OPT3101::frameData::phase (mean over captured frames)
tgrosch 0:62b846b3988a 884 phaseOffset->freqCount = this->reg.freq_count_read_reg.read(); ///* Captures snapshot of register value OPT3101::registers::freq_count_read_reg and assigns to input argument phaseOffset's OPT3101::phaseOffsetC::freqCount
tgrosch 0:62b846b3988a 885 if (phaseOffset->freqCount > 0)
tgrosch 0:62b846b3988a 886 phaseOffsetRegister = (int32_t)((phaseOffsetRegister * 16384) / phaseOffset->freqCount); ///* Scales phase offset value with OPT3101::phaseOffsetC::freqCount value
tgrosch 0:62b846b3988a 887 else
tgrosch 0:62b846b3988a 888 phaseOffsetRegister = 0;
tgrosch 0:62b846b3988a 889
tgrosch 0:62b846b3988a 890 phaseOffset->phaseOffset = (uint16_t)(phaseOffsetRegister & 0xFFFF); ///* Assigns input argument phaseOffset's OPT3101::phaseOffsetC::phaseOffset with scaled register value
tgrosch 0:62b846b3988a 891
tgrosch 0:62b846b3988a 892 phaseOffset->data = meanData; ///* Captures the calculated mean OPT3101::frameData to OPT3101::phaseOffsetC::data
tgrosch 0:62b846b3988a 893 phaseOffset->referenceDistanceInCodes = refDistanceInCodes; ///* Captures the snapshot of input argument refDistanceInCodes to the input argument phaseOffset's OPT3101::phaseOffsetC::referenceDistanceInCodes
tgrosch 0:62b846b3988a 894 }
tgrosch 0:62b846b3988a 895
tgrosch 0:62b846b3988a 896 void OPT3101::device::measurePhaseOffset(OPT3101::phaseOffsetC *phaseOffset, uint8_t txChannel, char registerSet, uint16_t refDistanceInCodes,uint8_t shiftIllumPhase) {
tgrosch 0:62b846b3988a 897 uint8_t regStore[14];
tgrosch 0:62b846b3988a 898 uint8_t dummy;
tgrosch 0:62b846b3988a 899
tgrosch 0:62b846b3988a 900 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 901 regStore[0] = this->reg.en_sequencer.read();
tgrosch 0:62b846b3988a 902 regStore[1] = this->reg.en_processor_values.read();
tgrosch 0:62b846b3988a 903 regStore[2] = this->reg.sel_hdr_mode.read();
tgrosch 0:62b846b3988a 904 regStore[3] = this->reg.sel_tx_ch.read();
tgrosch 0:62b846b3988a 905 regStore[4] = this->reg.en_adaptive_hdr.read();
tgrosch 0:62b846b3988a 906 regStore[5] = this->reg.en_tx_switch.read();
tgrosch 0:62b846b3988a 907 regStore[6] = this->reg.en_phase_corr.read();
tgrosch 0:62b846b3988a 908 regStore[7] = this->reg.en_nl_corr.read();
tgrosch 0:62b846b3988a 909 regStore[8] = this->reg.en_temp_corr.read();
tgrosch 0:62b846b3988a 910 regStore[9] = this->reg.amb_phase_corr_pwl_coeff0.read();
tgrosch 0:62b846b3988a 911 regStore[10] = this->reg.amb_phase_corr_pwl_coeff1.read();
tgrosch 0:62b846b3988a 912 regStore[11] = this->reg.amb_phase_corr_pwl_coeff2.read();
tgrosch 0:62b846b3988a 913 regStore[12] = this->reg.amb_phase_corr_pwl_coeff3.read();
tgrosch 0:62b846b3988a 914 regStore[13] = this->reg.shift_illum_phase.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily buffered to local variables.
tgrosch 0:62b846b3988a 915
tgrosch 0:62b846b3988a 916
tgrosch 0:62b846b3988a 917 this->reg.tg_en = 0;
tgrosch 0:62b846b3988a 918 this->reg.en_sequencer = 0;
tgrosch 0:62b846b3988a 919 this->reg.en_processor_values = 0;
tgrosch 0:62b846b3988a 920 if (registerSet == 'h')
tgrosch 0:62b846b3988a 921 this->reg.sel_hdr_mode = 1; ///* Register set is chosen based on registerSet input to this method by setting OPT3101::registers::sel_hdr_mode
tgrosch 0:62b846b3988a 922 if (registerSet == 'l')
tgrosch 0:62b846b3988a 923 this->reg.sel_hdr_mode = 0;
tgrosch 0:62b846b3988a 924 this->reg.sel_tx_ch = txChannel; ///* TX channel is chosen based on txChannel input to this method by setting OPT3101::registers::sel_tx_ch
tgrosch 0:62b846b3988a 925 this->reg.en_tx_switch = 0;
tgrosch 0:62b846b3988a 926 this->reg.en_adaptive_hdr = 0;
tgrosch 0:62b846b3988a 927 this->reg.en_phase_corr = 0;
tgrosch 0:62b846b3988a 928 this->reg.en_nl_corr = 0;
tgrosch 0:62b846b3988a 929 this->reg.en_temp_corr = 0;
tgrosch 0:62b846b3988a 930 this->reg.amb_phase_corr_pwl_coeff0 = 0;
tgrosch 0:62b846b3988a 931 this->reg.amb_phase_corr_pwl_coeff1 = 0;
tgrosch 0:62b846b3988a 932 this->reg.amb_phase_corr_pwl_coeff2 = 0;
tgrosch 0:62b846b3988a 933 this->reg.amb_phase_corr_pwl_coeff3 = 0;
tgrosch 0:62b846b3988a 934 this->reg.shift_illum_phase = shiftIllumPhase; ///* Sets up the OPT3101::registers::shift_illum_phase based on the input to this method shiftIllumPhase
tgrosch 0:62b846b3988a 935 this->reg.tg_en = 1;
tgrosch 0:62b846b3988a 936
tgrosch 0:62b846b3988a 937 this->measurePhaseOffset(phaseOffset, refDistanceInCodes); ///* Measures phase offset with following steps
tgrosch 0:62b846b3988a 938 // Added dummy lines so that Doxygen can recognize these multi-line comments
tgrosch 0:62b846b3988a 939 dummy = 0; ///* Calculates number of frames to average the data. Based on the OPT3101::device::configurationFlags_avgFrameCountExponentOfTwo number of average is decided. More frames are captured and averaged if device configuration has low average frames and vice versa
tgrosch 0:62b846b3988a 940 dummy = 0; ///* Captures all calculated number of frames from the h/w using OPT3101::frameData::capture method
tgrosch 0:62b846b3988a 941 dummy = 0; ///* Measures the mean of the captured frames OPT3101::frameData::populateWithMean method
tgrosch 0:62b846b3988a 942 dummy = 0; ///* Calculates the actual phase offset register value based on the input argument refDistanceInCodes and measured phase OPT3101::frameData::phase (mean over captured frames)
tgrosch 0:62b846b3988a 943 dummy = 0; ///* Captures snapshot of register value OPT3101::registers::freq_count_read_reg and assigns to input argument phaseOffset's OPT3101::phaseOffsetC::freqCount
tgrosch 0:62b846b3988a 944 dummy = 0; ///* Scales phase offset value with OPT3101::phaseOffsetC::freqCount value
tgrosch 0:62b846b3988a 945 dummy = 0; ///* Assigns input argument phaseOffset's OPT3101::phaseOffsetC::phaseOffset with scaled register value
tgrosch 0:62b846b3988a 946 dummy = 0; ///* Captures the calculated mean OPT3101::frameData to OPT3101::phaseOffsetC::data
tgrosch 0:62b846b3988a 947 dummy = 0; ///* Captures the snapshot of input argument refDistanceInCodes to the input argument phaseOffset's OPT3101::phaseOffsetC::referenceDistanceInCodes
tgrosch 0:62b846b3988a 948
tgrosch 0:62b846b3988a 949 phaseOffset->shiftIllumPhase = shiftIllumPhase;
tgrosch 0:62b846b3988a 950 phaseOffset->illumDCdac = this->reg.ILLUM_DC_CURR_DAC.read();
tgrosch 0:62b846b3988a 951 switch (txChannel) { ///* Captures the snapshot of the illum dac, illum DC and illum scale settings form h/w to the phaseOffset input argument
tgrosch 0:62b846b3988a 952 case 0:
tgrosch 0:62b846b3988a 953 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 954 phaseOffset->illumDac = this->reg.illum_dac_h_tx0.read();
tgrosch 0:62b846b3988a 955 phaseOffset->illumScale = this->reg.illum_scale_h_tx0.read();
tgrosch 0:62b846b3988a 956 }
tgrosch 0:62b846b3988a 957 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 958 phaseOffset->illumDac = this->reg.illum_dac_l_tx0.read();
tgrosch 0:62b846b3988a 959 phaseOffset->illumScale = this->reg.illum_scale_l_tx0.read();
tgrosch 0:62b846b3988a 960 }
tgrosch 0:62b846b3988a 961 break;
tgrosch 0:62b846b3988a 962 case 1:
tgrosch 0:62b846b3988a 963 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 964 phaseOffset->illumDac = this->reg.illum_dac_h_tx1.read();
tgrosch 0:62b846b3988a 965 phaseOffset->illumScale = this->reg.illum_scale_h_tx1.read();
tgrosch 0:62b846b3988a 966 }
tgrosch 0:62b846b3988a 967 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 968 phaseOffset->illumDac = this->reg.illum_dac_l_tx1.read();
tgrosch 0:62b846b3988a 969 phaseOffset->illumScale = this->reg.illum_scale_l_tx1.read();
tgrosch 0:62b846b3988a 970 }
tgrosch 0:62b846b3988a 971 break;
tgrosch 0:62b846b3988a 972 case 2:
tgrosch 0:62b846b3988a 973 if (registerSet == 'h') {
tgrosch 0:62b846b3988a 974 phaseOffset->illumDac = this->reg.illum_dac_h_tx2.read();
tgrosch 0:62b846b3988a 975 phaseOffset->illumScale = this->reg.illum_scale_h_tx2.read();
tgrosch 0:62b846b3988a 976 }
tgrosch 0:62b846b3988a 977 else if (registerSet == 'l') {
tgrosch 0:62b846b3988a 978 phaseOffset->illumDac = this->reg.illum_dac_l_tx2.read();
tgrosch 0:62b846b3988a 979 phaseOffset->illumScale = this->reg.illum_scale_l_tx2.read();
tgrosch 0:62b846b3988a 980 }
tgrosch 0:62b846b3988a 981 break;
tgrosch 0:62b846b3988a 982 default:
tgrosch 0:62b846b3988a 983 break;
tgrosch 0:62b846b3988a 984 }
tgrosch 0:62b846b3988a 985
tgrosch 0:62b846b3988a 986 this->reg.tg_en = 0;
tgrosch 0:62b846b3988a 987 this->reg.en_sequencer = regStore[0];
tgrosch 0:62b846b3988a 988 this->reg.en_processor_values = regStore[1];
tgrosch 0:62b846b3988a 989 this->reg.sel_hdr_mode = regStore[2];
tgrosch 0:62b846b3988a 990 this->reg.sel_tx_ch = regStore[3];
tgrosch 0:62b846b3988a 991 this->reg.en_adaptive_hdr = regStore[4];
tgrosch 0:62b846b3988a 992 this->reg.en_tx_switch = regStore[5];
tgrosch 0:62b846b3988a 993 this->reg.en_phase_corr = regStore[6];
tgrosch 0:62b846b3988a 994 this->reg.en_nl_corr = regStore[7];
tgrosch 0:62b846b3988a 995 this->reg.en_temp_corr = regStore[8];
tgrosch 0:62b846b3988a 996 this->reg.amb_phase_corr_pwl_coeff0 = regStore[9];
tgrosch 0:62b846b3988a 997 this->reg.amb_phase_corr_pwl_coeff1 = regStore[10];
tgrosch 0:62b846b3988a 998 this->reg.amb_phase_corr_pwl_coeff2 = regStore[11];
tgrosch 0:62b846b3988a 999 this->reg.amb_phase_corr_pwl_coeff3 = regStore[12];
tgrosch 0:62b846b3988a 1000 this->reg.shift_illum_phase = regStore[13]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
tgrosch 0:62b846b3988a 1001 this->reg.tg_en = 1;
tgrosch 0:62b846b3988a 1002
tgrosch 0:62b846b3988a 1003 }
tgrosch 0:62b846b3988a 1004
tgrosch 0:62b846b3988a 1005 void OPT3101::device::writeDataToEEPROM(uint8_t location, uint8_t data) {
tgrosch 0:62b846b3988a 1006 this->reg.i2c_write_data1 = location;
tgrosch 0:62b846b3988a 1007 this->reg.i2c_write_data2 = data;
tgrosch 0:62b846b3988a 1008 this->reg.i2c_trig_reg = 1;
tgrosch 0:62b846b3988a 1009 host.sleep(1); ///* Added delay to initiate an I2C write transaction
tgrosch 0:62b846b3988a 1010 this->reg.i2c_trig_reg = 0;
tgrosch 0:62b846b3988a 1011 host.sleep(1); ///* Added delay to initiate an I2C write transaction
tgrosch 0:62b846b3988a 1012 }
tgrosch 0:62b846b3988a 1013
tgrosch 0:62b846b3988a 1014 uint8_t OPT3101::device::readDataFromEEPROM(uint8_t location) {
tgrosch 0:62b846b3988a 1015 /* Will be updated in future revision of the SDK
tgrosch 0:62b846b3988a 1016 this->reg.i2c_write_data1 = location;
tgrosch 0:62b846b3988a 1017 this->reg.i2c_trig_reg = 1;
tgrosch 0:62b846b3988a 1018 host.sleep(50); ///* Added delay to initiate an I2C write transaction
tgrosch 0:62b846b3988a 1019 this->reg.i2c_trig_reg = 0;
tgrosch 0:62b846b3988a 1020 host.sleep(50); ///* Added delay to initiate an I2C write transaction
tgrosch 0:62b846b3988a 1021 return ((uint8_t) (this->reg.i2c_read_data.read()&0xFF));
tgrosch 0:62b846b3988a 1022 */
tgrosch 0:62b846b3988a 1023 return 0x00;
tgrosch 0:62b846b3988a 1024 }
tgrosch 0:62b846b3988a 1025
tgrosch 0:62b846b3988a 1026 void OPT3101::device::loadIllumCrosstalkSet(bool loadFromFile)
tgrosch 0:62b846b3988a 1027 {
tgrosch 0:62b846b3988a 1028 uint8_t c0, c1;
tgrosch 0:62b846b3988a 1029 uint16_t flashLocation;
tgrosch 0:62b846b3988a 1030 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 1031 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 1032 char fileName[FILENAME_LENGTH];
tgrosch 0:62b846b3988a 1033 #endif
tgrosch 0:62b846b3988a 1034 host.printf("INFO::Loading Illumination cross talk Set\r\n");
tgrosch 0:62b846b3988a 1035
tgrosch 0:62b846b3988a 1036 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 1037 if(loadFromFile){ ///* Checks if input argument loadFromFile is true. If true proceeds to load files in to OPT3101::device::calibration
tgrosch 0:62b846b3988a 1038 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 1039 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 1040 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 1041 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 1042 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 1043 sprintf(fileName, "%s/illumCrosstalk_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l');
tgrosch 0:62b846b3988a 1044 this->calibration->illumCrosstalk[c0][c1].loadFromFile(fileName); ///* Calls method OPT3101::crosstalkC::loadFromFile to load data from non-volatile memory to all the OPT3101::device::calibration::illumCrosstalk members
tgrosch 0:62b846b3988a 1045 #endif
tgrosch 0:62b846b3988a 1046 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 1047 flashLocation=(c1+(c0<<1))<<4;
tgrosch 0:62b846b3988a 1048 // TODO fix this host.flash.read(flashLocation, (uint8_t*)&this->calibration->illumCrosstalk[c0][c1] ,16);
tgrosch 0:62b846b3988a 1049 host.printf("INFO:Reading Illum Cross talk from Flash location 0x%04x\r\n",flashLocation);
tgrosch 0:62b846b3988a 1050 #endif
tgrosch 0:62b846b3988a 1051 this->calibration->illumCrosstalk[c0][c1].printHeader();
tgrosch 0:62b846b3988a 1052 this->calibration->illumCrosstalk[c0][c1].print();
tgrosch 0:62b846b3988a 1053 host.printf("\r\n");
tgrosch 0:62b846b3988a 1054
tgrosch 0:62b846b3988a 1055 }
tgrosch 0:62b846b3988a 1056 }
tgrosch 0:62b846b3988a 1057 }
tgrosch 0:62b846b3988a 1058 }
tgrosch 0:62b846b3988a 1059 }
tgrosch 0:62b846b3988a 1060
tgrosch 0:62b846b3988a 1061 this->calibration->findCommonCrosstalkScale(&this->calibration->illumCrosstalk[0][0], this->configurationFlags_isTXChannelActive,this->configurationFlags_isTXChannelActive); ///* Finds common crosstalk scale for the illum Crosstalk values captured in OPT3101::device::calibrationC using method OPT3101::calibrationC::findCommonCrosstalkScale
tgrosch 0:62b846b3988a 1062 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 1063 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 1064 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 1065 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 1066 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 1067 this->loadIllumCrosstalk(&this->calibration->illumCrosstalk[c0][c1], c0, c1 ? 'h' : 'l'); ///* Loads all the illum crosstalk corresponding to TX and register set configurations to the device from the OPT3101::device::calibrationC::illumCrosstalk member by calling OPT3101::device::loadIllumCrosstalk
tgrosch 0:62b846b3988a 1068 }
tgrosch 0:62b846b3988a 1069 }
tgrosch 0:62b846b3988a 1070 }
tgrosch 0:62b846b3988a 1071 }
tgrosch 0:62b846b3988a 1072
tgrosch 0:62b846b3988a 1073 void OPT3101::device::loadPhaseOffsetSet(bool loadFromFile)
tgrosch 0:62b846b3988a 1074 {
tgrosch 0:62b846b3988a 1075 uint8_t c0, c1;
tgrosch 0:62b846b3988a 1076 uint16_t flashLocation;
tgrosch 0:62b846b3988a 1077 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 1078 char fileName[FILENAME_LENGTH];
tgrosch 0:62b846b3988a 1079 #endif
tgrosch 0:62b846b3988a 1080 host.printf("INFO::Loading Phase Offset Set\r\n");
tgrosch 0:62b846b3988a 1081
tgrosch 0:62b846b3988a 1082 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 1083 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 1084
tgrosch 0:62b846b3988a 1085 if(loadFromFile){
tgrosch 0:62b846b3988a 1086 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 1087 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 1088 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 1089 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 1090 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 1091 sprintf(fileName, "%s/phaseOffset_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l'); ///* Creates filename illumCrosstalk_TX{channel}_{h/l}.txt in path filePath
tgrosch 0:62b846b3988a 1092 this->calibration->phaseOffset[c0][c1].loadFromFile(fileName); ///* Calls method OPT3101::crosstalkC::loadFromFile to store the data
tgrosch 0:62b846b3988a 1093 #endif
tgrosch 0:62b846b3988a 1094 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
tgrosch 0:62b846b3988a 1095 flashLocation = 96 + 36 * ((c0 << 1) + c1);
tgrosch 0:62b846b3988a 1096 // TODo Fix this host.flash.read(flashLocation, (uint8_t*)&this->calibration->phaseOffset[c0][c1], 36);
tgrosch 0:62b846b3988a 1097 host.printf("INFO:Reading Phase Offset from TX%d HDR %d to Flash location 0x%04x\r\n", c0, c1, flashLocation);
tgrosch 0:62b846b3988a 1098 #endif // TIHOST
tgrosch 0:62b846b3988a 1099 this->calibration->phaseOffset[c0][c1].printHeader();
tgrosch 0:62b846b3988a 1100 this->calibration->phaseOffset[c0][c1].print();
tgrosch 0:62b846b3988a 1101 host.printf("\r\n");
tgrosch 0:62b846b3988a 1102 }
tgrosch 0:62b846b3988a 1103 }
tgrosch 0:62b846b3988a 1104 }
tgrosch 0:62b846b3988a 1105 }
tgrosch 0:62b846b3988a 1106 }
tgrosch 0:62b846b3988a 1107
tgrosch 0:62b846b3988a 1108 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 1109 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 1110 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 1111 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 1112 this->loadPhaseOffset(&this->calibration->phaseOffset[c0][c1], c0, c1 ? 'h' : 'l'); ///* Loads all the phase offset corresponding to TX and register set configurations to the device from the OPT3101::device::calibrationC::phaseOffset member by calling OPT3101::device::loadPhaseOffset
tgrosch 0:62b846b3988a 1113 }
tgrosch 0:62b846b3988a 1114 }
tgrosch 0:62b846b3988a 1115 }
tgrosch 0:62b846b3988a 1116 }
tgrosch 0:62b846b3988a 1117
tgrosch 0:62b846b3988a 1118 uint8_t OPT3101::device::determineConfigCount() {
tgrosch 0:62b846b3988a 1119 return this->calibration->recordLength;
tgrosch 0:62b846b3988a 1120 }
tgrosch 0:62b846b3988a 1121
tgrosch 0:62b846b3988a 1122 void OPT3101::device::loadIllumCrosstalkTempCoffSet()
tgrosch 0:62b846b3988a 1123 {
tgrosch 0:62b846b3988a 1124 uint8_t c0, c1;
tgrosch 0:62b846b3988a 1125
tgrosch 0:62b846b3988a 1126 host.printf("INFO::Loading Illumination crosstalk Temperature Coefficient Set\r\n");
tgrosch 0:62b846b3988a 1127 this->loadIllumCrosstalkSet(true); ///* Calls OPT3101::device::loadIllumCrosstalkSet with the same loafFromFile flag specified to this method
tgrosch 0:62b846b3988a 1128 this->calibration->findCrosstalkTempRegisterValues(&this->calibration->illumCrosstalkTempCoff[0][0], this->configurationFlags_isTXChannelActive,this->configurationFlags_isTXChannelActive, &this->calibration->illumCrosstalk[0][0]); ///* Calls OPT3101::calibrationC::findCrosstalkTempRegisterValues based on the members from OPT3101::calibrationC class OPT3101::calibrationC::illumCrosstalkTempCoff and OPT3101::calibrationC::illumCrosstalk
tgrosch 0:62b846b3988a 1129 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 1130 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 1131 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 1132 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 1133 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 1134 this->loadIllumCrosstalkTempCoff(&this->calibration->illumCrosstalkTempCoff[c0][c1], c0, c1 ? 'h' : 'l'); ///* Calls the method OPT3101::device::loadIllumCrosstalkTempCoff to load all the crosstalk temp coff values from the OPT3101::calibrationC::illumCrosstalkTempCoff member
tgrosch 0:62b846b3988a 1135 }
tgrosch 0:62b846b3988a 1136 }
tgrosch 0:62b846b3988a 1137 }
tgrosch 0:62b846b3988a 1138 this->reg.en_temp_xtalk_corr=1;
tgrosch 0:62b846b3988a 1139 }
tgrosch 0:62b846b3988a 1140
tgrosch 0:62b846b3988a 1141 void OPT3101::device::loadPhaseOffsetTempCoffSet() {
tgrosch 0:62b846b3988a 1142 uint8_t c0, c1;
tgrosch 0:62b846b3988a 1143
tgrosch 0:62b846b3988a 1144 host.printf("INFO::Loading Phase Temperature coefficient Set\r\n");
tgrosch 0:62b846b3988a 1145 this->calibration->findPhaseTempRegisterValues(&this->calibration->phaseTempCoff[0][0], this->configurationFlags_isTXChannelActive,this->configurationFlags_isTXChannelActive, this->reg.freq_count_read_reg.read()); ///* Calls OPT3101::calibrationC::findPhaseTempRegisterValues based on the members from OPT3101::calibrationC class OPT3101::calibrationC::phaseTempCoff and current device register OPT3101::registers::freq_count_read_reg
tgrosch 0:62b846b3988a 1146
tgrosch 0:62b846b3988a 1147 // Loop to iterate over all TX channels
tgrosch 0:62b846b3988a 1148 for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
tgrosch 0:62b846b3988a 1149 if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
tgrosch 0:62b846b3988a 1150 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
tgrosch 0:62b846b3988a 1151 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
tgrosch 0:62b846b3988a 1152 this->loadPhaseOffsetTempCoff(&this->calibration->phaseTempCoff[c0][c1], c0, c1 ? 'h' : 'l'); ///* Calls the method OPT3101::device::loadPhaseOffsetTempCoff to load all the phase temp coff values from the OPT3101::calibrationC::phaseTempCoff member
tgrosch 0:62b846b3988a 1153 }
tgrosch 0:62b846b3988a 1154 }
tgrosch 0:62b846b3988a 1155 }
tgrosch 0:62b846b3988a 1156 }
tgrosch 0:62b846b3988a 1157
tgrosch 0:62b846b3988a 1158 void OPT3101::device::loadPhaseAmbientCoffSet()
tgrosch 0:62b846b3988a 1159 {
tgrosch 0:62b846b3988a 1160 host.printf("INFO::Loading Phase Ambient Coefficient Set\r\n");
tgrosch 0:62b846b3988a 1161 this->calibration->phaseAmbientCoff[0].calculateCoff(this->reg.freq_count_read_reg.read()); ///* Calculates the phase ambient coff by calling method OPT3101::phaseAmbientCoffC::calculateCoff also passing argument of device register OPT3101::registers::freq_count_read_reg
tgrosch 0:62b846b3988a 1162 this->loadPhaseAmbientCoff(&this->calibration->phaseAmbientCoff[0]); ///* Calls method OPT3101::device::loadPhaseAmbientCoff to load ambient coff to device from OPT3101::calibrationC::phaseAmbientCoff member
tgrosch 0:62b846b3988a 1163 }
tgrosch 0:62b846b3988a 1164
tgrosch 0:62b846b3988a 1165 void OPT3101::calibrationC::findCommonCrosstalkScale(OPT3101::crosstalkC* illumXtalk, bool *txActiveList,bool *registerSetActiveList) {
tgrosch 0:62b846b3988a 1166 uint8_t maxScale, c0,c1;
tgrosch 0:62b846b3988a 1167 maxScale = 0;
tgrosch 0:62b846b3988a 1168 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 1169 for (c0 = 0; c0 < 3; c0++) {
tgrosch 0:62b846b3988a 1170 for (c1 = 0; c1 < 2; c1++){
tgrosch 0:62b846b3988a 1171 if(txActiveList[c0] && registerSetActiveList[c1])
tgrosch 0:62b846b3988a 1172 maxScale = illumXtalk[(c0<<1)+c1].xtalkScale > maxScale ? illumXtalk[(c0<<1)+c1].xtalkScale : maxScale; ///* Finds the largest scale what will fit all the input OPT3101::crosstalkC arguments
tgrosch 0:62b846b3988a 1173 }
tgrosch 0:62b846b3988a 1174 }
tgrosch 0:62b846b3988a 1175 for (c0 = 0; c0 < 3; c0++) {
tgrosch 0:62b846b3988a 1176 for (c1 = 0; c1 < 2; c1++){
tgrosch 0:62b846b3988a 1177 if(txActiveList[c0] && registerSetActiveList[c1])
tgrosch 0:62b846b3988a 1178 illumXtalk[(c0<<1)+c1].commonScale = maxScale; ///* Assigns the identified maxScale to all the input argument illum Crosstalk pointers OPT3101::crosstalkC
tgrosch 0:62b846b3988a 1179 }
tgrosch 0:62b846b3988a 1180 }
tgrosch 0:62b846b3988a 1181 }
tgrosch 0:62b846b3988a 1182
tgrosch 0:62b846b3988a 1183 OPT3101::calibrationC::calibrationC(bool dummyFlag) {
tgrosch 0:62b846b3988a 1184 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 1185 ///* Allocates memory for OPT3101::calibrationC::internalCrosstalk size based on system configuration
tgrosch 0:62b846b3988a 1186 ///* Allocates memory for OPT3101::calibrationC::illumCrosstalk size based on system configuration
tgrosch 0:62b846b3988a 1187 ///* Allocates memory for OPT3101::calibrationC::phaseOffset size based on system configuration
tgrosch 0:62b846b3988a 1188 ///* Allocates memory for OPT3101::calibrationC::illumCrosstalkTempCoff size based on system configuration
tgrosch 0:62b846b3988a 1189 ///* Allocates memory for OPT3101::calibrationC::phaseTempCoff size based on system configuration
tgrosch 0:62b846b3988a 1190 ///* Allocates memory for OPT3101::calibrationC::phaseAmbientCoff size based on system configuration
tgrosch 0:62b846b3988a 1191 ///* Sets the member OPT3101::calibrationC::registerAddressListSize based on number of calibration registers requires
tgrosch 0:62b846b3988a 1192 ///* Allocates memory for OPT3101::calibrationC::registerAddressList based on OPT3101::calibrationC::registerAddressListSize
tgrosch 0:62b846b3988a 1193 ///* Sets up the flag OPT3101::calibrationC::EEPROM_connected based on configuration
tgrosch 0:62b846b3988a 1194 ///* Sets up the flag OPT3101::calibrationC::extTempSensor_connected based on configuration
tgrosch 0:62b846b3988a 1195 }
tgrosch 0:62b846b3988a 1196