TDC7200数据手册:https://www.ti.com/cn/lit/ds/symlink/tdc7200.pdf?ts=1708671736079&ref_url=https%253A%252F%252Fso.szlcsc.com%252F
TDC7200硬件电路:
TDC7200驱动程序,TDC7200有两种模式,使用的是模式2
模拟SPI:
SPI写数据:
void SPI_Write_Byte(uint8_t data)
{
uint8_t i = 0;
SPI_CLK_H;
for( i=0 ; i<8 ; i++)
{
SPI_CLK_L;
if(data & 0x80)
SPI_DOUT_H;
else
SPI_DOUT_L;
data <<= 1;
SPI_CLK_H;
}
}
SPI读数据:
uint8_t SPI_Read_Data( void )
{
uint8_t data = 0;
uint8_t i = 0;
SPI_CLK_H;
for( i=0 ; i<8 ; i++)
{
SPI_CLK_L;
data <<= 1;
if(SPI_DIN )
data++;
SPI_CLK_H;
}
return data;
}
写TDC7200配置寄存器:
void TDC7200_Write(uint8_t addr , uint8_t data)
{
SPI_CS_L;
SPI_Write_Byte(addr);
SPI_Write_Byte(data);
SPI_CS_H;
}
读TDC7200数据寄存器:
uint32_t TDC7200_Read(uint8_t addr)
{
uint32_t readdata;
uint8_t read[3];
SPI_CS_L;
SPI_Write_Byte(addr);
read[0] = SPI_Read_Data();
read[1] = SPI_Read_Data();
read[2] = SPI_Read_Data();
SPI_CS_H;
readdata = read[0] << 16 | read[1] << 8 | read[2];
return readdata;
}
TDC7200初始化:
void TDC7200_Init(void)
{
TDC7200_Write(ADDR_CONFIG1 , DATA_CONFIG1 );
int_data[0]=TDC7200_Read_ADDR(0x00);
TDC7200_Write(ADDR_CONFIG2 , DATA_CONFIG2 );
int_data[1]=TDC7200_Read_ADDR(0x01);
TDC7200_Write(ADDR_INT_MASK , DATA_INT_MASK );
int_data[3]=TDC7200_Read_ADDR(0x03);
TDC7200_Write(ADDR_CONFIG1 , DATA_CONFIG1_Start );
int_data[0]=TDC7200_Read_ADDR(0x00);
}
TDC7200读寄存器数据:
void TDC_Write_Readtest(void)
{
TDC_Time1 = TDC7200_Read( ADDR_TIME1_Measured );
TDC_Clock_Conunt1 = TDC7200_Read( ADDR_CLOCK_COUNT1 );
TDC_Time2 = TDC7200_Read( ADDR_TIME2_Measured );
TDC_Calibration1 = TDC7200_Read( ADDR_CALIBRATION1 );
TDC_Calibration2 = TDC7200_Read( ADDR_CALIBRATION2 );
TDC7200_Write(ADDR_CONFIG1 , DATA_CONFIG1_Start );
read_TDC_Data=TDC7200_Read_ADDR(0x00);
HAL_Delay(1);
}
TDC7200数据计算得出时差值:
void complate(void)
{
CALIBAR_Dif = (float)(TDC_Calibration2 - TDC_Calibration1);
calCount = (double)CALIBAR_Dif /CALIBRATION_PERIODS_D1 ;
normLSB = (double)(Clock_NS / calCount);
Time1_nor = (double)(TDC_Time1 * normLSB);
Time2_nor = (double)(TDC_Time2 * normLSB);
Clockcount = (double)(TDC_Clock_Conunt1 * Clock_NS);
TOF1 = (double)(Clockcount + Time1_nor - Time2_nor);
TDC_TIE_Data = TOF1 * TIE_NS - TIE_DIF;
}