|
@@ -4,7 +4,7 @@
|
|
|
#define ANZ_FIRE 12u//fire发送脉冲数
|
|
#define ANZ_FIRE 12u//fire发送脉冲数
|
|
|
#define DIV_FIRE 3u //内部时钟产生脉冲的分频
|
|
#define DIV_FIRE 3u //内部时钟产生脉冲的分频
|
|
|
#define DIV_CLKHS 0u //高速时钟分频
|
|
#define DIV_CLKHS 0u //高速时钟分频
|
|
|
-#define START_CLKHS 2u //高速启动后测量前晶振启动间隔时间,120us
|
|
|
|
|
|
|
+#define START_CLKHS 2u //高速启动后测量前晶振启动间隔时间,120us;0关闭,1持续开启,2延迟120us后开启
|
|
|
#define NEG_START 0u //start通道边缘
|
|
#define NEG_START 0u //start通道边缘
|
|
|
#define NEG_STOP 0u //stop通道边缘
|
|
#define NEG_STOP 0u //stop通道边缘
|
|
|
#define HITIN 9u //stop预期脉冲数
|
|
#define HITIN 9u //stop预期脉冲数
|
|
@@ -29,7 +29,7 @@
|
|
|
#define EN_INT_ALU 1 //alu中断触发位
|
|
#define EN_INT_ALU 1 //alu中断触发位
|
|
|
#define RFEDGE 0 //stop通道边沿敏感性
|
|
#define RFEDGE 0 //stop通道边沿敏感性
|
|
|
#define UP_DELVAL1 200 //当EN_FIST_WAVE=1时,为第一波屏蔽窗口 BIT12~27 暂未设置
|
|
#define UP_DELVAL1 200 //当EN_FIST_WAVE=1时,为第一波屏蔽窗口 BIT12~27 暂未设置
|
|
|
-#define OFFSET 30 //当en_hc=1时, 62~-64mV 暂未设置
|
|
|
|
|
|
|
+#define OFFSET 0 //当en_hc=1时, 62~-64mV 暂未设置
|
|
|
#define DFLT_WREG1 (( EN_INT_TO<<31) | \
|
|
#define DFLT_WREG1 (( EN_INT_TO<<31) | \
|
|
|
( EN_INT_HIT<<30) | \
|
|
( EN_INT_HIT<<30) | \
|
|
|
( EN_INT_ALU<<29) | \
|
|
( EN_INT_ALU<<29) | \
|
|
@@ -74,14 +74,14 @@
|
|
|
#define EN_ANALOG 1 //模拟测量控制开关
|
|
#define EN_ANALOG 1 //模拟测量控制开关
|
|
|
#define HZ60 0 //顺流测量和逆流测量的时间单位
|
|
#define HZ60 0 //顺流测量和逆流测量的时间单位
|
|
|
#define TCYCLE 1 //温度测量循环时间
|
|
#define TCYCLE 1 //温度测量循环时间
|
|
|
-#define ANZ_FAKE 1 //温度测量热身次数,0:两次热身,1:7次热身
|
|
|
|
|
|
|
+#define ANZ_FAKE 0 //温度测量热身次数,0:两次热身,1:7次热身
|
|
|
#define SEL_ECLK_TMP 1 //选择温度测量内部参考时钟
|
|
#define SEL_ECLK_TMP 1 //选择温度测量内部参考时钟
|
|
|
-#define TW2 4 //120us充电时间,与1030不同
|
|
|
|
|
|
|
+#define TW2 5 //180us充电时间,与1030不同
|
|
|
#define EN_PEAK 0 //峰值检波使能关闭,1030不同
|
|
#define EN_PEAK 0 //峰值检波使能关闭,1030不同
|
|
|
#define EN_DISCHARGE 0 //检波放电使能关闭,1030不同
|
|
#define EN_DISCHARGE 0 //检波放电使能关闭,1030不同
|
|
|
#define CYCLE_TOF 0 //顺流逆流自动检测模式下,顺流逆流测量间隔时间,初步确定为3=20ms 1030不同
|
|
#define CYCLE_TOF 0 //顺流逆流自动检测模式下,顺流逆流测量间隔时间,初步确定为3=20ms 1030不同
|
|
|
#define EN_ERR_VAL 1 //溢出时alu将全f写到结果寄存器
|
|
#define EN_ERR_VAL 1 //溢出时alu将全f写到结果寄存器
|
|
|
-#define EN_DC 0 //stop端口充电模式 这里设置为直流 1030不同
|
|
|
|
|
|
|
+#define EN_DC 1 //stop端口充电模式 这里设置为直流 1030不同
|
|
|
#define FIRE0_DEF 1 //fire通道默认状态,fire通道默认电平
|
|
#define FIRE0_DEF 1 //fire通道默认状态,fire通道默认电平
|
|
|
#define DOUBLE_RES 0 //双精度模式
|
|
#define DOUBLE_RES 0 //双精度模式
|
|
|
#define QUAD_RES 1 //4精度模式
|
|
#define QUAD_RES 1 //4精度模式
|
|
@@ -116,9 +116,9 @@
|
|
|
#define SEL_SRC_CLK (0<<7) //选择高速时钟输入源
|
|
#define SEL_SRC_CLK (0<<7) //选择高速时钟输入源
|
|
|
#define EN_HC (0<<6) //比较器调节步长
|
|
#define EN_HC (0<<6) //比较器调节步长
|
|
|
#define CURR32K (0<<5) //32K晶振功耗设置
|
|
#define CURR32K (0<<5) //32K晶振功耗设置
|
|
|
-#define DIS_Vref (0<<4) //基准电压输出控制
|
|
|
|
|
|
|
+#define DIS_Vref (1<<4) //基准电压输出控制
|
|
|
#define ADJ_LDO_ROUGH (0<<3) //内部LDO输出粗调
|
|
#define ADJ_LDO_ROUGH (0<<3) //内部LDO输出粗调
|
|
|
-#define ADJ_LDO_FINE (4<<0) //内部LDO输出细调
|
|
|
|
|
|
|
+#define ADJ_LDO_FINE (0<<0) //内部LDO输出细调
|
|
|
#define DFLT_WREG6 (DOWN_DELVAL1|SEL_SRC_CLK|EN_HC|CURR32K|DIS_Vref|ADJ_LDO_ROUGH|ADJ_LDO_FINE)
|
|
#define DFLT_WREG6 (DOWN_DELVAL1|SEL_SRC_CLK|EN_HC|CURR32K|DIS_Vref|ADJ_LDO_ROUGH|ADJ_LDO_FINE)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -152,20 +152,6 @@ void tdc_tof_init(void)
|
|
|
tdc_spi_wr_code(0x50);
|
|
tdc_spi_wr_code(0x50);
|
|
|
us_delay(1000); // 1000us > specification(500us)
|
|
us_delay(1000); // 1000us > specification(500us)
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-// tdc_spi_wr_d32(0x80, 0x1818088c); // 修正:SEL_TIMO_MB = 8(合法)
|
|
|
|
|
-// tdc_spi_wr_d32(0x81, 0x00000000);
|
|
|
|
|
-// tdc_spi_wr_d32(0x82, 0x00000000);
|
|
|
|
|
-// tdc_spi_wr_d32(0x83, 0x00000000);
|
|
|
|
|
-// tdc_spi_wr_d32(0x84, 0x46280540);
|
|
|
|
|
-// tdc_spi_wr_d32(0x85, 0x00000000);
|
|
|
|
|
-// tdc_spi_wr_d32(0x86, 0x0000001c);
|
|
|
|
|
-// 修正后的配置
|
|
|
|
|
-
|
|
|
|
|
-// tdc_spi_wr_code(0x70);
|
|
|
|
|
-
|
|
|
|
|
-// uint16_t aa=0;
|
|
|
|
|
-// aa=tdc_spi_rd_d16(0xd0);
|
|
|
|
|
tdc_spi_wr_d32(0x80, DFLT_WREG0);
|
|
tdc_spi_wr_d32(0x80, DFLT_WREG0);
|
|
|
uint32_t read_a0=tdc_spi_rd_d32(0xA0);
|
|
uint32_t read_a0=tdc_spi_rd_d32(0xA0);
|
|
|
read_a0=read_a0&0xFFu;
|
|
read_a0=read_a0&0xFFu;
|
|
@@ -232,15 +218,13 @@ void tdc_start_tof(uint32_t cfg)
|
|
|
|
|
|
|
|
if (cfg & TDC_CFG_DO_WREG){
|
|
if (cfg & TDC_CFG_DO_WREG){
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- // write_reg3
|
|
|
|
|
|
|
|
|
|
- u32tmp = DFLT_WREG3 |
|
|
|
|
|
-// ( 0u<<13) | // measure FW pulse width, 0:on; 1:off
|
|
|
|
|
- (TdcFwOfst<<6); // FW wave_offs, 0:0mv; 1~63:2~126mV; 64~127:-128~-2mV;
|
|
|
|
|
-// if (tof_state&TOF_ST_VOID){
|
|
|
|
|
-// u32tmp |= (1u<<13); // disable FW pulse width to save power
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ u32tmp = (DFLT_WREG3 & ~(1u << 13)) | (TdcFwOfst << 6);
|
|
|
|
|
+ // measure FW pulse width, 0:on; 1:off
|
|
|
|
|
+ // FW wave_offs, 0:0mv; 1~63:2~126mV; 64~127:-128~-2mV;
|
|
|
|
|
+ if (tof_state&TOF_ST_VOID){
|
|
|
|
|
+ u32tmp |= (1u<<13); // disable FW pulse width to save power
|
|
|
|
|
+ }
|
|
|
tdc_spi_wr_d32(0x83, u32tmp);
|
|
tdc_spi_wr_d32(0x83, u32tmp);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -293,13 +277,16 @@ void tdc_read_tof(uint32_t cfg)
|
|
|
|
|
|
|
|
if ((TdcStatus&0x03F0)!=0x0090u){
|
|
if ((TdcStatus&0x03F0)!=0x0090u){
|
|
|
tof_flag |= TOF_FLAG_BLANK_PIPE;
|
|
tof_flag |= TOF_FLAG_BLANK_PIPE;
|
|
|
-// tdc_spi_wr_code(0x70);
|
|
|
|
|
|
|
+ tdc_spi_wr_code(0x70);
|
|
|
|
|
+ tdc_spi_wr_d32(0x80, DFLT_WREG0 & ~(0x07 << 14)); //一旦为空管马上关闭高速晶振,降低功耗
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
TdcUPwFw = tdc_spi_rd_d16(0xd3); // First wave pulse width
|
|
TdcUPwFw = tdc_spi_rd_d16(0xd3); // First wave pulse width
|
|
|
TdcUPwHw = tdc_spi_rd_d16(0xd4); // 1st Hit wave pulse width
|
|
TdcUPwHw = tdc_spi_rd_d16(0xd4); // 1st Hit wave pulse width
|
|
|
|
|
+ TdcDPwFw = tdc_spi_rd_d16(0xd3);
|
|
|
|
|
+ TdcDPwHw = tdc_spi_rd_d16(0xd4);
|
|
|
|
|
|
|
|
// TOF_UP_HITs
|
|
// TOF_UP_HITs
|
|
|
TdcUToF[0] = tdc_spi_rd_d32(0xb8)*(1.0f/8); // average of all
|
|
TdcUToF[0] = tdc_spi_rd_d32(0xb8)*(1.0f/8); // average of all
|
|
@@ -328,9 +315,9 @@ void tdc_start_cal(uint32_t cfg)
|
|
|
// 8*T_32k = 244.140625us
|
|
// 8*T_32k = 244.140625us
|
|
|
if (cfg & TDC_CFG_DO_WREG){
|
|
if (cfg & TDC_CFG_DO_WREG){
|
|
|
// write_reg0
|
|
// write_reg0
|
|
|
- tdc_spi_wr_d32(0x80, DFLT_WREG0 |
|
|
|
|
|
- ( 2u<< 4) // SEL_TIMO_MB, 0:64us; 1:128us; 2:256us; ~ 6:4096us;
|
|
|
|
|
- );
|
|
|
|
|
|
|
+// tdc_spi_wr_d32(0x80, DFLT_WREG0 |
|
|
|
|
|
+// ( 2u<< 4) // SEL_TIMO_MB, 0:64us; 1:128us; 2:256us; ~ 6:4096us;
|
|
|
|
|
+// );
|
|
|
|
|
|
|
|
// write_reg3
|
|
// write_reg3
|
|
|
tdc_spi_wr_d32(0x83, DFLT_WREG3 |
|
|
tdc_spi_wr_d32(0x83, DFLT_WREG3 |
|
|
@@ -366,7 +353,7 @@ void tdc_read_cal(uint32_t cfg)
|
|
|
TdcScale += (244140.625f/TdcCal - TdcScale)*(1.0f/2);
|
|
TdcScale += (244140.625f/TdcCal - TdcScale)*(1.0f/2);
|
|
|
//LOG("----------TdcScale=%.6f\n",TdcScale);
|
|
//LOG("----------TdcScale=%.6f\n",TdcScale);
|
|
|
} else {
|
|
} else {
|
|
|
- tdc_spi_wr_code(0x70);
|
|
|
|
|
|
|
+// tdc_spi_wr_code(0x70);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (cfg & TDC_CFG_DO_CKDIS){
|
|
if (cfg & TDC_CFG_DO_CKDIS){
|
|
@@ -387,14 +374,14 @@ void tdc_start_temp(uint32_t cfg)
|
|
|
if (cfg & TDC_CFG_DO_WREG){
|
|
if (cfg & TDC_CFG_DO_WREG){
|
|
|
|
|
|
|
|
|
|
|
|
|
- tdc_spi_wr_d32(0x80, DFLT_WREG0 |
|
|
|
|
|
- ( 3u<< 6) // SEL_TIMO_MB, 0:64us; 1:128us; 2:256us; 3:512us; ~ 6:4096us;
|
|
|
|
|
- );
|
|
|
|
|
|
|
+// tdc_spi_wr_d32(0x80, DFLT_WREG0 |
|
|
|
|
|
+// ( 3u<< 6) // SEL_TIMO_MB, 0:64us; 1:128us; 2:256us; 3:512us; ~ 6:4096us;
|
|
|
|
|
+// );
|
|
|
|
|
|
|
|
- // write_reg1
|
|
|
|
|
- tdc_spi_wr_d32(0x81, DFLT_WREG1 |
|
|
|
|
|
- ( 0u<< 12) // DELVAL1=0us, format:16.5, time unit:Tref;
|
|
|
|
|
- );
|
|
|
|
|
|
|
+// // write_reg1
|
|
|
|
|
+// tdc_spi_wr_d32(0x81, DFLT_WREG1 |
|
|
|
|
|
+// ( 0u<< 12) // DELVAL1=0us, format:16.5, time unit:Tref;
|
|
|
|
|
+// );
|
|
|
|
|
|
|
|
// write_reg3
|
|
// write_reg3
|
|
|
tdc_spi_wr_d32(0x83, DFLT_WREG3 |
|
|
tdc_spi_wr_d32(0x83, DFLT_WREG3 |
|
|
@@ -411,7 +398,7 @@ void tdc_start_temp(uint32_t cfg)
|
|
|
}
|
|
}
|
|
|
//rt_exit_critical();
|
|
//rt_exit_critical();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+uint8_t temp_error_flag=0;
|
|
|
void tdc_read_temp(uint32_t cfg)
|
|
void tdc_read_temp(uint32_t cfg)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -421,16 +408,17 @@ void tdc_read_temp(uint32_t cfg)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TdcStatus = tdc_spi_rd_d16(0xd0); // status
|
|
TdcStatus = tdc_spi_rd_d16(0xd0); // status
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
TdcPT[0] = tdc_spi_rd_d32(0xd1); // REF 5K +/- 5
|
|
TdcPT[0] = tdc_spi_rd_d32(0xd1); // REF 5K +/- 5
|
|
|
TdcPT[1] = tdc_spi_rd_d32(0xd2); // U7
|
|
TdcPT[1] = tdc_spi_rd_d32(0xd2); // U7
|
|
|
|
|
|
|
|
- if(TdcPT[0]==0xffffffff || TdcPT[1]==0xffffffff || TdcPT[0] ==0x00000000 || TdcPT[0]==0x00000000)
|
|
|
|
|
|
|
+ if(TdcPT[0]==0xffffffff || TdcPT[1]==0xffffffff || TdcPT[0] ==0x00000000 || TdcPT[1]==0x00000000)
|
|
|
{
|
|
{
|
|
|
- TdcResist=0;
|
|
|
|
|
|
|
+ temp_error_flag=1;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
+ temp_error_flag=0;
|
|
|
TdcResist = 2500.0f*TdcPT[1]/TdcPT[0]; // ohmX10
|
|
TdcResist = 2500.0f*TdcPT[1]/TdcPT[0]; // ohmX10
|
|
|
Ohm2Dgr2USSpd(TdcResist, WaterPrmt); // [0]:Temperature; [1]:ultrasonic speed @Temp
|
|
Ohm2Dgr2USSpd(TdcResist, WaterPrmt); // [0]:Temperature; [1]:ultrasonic speed @Temp
|
|
|
}
|
|
}
|
|
@@ -442,3 +430,39 @@ void tdc_read_temp(uint32_t cfg)
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void MS1031_DisableHighSpeedOsc(void)
|
|
|
|
|
+{
|
|
|
|
|
+ PeriClk_MutEnable(PeriClk_Spi1);
|
|
|
|
|
+ DMA_ReqClkOn();
|
|
|
|
|
+
|
|
|
|
|
+ tdc_spi_wr_d32(0x80, DFLT_WREG0 & ~(0x07 << 14)); //一旦为空管马上关闭高速晶振,降低功耗
|
|
|
|
|
+
|
|
|
|
|
+ DMA_ReqClkOff();
|
|
|
|
|
+ PeriClk_MutDisable(PeriClk_Spi1);
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void MS1031_EnableHighSpeedOsc(void)
|
|
|
|
|
+{
|
|
|
|
|
+ PeriClk_MutEnable(PeriClk_Spi1);
|
|
|
|
|
+ DMA_ReqClkOn();
|
|
|
|
|
+
|
|
|
|
|
+ GpioClrPins(GpioPortD, GpioBitMsk2);
|
|
|
|
|
+ us_delay(10);
|
|
|
|
|
+ GpioSetPins(GpioPortD, GpioBitMsk2);
|
|
|
|
|
+ us_delay(10);
|
|
|
|
|
+
|
|
|
|
|
+ tdc_spi_wr_d32(0x80,DFLT_WREG0);
|
|
|
|
|
+ tdc_spi_wr_d32(0x81,DFLT_WREG1);
|
|
|
|
|
+ tdc_spi_wr_d32(0x82,DFLT_WREG2);
|
|
|
|
|
+ tdc_spi_wr_d32(0x83,DFLT_WREG3);
|
|
|
|
|
+ tdc_spi_wr_d32(0x84,DFLT_WREG4);
|
|
|
|
|
+ tdc_spi_wr_d32(0x85,DFLT_WREG5);
|
|
|
|
|
+ tdc_spi_wr_d32(0x86,DFLT_WREG6);
|
|
|
|
|
+ tdc_spi_wr_d32(0x87,0x20000000);//!!!!!!!!do not delete!!!!!!!!!
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ DMA_ReqClkOff();
|
|
|
|
|
+ PeriClk_MutDisable(PeriClk_Spi1);
|
|
|
|
|
+
|
|
|
|
|
+}
|