This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OPT3101EVM: OPT3101 init & read distance code/regs

Part Number: OPT3101EVM
Other Parts Discussed in Thread: OPT3101, , MSP-EXP430FR4133

Hi,

We have purchased couple of OPT3101 and want to use in our product for obstacle detection..

Could you please help to point code for initialize and reading the distance if I have two LEDs connected?

  • Hi Neeraj,

    I wanted to let you know that the device expert is out of the office on a business trip, he will be back in the office next week.

    Thanks in advance for your patience and understanding.

  • Hi Neerja,

    Did you purchase OPT3101EVM board or OPT3101 ICs?

    OPT3101EVM has all the calibration and initialization taken care of. If you ordered ICs and built a custom board you will need to run through the calibration process before getting useful data. Also the board layout mentioned in the system design doc is very important to get good results. The SDK, configurator tool, and how to calibrate doc will be most helpful for the calibration/initialization process.

    Please refer here for all our documentation including the collateral I mentioned above. 

    https://e2e.ti.com/support/sensors/f/1023/t/815766

    Best,

    Alex

  • Hi Alex,

    Thanks for your reply with detailed info.

    We had purchased evl and now made our own pcb with opt3101 ic with two sensors.

    So was looking to set minimum registers to get sensors working and get the distance.

  • Hi Alex,

    I am using below code to initialize, trigger, get measurement but somehow I am getting 0x8, 0x9 and 0xa all zeros.

    void OPT3101_initialize(OPT3101_DEV dev)
    {
        // SCL_M SDA_M floating, need set FORCE_EN_SLAVE to 1 to enable slave registers access for any address
        dev->reg_00.bit.force_en_slave = 1;         
        OPT3101_writeRegister(dev,0x00,dev->reg_00.all);
        
        // Overload Flag Observation window
        dev->reg_89.bit.tm_sig_4_start = 7000;
        OPT3101_writeRegister(dev,0x89,dev->reg_89.all);   
     
        // Enable Temperature Sensor
        dev->reg_6e.bit.en_temp_conv = 0;
        OPT3101_writeRegister(dev,0x6e,dev->reg_6e.all);

        dev->reg_50.bit.clip_mode_fc = 1;
        dev->reg_50.bit.clip_mode_temp = 0;    
        dev->reg_50.bit.clip_mode_offset = 0;
        OPT3101_writeRegister(dev,0x50,dev->reg_50.all);
        
        dev->reg_2e.bit.iq_read_data_sel = 3;
        OPT3101_writeRegister(dev,0x2e,dev->reg_2e.all);

        dev->reg_72.bit.iamb_max_sel = 12;
        OPT3101_writeRegister(dev,0x72,dev->reg_72.all);
        
        dev->reg_78.bit.gpio1_obuf_en = 1;
        dev->reg_78.bit.gpo1_mux_sel = 2;                   // select dig_gpo_0 on gpio1
        dev->reg_0b.bit.dig_gpo_sel0 = 9;                   // Select Data Ready on dig_gpo_0
        OPT3101_writeRegister(dev,0x78,dev->reg_78.all);
        OPT3101_writeRegister(dev,0x0b,dev->reg_0b.all);
       
        // HDR MODE
        dev->reg_2b.bit.hdr_thr_high = HDR_THRESHOLD_H;
        dev->reg_2c.bit.hdr_thr_low = HDR_THRESHOLD_L;
        dev->reg_2a.bit.en_adaptive_hdr = HDR_MODE;
        dev->reg_2a.bit.en_tx_switch = TX_CH_SWITCH;        // Signle channel or multi-channel
        dev->reg_2a.bit.sel_tx_ch = 0;
        dev->reg_2a.bit.tx_seq_reg = 0x924;                 // 2-1-0-2-1-0
        OPT3101_writeRegister(dev,0x2b,dev->reg_2b.all);
        OPT3101_writeRegister(dev,0x2c,dev->reg_2c.all);
        OPT3101_writeRegister(dev,0x2a,dev->reg_2a.all);

        // Configure Frame Rate
        dev->reg_27.bit.monoshot_mode = MEASUREMENT_MODE;   // 0: continous or monoshot mode
        dev->reg_27.bit.monoshot_numframe = 1;              // number of frames at every monoshot trigger
        dev->reg_9f.bit.num_sub_frames = NUM_AVG_FRAMES-1;
        dev->reg_9f.bit.num_avg_sub_frames = NUM_AVG_FRAMES-1;
        dev->reg_2e.bit.xtalk_filt_time_const = xtalkFilterTau;
        OPT3101_writeRegister(dev,0x27,dev->reg_27.all);
        OPT3101_writeRegister(dev,0x9f,dev->reg_9f.all);
        OPT3101_writeRegister(dev,0x2e,dev->reg_2e.all);

        // Enable continous frequency calibration
        dev->reg_78.bit.gpio2_obuf_en = 0;
        dev->reg_78.bit.gpio2_ibuf_en = 1;                  //GP1 for Ref clock input
        OPT3101_writeRegister(dev,0x78, dev->reg_78.all);
        
        dev->reg_0f.bit.ref_clk_divider = CLK_DIV;
        dev->reg_0f.bit.ref_count_limit = REF_COUNT_LIMIT;
        
        dev->reg_10.bit.en_cont_fcalib = 1;
        dev->reg_0f.bit.start_freq_calib = 1;
        dev->reg_0f.bit.en_floop = 1;
        dev->reg_0f.bit.en_auto_freq_count = 1;
        dev->reg_0f.bit.en_freq_corr = 0;
        OPT3101_writeRegister(dev,0x10, dev->reg_10.all);
        OPT3101_writeRegister(dev,0x0f, dev->reg_0f.all);
        
        dev->reg_80.bit.tg_en = 1;
        OPT3101_writeRegister(dev,0x80,dev->reg_80.all);   
    }

    void OPT3101_triggerSignleMeasurement(OPT3101_DEV dev, uint16_t delay)
    {
        if((delay < 0x100)&&(delay > 0x3ff6))
            delay = 0x100;

        dev->reg_26.bit.powerup_delay = delay;
        OPT3101_writeRegister(dev,0x26,dev->reg_26.all);

        dev->reg_00.bit.monoshot_bit = 1;
        OPT3101_writeRegister(dev,0x00,dev->reg_00.all);
    }

    void OPT3101_getMeasurementData(OPT3101_DEV dev, OPT_Ranging_Results *result)
    {
        OPT3101_readRegister(dev,0x08,&dev->reg_08.all);
        OPT3101_readRegister(dev,0x09,&dev->reg_09.all);
        OPT3101_readRegister(dev,0x0a,&dev->reg_0a.all);
          
        result->phase = dev->reg_08.bit.phase_out;
        result->amp = dev->reg_09.bit.amp_out;
        result->temp  = dev->reg_0a.bit.tmain/8-256;
        result->distance = (uint16_t)(result->phase*0.22872);
        result->txChannel = dev->reg_08.bit.tx_channel;
        result->ambient = dev->reg_0a.bit.amb_data;
        result->flags = (dev->reg_08.all >> 16)|((dev->reg_09.all & 0xFF0000)>> 8);
    }

    Could you please help me on this what is going wrong? I do not have temperature sensor mounted on board.

    I have already validated my read/write APIs.

    Thank You

    neeraj

  • Hi Alex,

    Further update on this...

    I can see values for phase and distance after modifying ( not setting) the values I am initializing.

    Currently problem is, I do not see distance values increasing or decreasing (it's reverse) and seems not linear.

    Could you please suggest anything?

    I want continuous mode (no her), where can I get details about.

    Thank you

    Neeraj

  • Hi Team,

    In order to debug more on why I get distance reducing when there is obstacle, I commented out init part and I have only below:

    dev->reg_00.bit.force_en_slave = 1;

    OPT3101_writeRegister(dev,0x00,dev->reg_00.all);

    dev->reg_2a.bit.en_tx_switch = TX_CH_SWITCH;        // Signle channel or multi-channel
    dev->reg_2a.bit.sel_tx_ch = 0;
    dev->reg_2a.bit.tx_seq_reg = 0x111;//0x924;                 // 2-1-0-2-1-0
    OPT3101_writeRegister(dev,0x2a,dev->reg_2a.all);
    dev->reg_27.bit.monoshot_mode = MONOSHOT_MODE;
    dev->reg_27.bit.monoshot_numframe = 1;              // number of frames at every monoshot trigger
    dev->reg_9f.bit.num_sub_frames = NUM_AVG_FRAMES-1;
    dev->reg_9f.bit.num_avg_sub_frames = NUM_AVG_FRAMES-1;
    OPT3101_writeRegister(dev,0x27,dev->reg_27.all);
    OPT3101_writeRegister(dev,0x9f,dev->reg_9f.all);

    dev->reg_80.bit.tg_en = 1;
    OPT3101_writeRegister(dev,0x80,dev->reg_80.all);

    it's giving values for phase and distance but values are not linear and distance value increases when object is near.

    I am stuck here.. could you please help..

  • Could you please help on this?

  • Hi Neeraj,

    The OPT3101EVM works out of the box because we have calibrated the board in production and the calibration gets loaded from the MCU flash. 

    It looks like your first issue from zeros in the data registers was an issue in initialization that you have resolved, correct? My next questions would be if you have taken care of the calibration for OPT3101. I mentioned this in my post above and we have a lot of documentation online in the link I mentioned in that post as well. I have also mentioned about the guidelines for board design/layout. Can you please confirm those points from my first post (calibration and board design)? Then I can try to help further here.

    Best,

    Alex

  • Hi Alex,

    Reading data zeros was resolved after adding reset_function (which actually reads out all the required registers) which we modify in init. thank you.

    since we have different transmitter and receiver, let me go through Calibration process and update you my findings.

    Thanks

    Neeraj

  • Hi Neeraj,

    Understood. Thanks for the update. If you did not run through calibration then this would be why phase and amplitude readings were behaving unexpectedly. In terms of calibration could you let me know your plan in terms of the steps you plan to run through? Calibration is a bit intensive so I want to make sure you are using all the tools we have available to speed up the process.

    For a brief overview we provide the SDK which has functions for running calibration. The how to calibrate guide also goes along with the sdk to give step by step instructions to the process. The configuration tool generates the initialization.cpp file for the SDK and allows you to generate different device initialization settings depending on your application and needs. The SDK includes the type of functions you are writing from scratch as well so that would be helpful too. 

    The first step for calibration with SDK is the simple bring up step. In this step you calibrate out crosstalk. Crosstalk also gives an indication of the quality of board design and part of this step is measuring the raw crosstalk from the board. I would want you to check the raw crosstalk on the board to check the quality of the board design as well to make sure you don't lose any performance due to any PCB issues. Step 4 here shows how to do this https://e2e.ti.com/support/sensors/f/1023/t/727462?tisearch=e2e-sitesearch&keymatch=opt3101evm

    Best,

    Alex

  • Hi Alex,

    Thank you so much for sharing comprehensive info. let me go through and see the how much we can use SDK. We have c code base in the project.

    Just to answer you, we have designed separate PCB having 2-Tx and 1-Rx with TI MCU to detect max 2m range. It interfaces with iMX7 using I2C. let us plan to use EEPROM to store calibration data. (how many bytes approximately ??)

    I think this should solve our issue. Will update our findings once done.

    Thanks

    Neeraj

  • Hi Neeraj,

    Is this the same project as this thread? https://e2e.ti.com/support/sensors/f/1023/t/838538

    If so please let me know because it looks like there may be some issues with the design that would need to be addressed before moving to calibration. They have provided the board files and I will review and follow up with them by next week.

    Best,

    Alex

  • Hi Alex,

    Yes, it's same project. I am working on Firmware and I see HW team also posted to debug w.r.t. HW design.

    Please help us as we are in final stage and assuming that by tuning current/calibration we can fix this issue.

    Thank You

    Neeraj

  • Hi Neeraj,

    I will need to review the hardware, but it looks like there may be some issues that would need to be solved on the PCB first before calibrating. Please do the residue crosstalk check (masking the photodiode and checking remaining amplitude). We'll want to ideally have this down to ~300 codes or less before starting calibration, though we can also deal with higher values if we must.

    We are working on an update to the SDK that improves ease of use. It allows you to load the SDK on to an MSP430 launchpad, which you need to wire to the OPT3101 on your board. You can then perform the calibration through command line with the MSP430 plugged into your PC. It means you don't have to customize the SDK to your host in terms of i2c access, etc. since we make the host the MSP430. Is this something that would be useful for you and you would want to wait for?

    Best,

    Alex

  • Hi Alex,

    Let me try masking the photodiode and checking remaining amplitude.

    I am msp430 user from long time.. I have MSP-EXP430FR4133 board and use CCS or IAR. Will it be possible to use OPT3101 SDK as is in this board? We will try calibrating and validating using MSP as host and then use other host for final.

    I can wait for 2-3 days max as we have hard timelines...

    Thank You

    Neeraj

  • Hi Neeraj,

    I provided an update on my board design review here: https://e2e.ti.com/support/sensors/f/1023/t/838538

    I saw issues in the design relating to not following the guidelines in our system design doc. We need to check the crosstalk value as I mentioned in the other post before moving forward.

    Best,

    Alex

  • Hi Alex,

    Thank you. Let me check with HW team. will let you know if I have any opens.

    Thank you.

  • Hi Neeraj,

    I will close this post for now. Please keep me posted on status.

    Best,

    Alex