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.

TDC7200 multicycle averaging

Other Parts Discussed in Thread: TDC7200, TDC7200EVM, TDC1000

Hi,

I want to use the multi-cycle averaging mode for TDC7200 in mode2. Can you please provide the example to calculate the TOF for multicycle averaging?

I have the TDC1000_TDC7200EVM and I am working on water flow meter application. I have implemented the equation for "Multi-Cycle Averaging" mentioned in "TDC7200 Time-to-Digital Converter for Time-of-Flight Applications in LIDAR, Magnetostrictive and Flow Meters" document.

TOFn = normLSB[TIME1 - TIME(n+1)] + [CLOCK_COUNTn >> log 2 (AVG_CYCLES)] x [CLOCKperiod]

I have used the example source for "demo4_tdc1000_tdc7200_usb" available after installing GUI.

The piece of code is: 

/*********************************************************************************************************************************

#define AVG_CYCLES_BITS 0x38

uint8_t cnfg2;
uint8_t avg_count;
uint8_t buffer[50] = {0};
cnfg2 = TI_TDC7200_SPIByteReadReg(TI_TDC7200_CONFIG2_REG);
avg_count = (cnfg2 & AVG_CYCLES_BITS) >> 0x03;

//mreg[0] = Time1, mreg[1] = Clk_count1, mreg[2] = Time2
//mreg[3] = Clk_count2, mreg[4] = Time3, mreg[5] = Clk_count3
//mreg[6] = Time4, mreg[7] = Clk_count4, mreg[8] = Time5
//mreg[9] = Clk_count5, mreg[10] = Time6, mreg[11] = Calibration1
//mreg[12] = Calibration2

if (avg_count)
{
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]) >> (int16_t)log2(avg_count) );

}
} else {
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];

}
}

tof = start2stop[0];

/*********************************************************************************************************************************

but I get different values of TOF(in ns) for different measurement cycles as below for no flow.

Averaging cycle : 1 TOF : 37604.136719 ns

Averaging cycle : 2 TOF : 75176.921875 ns

Averaging cycle : 4 TOF : 75172.750000 ns

Averaging cycle : 8 TOF : 150298.187500 ns

Averaging cycle : 16 TOF : 150298.578125 ns

Averaging cycle : 32 TOF : 300548.906250 ns

Averaging cycle : 64 TOF : 601049.187500 ns

Averaging cycle : 128 TOF : 1202049.250000 ns

For no flow, these all values must be equal for different measurement cycles. But I am getting different values for different averaging cycles.

As per datasheet,  AVG_CYCLES is 

000: 1 Measurement Cycle only (no Multi-Cycle Averaging Mode)
001: 2 Measurement Cycles
010: 4 Measurement Cycles
011: 8 Measurement Cycles
100: 16 Measurement Cycles
101: 32 Measurement Cycles
110: 64 Measurement Cycles
111: 128 Measurement Cycles

If I select 8 Measurement Cycles, Should I have to pass AVG_CYCLES as 3 as per datasheet or 8 in the below equation TOF?

TOFn = normLSB[TIME1 - TIME(n+1)] + [CLOCK_COUNTn >> log 2 (AVG_CYCLES)] x [CLOCKperiod]

Thanks,

Khushbu

  • Khushbu,

    I think the issue is

    >>>avg_count = (cnfg2 & AVG_CYCLES_BITS) >> 0x03;

    As avg_cnt is going to be between 0 to 7 (not 1 to 128, so AVG_CYCLES is "2^avg_count") you don't need "log2" in equation below

    >>>start2stop[n] = norm_lsb * (meas_result_regrs[0] - meas_result_regrs[2*(n+1)]) +
    tdc_clk_period * (( meas_result_regrs[2*(n+1)-1]) >> (int16_t)log2(avg_count) );

    Thanks,
    Vishy
  • Hi Vishy,

    Thank you for your response.
    I have one query about the answer you suggested.

    If I use
    >>>avg_count = (cnfg2 & AVG_CYCLES_BITS);

    then the equation should be like below?
    >>>start2stop[n] = norm_lsb * (meas_result_regrs[0] - meas_result_regrs[2*(n+1)]) +
    tdc_clk_period * (( meas_result_regrs[2*(n+1)-1]) >> (int16_t)log2(avg_count) );

    For ex. If I choose 8 Measurement Cycles , so avg_count = 24(decimal) as per datasheet. and log2(24) nearly equal to 4.58. But for 8 Measurement Cycles, I required right shift by 3.

    Thanks,
    Khushbu
  • Khusbu,

    No need to change avg_count. Use

    >>>avg_count = (cnfg2 & AVG_CYCLES_BITS) >> 0x03;

    and you still have to shift right the clock_count result (but no log2 needed) as shown below
    >>>start2stop[n] = norm_lsb * (meas_result_regrs[0] - meas_result_regrs[2*(n+1)]) +
    tdc_clk_period * (( meas_result_regrs[2*(n+1)-1]) >> (int16_t)(avg_count) );

    Thanks,
    Vishy