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.

TDC7201-ZAX-EVM: Not getting data from TDC2 in combined mode

Part Number: TDC7201-ZAX-EVM
Other Parts Discussed in Thread: TDC7201

Hi,

I want to use combined mode for short measurement but I could not get any data from TDC2. When debugging I see that in this position debugging does not work which coding line mentioned below

if ((dev == TDC720x_TDC2) && (TDC720x_Parallel_Read == 1))
  {
    while (!(UCB1IFG&UCRXIFG));  // here dubugging not work
    y = UCB1RXBUF;
  }  

But I can get data from the TDC1 . So any kind of suggestion will be appreciated.  

Thank you. 

  • Ahmed,

    Looks like the MSP430 is still waiting for the data from the TDC7201. Please send me your actual setup condition including the schematics.
  • Hello Mr. Bharat,

    I already connect MSP_START pin to COMMON_START and also Populate zero ohm resistors R11 and R12 Remove R2 and R9.

    Here is my code

    //9.5.2018  backup
    
    
    //******************************************************************************
    //  Demo Application01 for MSP430/TDC720x Interface Code Library v1.0
    //  Byte Read/ Byte Write TDC720x Registers
    //
    //                MSP430F5529
    //             -----------------
    //         /|\|              XIN|-
    //          | |                 |
    //          --|RST          XOUT|-
    //            |                 |
    //            |    P3.0/UCB0SIMO|--> SDI
    //            |    P3.1/UCB0SOMI|<-- SDO
    //            |     P3.2/UCB0CLK|--> CLK
    //            |             P2.6|--> CSB
    //            |             P2.4|
    //            |                 |
    //            |             P1.2|
    //
    //   Vishy Natarajan
    //   Texas Instruments Inc.
    //   March 2013
    //   Built with IAR Embedded Workbench Version:  5.5x
    //******************************************************************************
    /*  Copyright 2011-2012 Texas Instruments Incorporated. All rights reserved.
    
      IMPORTANT: Your use of this Software is limited to those specific rights
      granted under the terms of a software license agreement between the user who
      downloaded the software, his/her employer (which must be your employer) and
      Texas Instruments Incorporated (the "License"). You may not use this Software
      unless you agree to abide by the terms of the License. The License limits your
      use, and you acknowledge, that the Software may not be modified, copied or
      distributed unless embedded on a Texas Instruments microcontroller which is
      integrated into your product. Other than for the foregoing purpose, you may
      not use, reproduce, copy, prepare derivative works of, modify, distribute,
      perform, display or sell this Software and/or its documentation for any
      purpose.
    
      YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
      PROVIDED 鄭S IS・WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
      INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
      NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS
      INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
      NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL
      EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT
      LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL
      DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS,
      TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
      LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
    
      Should you have any questions regarding your right to use this Software,
      contact Texas Instruments Incorporated at www.TI.com.
    *******************************************************************************/
    #include <intrinsics.h>
    #include <string.h>
    # include <stdint.h>
    #include  <cstring.h>
    #include  <stdio.h>
    #include "TI_TDC720x.h"
    #include "TI_MSP430.h"
    #include "TI_MSP430_hardware_board.h"
    #include "TI_MSP430_spi.h"
    #include "C:\Users\Fahin Syed\Desktop\Combined_Mode\Combined_mode\code\demo_apps\demo1_tdc720x_basic_rw\timer_queue.h"
    #include "host_interface.h"
    #include "tdc720x_calculation.h"
    #include "uart_commn.h"
    #include "USB_API/USB_Common/device.h"
    #include "USB_API/USB_Common/types.h"
    #include "USB_API/USB_Common/usb.h"
    #include "F5xx_F6xx_Core_Lib/HAL_UCS.h"
    #include "F5xx_F6xx_Core_Lib/HAL_PMM.h"
    #include "C:\Users\Fahin Syed\Desktop\Combined_Mode\Combined_mode\code\USB_API\USB_CDC_API\UsbCdc.h"
    #include "C:\Users\Fahin Syed\Desktop\Combined_Mode\Combined_mode\code\USB_app\usbConstructs.h"
    #include "USB_config/descriptors.h"
    #include "HAL_PMM.h"
    
    
    #define TDC720x_TDC1 0
    #define TDC720x_TDC2 1
    #define MAX_STR_LENGTH 32
    //function defination
    void InitMCU(void);
    void Init_Clock (void);
    void Init_Ports (void);
    void USBCommunicationTask(void);
    void TI_TDC720x_reg_init(uint8_t);
    extern void timer_microsec_delay(uint16_t);
    extern void tdc_trigger_measure(void);
    
    // Globals & Externs
    volatile uint8_t TDC720x_XYBufferReady = 0;
    volatile uint8_t TDC720x_PQBufferReady = 0;
    
    
    void TDC720x_calc();
    void TDC720x_normlsb();
    void TDC720x_start2stopn();
    void TI_TDC720x_build_mreg();
    void TDC720x_calculation();
    void two_tdc_measure_results();
    float getTOF(uint32_t timeN, uint32_t clockcountN, uint32_t cal1, uint32_t cal2);
    void moving_filter(float noise_tof); //fahin
    float holt_exponential_smoother(float noise_tof); //fahin
    float kalmanFilter(float inData); //fahin
    uint8_t wait_on_intb_pin(uint16_t pin);
    
    //uint8_t USBCDC_abortSend (uint16_t* size, uint8_t intfNum);
    volatile BYTE bCDCDataReceived_event = FALSE;   //Indicates data has been received without an open rcv operation
    WORD w;
    uint8_t bufferX[BUF_LENGTH];
    uint8_t bufferY[BUF_LENGTH];
    uint8_t *mbuf=bufferX;
    uint8_t *ubuf;
    uint8_t *cmdResponseStringMAX;
    uint16_t _STR_LENGTH;
    
    //uint8_t CDC0_INTFNUM;
    
    uint8_t bufferP[BUF_LENGTH];
    uint8_t bufferQ[BUF_LENGTH];
    uint8_t *nbuf=bufferP;
    uint8_t *vbuf;
    uint8_t cmdResponseString[MAX_STR_LENGTH] = "";
    uint8_t single_shot_measure_state=0;
    uint8_t tof_graph_state=0;
    uint8_t graph_delay_sweep_state=0;
    uint8_t double_resolution=0;
    uint8_t current_tdc = TDC720x_TDC1;
    uint8_t TDC720xEVM_Device = TDC7201;
    uint32_t err_count = 0;
    
    
    extern volatile uint8_t next_trigger_time =0;
    extern uint8_t TDC720x_UART_Stream =1;
    extern uint8_t Measure_LT12ns_Method =TDC720x_MUX_METHOD;;
    
    
    // Test TDC720x Register Read/Write & Conversion
    uint32_t tDC720x_TDC2 = 1;
    uint32_t clk_count;
    uint32_t clk_count1;
    
    //clock initilization
    uint32_t clk_counter1;
    uint32_t clk_counter2;
    uint32_t clk_counter3;
    uint32_t clk_counter4;
    uint32_t clk_counter5;
    
    uint32_t calibration1; //fahin
    uint32_t calibration2; //fahin
    uint32_t timer1;//fahin
    uint32_t timer2;//fahin
    uint32_t timer3;//fahin
    uint32_t timer4;//fahin
    uint32_t timer5;//fahin
    uint32_t timer6;//fahin
    
    float tof;
    float tof1;
    float tof2;
    float tof3;
    float tof4;
    float tof5;
    
    float tof_storage[100];
    char res[20];
    int counter =0;
    int count = 1;
    int num = 1;
    int filter_count =0;
    float y[100];
    float filter_tof[1000];
    //copied from tdc720x_calculation
    float tdc_clk_period = 125.0;
    float start2stop[MAX_STOPS];
    uint8_t outString[128];
    int32_t meas_result_regrs[MEAS_RESULT_REG_NUM];
    float norm_lsb;
    float ccnt;
    int smoother = 1;
    int smooth = 1;
    float holt_data[100];
    
    
    float y_curr = 0;
    float y_prev = 0;
    float x_prev = 0;
    float alpha  = 1;
    float temp   = 0;
    float highpass(float x);
    
    float EMA_S = 0;
    float EMA_a = .15;
    float highpases;
    float arduino_highPass(float sensorValue );
    
    
    
    void moving_filter_algo(float noise_tof);
    float total =0.0;
    float filter_tof_val =0.0;
    int countering = 1;
    
    
    
    float holt_exponential_smoother_test(float noise_tof);
    float holt_data_current =  0;
    float holt_data_previous = 0;
    float thresolds = 0;
    //-----------------------------------------
    uint8_t *ubuf; //fahin
    uint8_t read_val[3], all_data[TDC720x_ALL_DATA_SIZE], byte_data;
    uint32_t tout = 0;
    uint8_t TDC720x_Parallel_Read = 1;
    //******************************************************************************
    void main(void)
     {
    
      WDTCTL = WDTPW+WDTHOLD;                                                      // Stop WDT
    
      TI_TDC720x_GLED_PxOUT |= TI_TDC720x_GLED_PIN;                                // Set LED ON
      TI_TDC720x_GLED_PxDIR |= TI_TDC720x_GLED_PIN;                                // Set pin direction is output
    
      TI_TDC720x_RLED_PxOUT &= ~TI_TDC720x_RLED_PIN;                                // Set RLED OFF
      TI_TDC720x_RLED_PxDIR |= TI_TDC720x_RLED_PIN;                                // Set pin direction
    
      TI_TDC720x_OSCENABLE_PxOUT |= TI_TDC720x_OSCENABLE_PIN;                    // Set pin high: enable afe osc
      TI_TDC720x_OSCENABLE_PxDIR |= TI_TDC720x_OSCENABLE_PIN;                    // Set pin direction is output
    
      __delay_cycles(50000);
    
      TI_TDC720x_ENABLE1_PxOUT |= TI_TDC720x_ENABLE1_PIN;                            // Enable device
      TI_TDC720x_ENABLE1_PxDIR |= TI_TDC720x_ENABLE1_PIN;                            // Set pin direction output
    
    #if 0
      TI_TDC720x_FLAG_PxOUT |= TI_TDC720x_FLAG_PIN;                                // Flag Input Pull up enable
      TI_TDC720x_FLAG_PxREN |= TI_TDC720x_FLAG_PIN;                                // Flag Input Resistor enable
      TI_TDC720x_FLAG_PxDIR &= ~TI_TDC720x_FLAG_PIN;                               // Set pin direction input
    #endif
    
      TI_TDC720x_ENABLE2_PxOUT |= TI_TDC720x_ENABLE2_PIN;                          // Enable2 device
      TI_TDC720x_ENABLE2_PxDIR |= TI_TDC720x_ENABLE2_PIN;                          // Set pin direction output
    
      TI_TDC720x_MUX1_CTRL_PxOUT &= ~TI_TDC720x_MUX1_CTRL_PIN;                     // Set MUX1 low
      TI_TDC720x_MUX1_CTRL_PxDIR |= TI_TDC720x_MUX1_CTRL_PIN;                      // Set pin direction output
    
      TI_TDC720x_MUX2_CTRL_PxOUT &= ~TI_TDC720x_MUX2_CTRL_PIN;                     // Set MUX1 low
      TI_TDC720x_MUX2_CTRL_PxDIR |= TI_TDC720x_MUX2_CTRL_PIN;                      // Set pin direction output
    
      // Set msp430 to send start pulse
      TI_TDC720x_START_MSP430_PxOUT &= ~TI_TDC720x_START_MSP430_PIN;
      TI_TDC720x_START_MSP430_PxDIR |= TI_TDC720x_START_MSP430_PIN;
    
      // configure Port Pin to handle Interrupt Bar Output (INTB) from TDC720x
      TI_TDC720x_INTB_PxDIR &= ~TI_TDC720x_INTB1_PIN;                               // Set up port pin for INTB
      TI_TDC720x_INTB_PxOUT |= TI_TDC720x_INTB1_PIN;                                // INTB Input Pull up enable
      TI_TDC720x_INTB_PxREN |= TI_TDC720x_INTB1_PIN;                                // INTB Input Resistor enable
      TI_TDC720x_INTB_PxIES |= TI_TDC720x_INTB1_PIN;                                // Interrupt Edge Select
      TI_TDC720x_INTB_PxIFG &= ~TI_TDC720x_INTB1_PIN;                               // Clear Interrupt Flag
    //  TI_TDC720x_INTB_PxIE |= TI_TDC720x_INTB1_PIN;                               // Enable Port interrupt
    
     // configure Port Pin to handle Interrupt Bar Output (INTB2) from TDC720x
       TI_TDC720x_INTB_PxDIR &= ~TI_TDC720x_INTB2_PIN;                              // Set up port pin for INTB
       TI_TDC720x_INTB_PxOUT |= TI_TDC720x_INTB2_PIN;                               // INTB Input Pull up enable
       TI_TDC720x_INTB_PxREN |= TI_TDC720x_INTB2_PIN;                               // INTB Input Resistor enable
       TI_TDC720x_INTB_PxIES |= TI_TDC720x_INTB2_PIN;                               // Interrupt Edge Select
       TI_TDC720x_INTB_PxIFG &= ~TI_TDC720x_INTB2_PIN;                              // Clear Interrupt Flag
      //  TI_TDC720x_INTB_PxIE |= TI_TDC720x_INTB2_PIN;
    
      // oscillator fail if LED keeps flashing after InitMCU
      InitMCU();
    
      // Initilaize MSP430 UART A1 Block
      InitUART();
    
      // Initilaize MSP430 SPI Block
      TI_TDC720x_SPISetup();                                                       // Initilaize MSP430 SPI Block
    
      timer1_A0_init(); // init interval timer (timer1)
    
      // init timer0 A0 for programmable external osc wake up time
        //timer0_A0_init();
    
        // init timer2 A0 to generate PWM
        timer2_A0_init();
    
      // default device is TDC7201 and default tdc is TDC1
      if (TDC720xEVM_Device == TDC7201)
      {
        TI_TDC720x_reg_init(TDC720x_TDC1);
        TI_TDC720x_reg_init(TDC720x_TDC2);
      }
      else
      {
        TI_TDC720x_reg_init(TDC720x_TDC1);
      }
     // next_trigger_time = 1;
    
      while (1)
        {
       // __bis_SR_register(LPM0_bits + GIE);                                        // Enter LPM0, enable interrupts
     //     __no_operation();                                                          // For debugger
       //   __delay_cycles(250000);
       //   if (next_trigger_time)
       //  {
         //   next_trigger_time = 0;
        //  USBCommunicationTask();
          two_tdc_measure_results();    // trigger
          TDC720x_calculation() ;       //calculation
       //     __no_operation();                                                        // For debugger
       //   }
          __delay_cycles(250000);
         __no_operation();                                                          // For debugger
    //      }
      }
    
    
    
    
                                          // Enter LPM0, enable interrupts
                                                                // For debugger
    
    } // close main
    //******************************************************************************
    //******************************************************************************
    /**
    * @brief Function Name: Init_Clock .
    * @brief Description  : Initializes MSP430 clock module.
    * @param parameters   : none
    * @return Value       : none
    */
    //******************************************************************************
    void Init_Clock(void)
    {
    
    //  UCSCTL3 = SELREF_2;                       // Set DCO FLL reference = REFO
    //  UCSCTL4 |= SELA_2;                        // Set ACLK = REFO
      // Enable XT2 XIN/XOUT Pins
      P5SEL |= 0x0C;                            // Select XIN, XOUT on P5.3 and P5.2
      UCSCTL6 &= ~XT2OFF;                       // Enable XT2
      UCSCTL6 |= XT2DRIVE_3;
    
      P5SEL |= BIT4+BIT5;                       // Select XT1
    
      UCSCTL6 &= ~(XT1OFF);                     // XT1 On
      UCSCTL6 |= XCAP_3;                        // Internal load cap
      UCSCTL3 = 0;                              // FLL Reference Clock = XT1
    
      // Loop until XT1,XT2 & DCO stabilizes - In this case loop until XT1 and DCo settle
      do
      {
        UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
                                                // Clear XT2,XT1,DCO fault flags
        SFRIFG1 &= ~OFIFG;                      // Clear fault flags
        TI_TDC720x_RLED_PxOUT ^= TI_TDC720x_RLED_PIN;                              // Toggle LED
        __delay_cycles(250000);
      }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
    
      UCSCTL6 &= ~(XT1DRIVE_3);                 // Xtal is now stable, reduce drive strength
    
      UCSCTL4 |= SELA_0;                        // ACLK = LFTX1 (by default)
    
      __bis_SR_register(SCG0);                  // Disable the FLL control loop
      UCSCTL0 = 0x0000;                         // Set lowest possible DCOx, MODx
      UCSCTL1 = DCORSEL_7;                      // Select DCO range 50MHz operation
      UCSCTL2 = FLLD_0 + 747;                   // Set DCO Multiplier(762/498) for 25MHz/16MHz
                                                // (N + 1) * FLLRef = Fdco
                                                // (762 + 1) * 32768 = 25MHz
                                                // Set FLL Div = fDCOCLK/2
      __bic_SR_register(SCG0);                  // Enable the FLL control loop
    
      // Worst-case settling time for the DCO when the DCO range bits have been
      // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
      // UG for optimization.
      // 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle
      __delay_cycles(782000);
    
      // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize
      do
      {
        UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
                                                // Clear XT2,XT1,DCO fault flags
        SFRIFG1 &= ~OFIFG;                      // Clear fault flags
        TI_TDC720x_RLED_PxOUT ^= TI_TDC720x_RLED_PIN;                              // Toggle LED
        __delay_cycles(250000);
      }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
    
      UCSCTL4 = SELA__XT1CLK + SELS__DCOCLKDIV + SELM__DCOCLKDIV;                  // SMCLK=MCLK=
    
      // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize
      do
      {
        UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
                                                // Clear XT2,XT1,DCO fault flags
        SFRIFG1 &= ~OFIFG;                      // Clear fault flags
        TI_TDC720x_RLED_PxOUT ^= TI_TDC720x_RLED_PIN;                              // Toggle LED
        __delay_cycles(250000);
      }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
    
      TI_TDC720x_RLED_PxOUT &= ~TI_TDC720x_RLED_PIN;                                // turn off red
    
    }
    //******************************************************************************
    /**
    * @brief  Local functions.
    */
    
    /**
    * @brief Function Name:  InitMCU.
    * @brief Description  :  Initializes the MSP430 peripherals and modules.
    * @param parameters   :  none
    * @return Value       :  none
    */
    //******************************************************************************
    void InitMCU(void)
    {
    
      __disable_interrupt();                                                       // Disable global interrupts
        SetVCore(3);
        Init_Clock();                                                              //Init clocks
      __enable_interrupt();                                                        // enable global interrupts
    
    }
    //******************************************************************************
    
    //********************************************
    /**
    * @brief  Local functions.
    */
    
    /**
    * @brief Function Name:  TDC720x_calc
    * @brief Description  :  Measurement calculation
    * @param parameters   :  none
    * @return Value       :  none
    * @Developed by       :  TI
    */
    //********************************************
    
    void TDC720x_calc()
    {
      TI_TDC720x_build_mreg();
      TDC720x_start2stopn();
     // print_start2stopn();
    }
    
    /*
    * Function Name       :  Start to stop pin
    * @brief Description  :  num of stop countung
    * @param parameters   :  none
    * @return Value       :  none
    * @Developed by       :  TI
    */
    void TDC720x_start2stopn()
    {
          uint8_t n;
          TDC720x_normlsb();
      for(n=0; n < MAX_STOPS; n++)
          start2stop[n] = norm_lsb * (meas_result_regrs[0] - meas_result_regrs[2*(n+1)]) +
                          tdc_clk_period * meas_result_regrs[2*(n+1)-1];
    
    }
    
    
    /*
     * Function name       :  TDC720x_normlsb
     * Description         :  Normalized LSD value
     * @param parameters   :  device
     * @return Value       :  none
     * @Developed by       :  TI
     */
    void TDC720x_normlsb()
    {
      uint8_t tdcbyte =2, cal2cy;
      // read config2 register - use local saved data
     // tdcbyte = (TI_TDC720x_SPIByteReadReg(TI_TDC720x_CONFIG2_REG, dev) & CAL2MASK)>>CAL2SHFT;
    
      switch (tdcbyte)
      {
        case 0:
          cal2cy = 2;
          break;
        case 1:
          cal2cy = 10;
          break;
        case 2:
          cal2cy = 20;
          break;
        case 3:
          cal2cy = 40;
        default:
          cal2cy = 10;
      }               //calibration2
    
      ccnt = (float) (meas_result_regrs[12]-meas_result_regrs[11])/(cal2cy-1);
      norm_lsb = tdc_clk_period / ccnt;
    }
    
    void TI_TDC720x_build_mreg()  // Register for getting data
    {
    
       meas_result_regrs[0]  = TI_TDC720x_SPILongReadReg(0x10,TDC720x_TDC1);;
       meas_result_regrs[1]  = TI_TDC720x_SPILongReadReg(0x11, TDC720x_TDC1);
       meas_result_regrs[2]  = TI_TDC720x_SPILongReadReg(0x12,TDC720x_TDC1);
       meas_result_regrs[3]  = TI_TDC720x_SPILongReadReg(0x13, TDC720x_TDC1);
       meas_result_regrs[4]  = TI_TDC720x_SPILongReadReg(0x14,TDC720x_TDC1);
       meas_result_regrs[5]  = TI_TDC720x_SPILongReadReg(0x15, TDC720x_TDC1);
       meas_result_regrs[6]  = TI_TDC720x_SPILongReadReg(0x16,TDC720x_TDC1);
       meas_result_regrs[7]  = TI_TDC720x_SPILongReadReg(0x17, TDC720x_TDC1);
       meas_result_regrs[8]  = TI_TDC720x_SPILongReadReg(0x18,TDC720x_TDC1);
       meas_result_regrs[9]  = TI_TDC720x_SPILongReadReg(0x19, TDC720x_TDC1);
       meas_result_regrs[10] = TI_TDC720x_SPILongReadReg(0x1Au,TDC720x_TDC1);
       meas_result_regrs[11] = TI_TDC720x_SPILongReadReg(0x1B,TDC720x_TDC1);
       meas_result_regrs[12] = TI_TDC720x_SPILongReadReg(0x1C,TDC720x_TDC1);
    
    }
    
    
    
    /*
    * @brief Function Name:  TDC720x_calculation()
    * @brief Description  :  ToF Measurement calculation
    * @param parameters   :  none
    * @return Value       :  none
    * @Developed by       :  Ahmed Syed Fahin
    */
    
    void TDC720x_calculation()
    {
        // register initialization
        timer1          = TI_TDC720x_SPILongReadReg(0x10,TDC720x_TDC1);
        clk_counter1    = TI_TDC720x_SPILongReadReg(0x11, TDC720x_TDC1);
        calibration1    = TI_TDC720x_SPILongReadReg(0x1B,TDC720x_TDC1);
        calibration2    = TI_TDC720x_SPILongReadReg(0x1C,TDC720x_TDC1);
    
        tof1            = getTOF(timer1, clk_counter1, calibration1, calibration2);
        printf("%f",tof1);
    
        // register initialization
        timer1          = TI_TDC720x_SPILongReadReg(0x10,TDC720x_TDC2);
        clk_counter1    = TI_TDC720x_SPILongReadReg(0x11, TDC720x_TDC2);
        calibration1    = TI_TDC720x_SPILongReadReg(0x1B,TDC720x_TDC2);
        calibration2    = TI_TDC720x_SPILongReadReg(0x1C,TDC720x_TDC2);
    
        tof2            = getTOF(timer1, clk_counter1, calibration1, calibration2);
        tof             = tof2 - tof1;
        printf("%f",tof);
    
    }
    
    
    /*
    * @brief Function Name:  getTOF
    * @brief Description  :  ToF calculation
    * @param parameters   :  Timer1, Timer2,Clockcount, Calibration1 and calibration2
    * @return Value       :  ToF
    * @Developed by       :  Ahmed Syed Fahin
    */
    float getTOF(uint32_t timeN,uint32_t clockcountN, uint32_t cal1, uint32_t cal2)
        {
    
         float calCount = (cal2 - cal1) / (10 - 1.0);
         float normLSB = (125 / calCount);
         float tof_temp = normLSB*(float)timeN;
    
          return tof_temp;
        }
    
    /*
    * @brief Function Name:  Two_tdc_measure_result
    * @brief Description  :  Start new measurement after generating trigger
    * @param parameters   :  None
    * @return Value       :  None
    */
    
    void two_tdc_measure_results()
        {
            int8_t byte_data1, byte_data2;
            // read config register of TDC1 and TDC2
            byte_data1 = TI_TDC720x_SPIByteReadReg(TI_TDC720x_CONFIG1_REG, TDC720x_TDC1);
            byte_data2 = TI_TDC720x_SPIByteReadReg(TI_TDC720x_CONFIG1_REG, TDC720x_TDC2);
            byte_data1 |= 0x01;
            TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CONFIG1_REG, byte_data1, TDC720x_TDC1);
            byte_data2 |= 0x01;
            TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CONFIG1_REG, byte_data2, TDC720x_TDC2);
    
            // send REF_START: could be used as DTG_TRIG also
              TI_TDC720x_REF_START_PxOUT |= TI_TDC720x_REF_START_PIN;
              TI_TDC720x_REF_START_PxOUT &= ~TI_TDC720x_REF_START_PIN;
              TI_TDC720x_DTG_TRIG_PxOUT |= TI_TDC720x_DTG_TRIG_PIN;
              TI_TDC720x_DTG_TRIG_PxOUT &= ~TI_TDC720x_DTG_TRIG_PIN;
    
              //wait for INTB1 pin to go low
             wait_on_intb_pin(TI_TDC720x_INTB1_PIN);
             TI_TDC720x_SPIAllReadReg(mbuf, TDC720x_TDC1);
             // switch buffer and set flag for usb to send the filled buffer
              ubuf = mbuf;
              if (mbuf == bufferX)
                mbuf = bufferY;
              else
                mbuf = bufferX;
              TDC720x_XYBufferReady = 1;
              //wait for INTB2 pin to go low
               wait_on_intb_pin(TI_TDC720x_INTB2_PIN);
               TI_TDC720x_SPIAllReadReg(nbuf, TDC720x_TDC2);
    
               // switch buffer and set flag for usb to send the filled buffer
               vbuf = nbuf;
               if (nbuf == bufferP)
                 nbuf = bufferQ;
               else
                 nbuf = bufferP;
               TDC720x_PQBufferReady = 1;
        }
    
    //******************************************************************************
    uint8_t wait_on_intb_pin(uint16_t pin)
    {
      uint32_t tout = 0;
      //wait for INTB2 pin to go low
      while(TI_TDC720x_INTB_PxIN & pin)
      {
        tout++;
        // 1us delay below at 24MHz master clock
        __delay_cycles(24);
        // TIMEOUT_VALUE is 200000, wait atleast 200ms and timeout
        if (tout >= TIMEOUT_VALUE)
         return 0;
      }
      return 1;
    }
    
    //******************************************************************************
    void TI_TDC720x_reg_init(uint8_t dev)
    {
    
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CONFIG1_REG, 0x00, dev); // Default Mode 2
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CONFIG2_REG, 0x40, dev); // cal2 period = 10 clocks
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_INTRPT_STATUS_REG, 0x0B, dev); // clear interrupt status
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_INTRPT_MASK_REG, 0x07, dev); // interrupts enabled
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_COARSE_COUNTER_OVH_REG, 0xFF, dev); // default
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_COARSE_COUNTER_OVL_REG, 0xFF, dev); // default
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CLOCK_COUNTER_OVH_REG, 0xFF, dev); // default
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CLOCK_COUNTER_OVL_REG, 0xFF, dev); // default
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CLOCK_COUNTER_STOP_MASKH_REG, 0x00, dev); // default
      TI_TDC720x_SPIByteWriteReg(TI_TDC720x_CLOCK_COUNTER_STOP_MASKL_REG, 0x00, dev); // default
    }
    //******************************************************************************
    //EOF
    void timer1_A0_init(void)
    {
      TA1CCR0 = INTERVAL_100ms;
      // enable timer interrupt
      TA1CCTL0 |= CCIE;                                                            // TA1CCR0 interrupt enabled
      // Note: TACLR clears both counter and clock divider: setup divider later
      TA1CTL |= TACLR;
      TA1CTL = TASSEL_2 + MC_1 + ID_2;                                     // SMCLK (4MHz), clear TAR, conts mode, divide by 4, no overflow intrpt TAIE
      TA1EX0 = TAIDEX_7;                                                           // further divide by 8
    
    }
    
    
    void timer2_A0_init(void)
    {
      uint8_t pwm_period;
    
      //SMCLK assumed to be 4MHz
      pwm_period = 11; // default freq = 4MHz/12 = 0.333MHz
      // Select PWM output pins: DTG_TRIG and REF_START pins
      TI_TDC720x_DTG_TRIG_PxOUT &= ~TI_TDC720x_DTG_TRIG_PIN;                       // Set pin output low
      TI_TDC720x_DTG_TRIG_PxDIR |= TI_TDC720x_DTG_TRIG_PIN;                        // Set pin direction is output
      TI_TDC720x_DTG_TRIG_PxDS |= TI_TDC720x_DTG_TRIG_PIN;
    
    //  TI_TDC720x_REF_START_PxOUT &= ~TI_TDC720x_REF_START_PIN;                     // Set pin output low
      TI_TDC720x_REF_START_PxDIR &= ~TI_TDC720x_REF_START_PIN;                      // Set pin direction is output
    //  TI_TDC720x_REF_START_PxDS |= TI_TDC720x_REF_START_PIN;
    
      // Output the clock on the pin when enabled by TDC720x_MEASURE_LT12NS user command
      TA2CCR0 = pwm_period;                                                        // PWM Period
      // enable timer interrupt
      TA2CCTL0 |= CCIE;
      // enable set/reset of P2.4 and P2.5 Timer PWM pins: P2.4 is REF_START, P2.5 is DTG_TRIGG
      // First give REF_START then DTG_TRIGG
      TA2CCTL1 = OUTMOD_3;                                                         // CCR1 set/reset
      TA2CCTL2 = OUTMOD_3;                                                         // CCR2 set/reset
      TA2CCR1 = (pwm_period+1) / 3;
      TA2CCR2 = 2 * (pwm_period+1)/3;                                              // CCR2 PWM duty cycle
      TA2CTL = TASSEL__SMCLK + MC_0 + TACLR;                                       // SMCLK, stop mode, clear TAR
    
    }
    void InitUART(void){
    
      UCAxCTL1 |= UCSWRST;                      // **Stops USCI state machine**
    
      UART_PxREN &= ~(UART_TX_PAD|UART_RX_PAD); //Disable port pull resistors
      UART_PxDIR &= ~UART_RX_PAD;               // Configure Px.X as input
      UART_PxDIR |= UART_TX_PAD;                // Configure Px.X as output
      UART_PxSEL |= (UART_TX_PAD|UART_RX_PAD);  // Px.x & Px.X = USCI_Ax TXD & RXD
    
      UCAxCTL0 = 0x00;                          // No parity, 8-N-1 mode
      UCAxCTL1 |= UCSSEL__SMCLK;                // Select 12MHz SMCLK as clock source for the UART
      UCAxBR = UART_BAUDRATE_REG;               // defines baudrate
      UCAxMCTL =  (UCBRF_0|UCBRS_3);            //    38400  baudrate selection @ 4MHz
    //  UCAxMCTL =  (UCBRF_0|UCBRS_4);            //  57600  baudrate selection @ 4MHz
      UCAxIFG &= ~UCAxRXIFG;          //Clear RX IFG
    
      UCAxCTL1 &= ~UCSWRST;           // **Initialize USCI state machine**
    //  UCAxIE |= UCAxRXIE;             // Enable USCI_A1 RX interrupt
    //  UCAxIE |= UCAxTXIE;             // Enable USCI_A1 TX interrupt
    
    }
    
    
    void tdc_trigger_measure(void)
    {
    
      // enable external osc before starting measurement
      //TI_TDC720x_OSCENABLE_PxOUT |= TI_TDC720x_OSCENABLE_PIN;                    // Set pin high: enable afe osc
      //TI_TDC720x_OSCENABLE2_PxOUT |= TI_TDC720x_OSCENABLE2_PIN;
    
      // use default delay if input is 0
      //timer_microsec_delay(0);
    
      if ((tof_graph_state == 1) || (single_shot_measure_state == 1))
      {
    // if (TDC720x_Measure_LT12ns == 1){}
    //      TDC720x_mode1_lt12ns();
    //    else if ((tof_graph_state == 1) && (TDC720x_Graph_Select == TDC720x_BOTH))
    //      two_tdc_measure_results();
    //    else
    //      one_tdc_measure_results();
      }
    
      // disable osc after completing measurement
      //TI_TDC720x_OSCENABLE_PxOUT &= ~TI_TDC720x_OSCENABLE_PIN;                   // Set pin low: disable afe osc
      //TI_TDC720x_OSCENABLE2_PxOUT &= ~TI_TDC720x_OSCENABLE2_PIN;
    
      // __bic_SR_register_on_exit(LPM0_bits);
    }
    
    
    void USBCommunicationTask(void)
    {
      WORD bytesSent, bytesReceived;
      uint16_t count;
      uint8_t send_error=0, receive_error=0, send_response, i;
    
            switch (USB_connectionState())
            {
                case ST_USB_DISCONNECTED:
    //                __bis_SR_register(LPM3_bits + GIE);                     //Enter LPM3 w/interrupt
                    _NOP();
                    break;
    
                case ST_USB_CONNECTED_NO_ENUM:
                    break;
    
                case ST_ENUM_ACTIVE:
                    if (USBCDC_intfStatus(CDC0_INTFNUM,&bytesSent, &bytesReceived) & kUSBCDC_waitingForSend)
                        err_count++;
                    // Exit LPM because of a data-receive event, and fetch the received data
                    if(bCDCDataReceived_event)
                    {
                      bCDCDataReceived_event = FALSE;                                  // Clear flag early -- just in case execution breaks below because of an error
                      count = cdcReceiveDataInBuffer(cmdResponseStringMAX, _STR_LENGTH, CDC0_INTFNUM);         // Count has the number of bytes received into dataBuffer
                      send_response = handleHostCommand(cmdResponseString,count);
                      if (send_response)
                      {
                        if(cdcSendDataInBackground((BYTE*)cmdResponseString,MAX_STR_LENGTH,CDC0_INTFNUM,0))             // Send data to host
                        {
                          send_error = 1;                                            // Something went wrong -- exit
                          break;
                        }
                      }
                      for(i=0;i<MAX_STR_LENGTH;i++)
                        cmdResponseString[i] = NULL;
                    } else if ((tof_graph_state == 1) || (single_shot_measure_state == 1))
                    {
                      if (TDC720x_XYBufferReady)
                      {
                        TDC720x_XYBufferReady = 0;
                        if (cdcSendDataInBackground((BYTE*)ubuf,BUF_LENGTH,CDC0_INTFNUM,0))
                        {
                            bCDCDataReceived_event = FALSE;
                            USBCDC_abortSend(&w,CDC0_INTFNUM);              //Operation probably still open; cancel it
                        }
                        TI_TDC720x_GLED_PxOUT ^= TI_TDC720x_GLED_PIN;                      // Toggle LED
                        if (single_shot_measure_state == 1)
                        {
                          single_shot_measure_state = 0;
                          TI_TDC720x_GLED_PxOUT |= TI_TDC720x_GLED_PIN;                        // Turn on LED
                        }
                        if (TDC720x_UART_Stream)
                          TDC720x_calc(ubuf, TDC720x_TDC1);
                      }
                      if (TDC720x_PQBufferReady)
                      {
                        TDC720x_PQBufferReady = 0;
                        if (cdcSendDataInBackground((BYTE*)vbuf,BUF_LENGTH,CDC0_INTFNUM,0))
                        {
                            bCDCDataReceived_event = FALSE;
                            USBCDC_abortSend(&w,CDC0_INTFNUM);              //Operation probably still open; cancel it
                        }
                        TI_TDC720x_GLED_PxOUT ^= TI_TDC720x_GLED_PIN;                      // Toggle LED
                        if (single_shot_measure_state == 1)
                        {
                          single_shot_measure_state = 0;
                          TI_TDC720x_GLED_PxOUT |= TI_TDC720x_GLED_PIN;                        // Turn on LED
                        }
                        if (TDC720x_UART_Stream)
                          if (Measure_LT12ns_Method == TDC720x_MUX_METHOD)
                            TDC720x_calc(vbuf, TDC720x_TDC1);
                          else
                            TDC720x_calc(vbuf, TDC720x_TDC2);
    
                      }
                    }
                    break;
    
                case ST_ENUM_SUSPENDED:
    //                __bis_SR_register(LPM3_bits + GIE);             //Enter LPM3 until a resume or VBUS-off event
                    break;
    
                case ST_ENUM_IN_PROGRESS:
                    break;
    
                case ST_NOENUM_SUSPENDED:
    //                __bis_SR_register(LPM3_bits + GIE);
                    break;
    
                case ST_ERROR:
                    _NOP();
                    break;
    
                default:;
            }                                                                            //end of switch-case sentence
            if(send_error || receive_error)
            {
              //TO DO: User can place code here to handle error
            }
    }
    

    Thank you. Waiting for your reply.

  • Ahmed,

    I may not be able to check the code & help wit debug. Please send me a short register map for your setup & I can help if there is any issues with the same.
  • Ahmed,

    please let me know if you could send me the register map.