Explorar el Código

1、lcd_drv.c文件LCD_DispFloat函数去掉+0.5的补偿,解决流速显示偏大问题
2、main.c中恢复非空管时RTC中断为0.5秒每次
3、tdc_ms1030.c修改CYCLE_TOF由0变1,UP和DOWN发波间隔由5ms变为10ms
4、tof_isr.c中新增检表模式下采集频次每秒40次(每0.5秒20次)

yw hace 2 semanas
padre
commit
cd54008265
Se han modificado 4 ficheros con 31 adiciones y 61 borrados
  1. 3 2
      Drivers/Board/lcd_drv.c
  2. 2 1
      Users/main.c
  3. 1 1
      Users/tdc_tof/tdc_ms1030.c
  4. 25 57
      Users/tdc_tof/tof_isr.c

+ 3 - 2
Drivers/Board/lcd_drv.c

@@ -293,8 +293,9 @@ void LCD_DispFloat(float val, uint8_t pos, uint8_t dl, uint8_t il)
         val *= 10;
     }
 
-    Tu32 = (uint32_t)(val + 0.5f);
-    
+    //Tu32 = (uint32_t)(val + 0.5f);
+    Tu32 = (uint32_t)(val);//modified by yuewei 261023
+
     if(Tu32<1)
     {
       instant_flow_zero_flag=1;

+ 2 - 1
Users/main.c

@@ -145,7 +145,7 @@ void PeriodProc(void) // 
             // 不是空管,设置RTC中断0.5秒1次
             if ((get_rtc_interrupt_time() == 2) || (get_rtc_interrupt_time() == 1))
             {
-                set_rtc_interrupt_time(1); // 0.5
+                set_rtc_interrupt_time(0.5); // 0.5
 //							  c_step=1;
             }
         }
@@ -378,6 +378,7 @@ static void tdc_business_thread(void *parameter)
 #ifdef DEBUG_TDC
             LOG("Diff=%.6f, AvgDiff=%.6f, T=%.6f, vol=%.6f\n", SerPlot.f.Data[0], SerPlot.f.Data[3], WaterPrmt[0], FlowVol * 0.000001f * 3600);
             // LOG("diff=%.6f, U=%.6f, D=%.6f\n", SerPlot.f.Data[0], SerPlot.f.Data[1], SerPlot.f.Data[2]);
+            LOG("----------------CumFlow=%.6f,%.6f\r\n", CumFlow,CumFlow * 0.1);
             rt_thread_mdelay(4);
 #endif
 #endif

+ 1 - 1
Users/tdc_tof/tdc_ms1030.c

@@ -73,7 +73,7 @@
 #define TW2             5   //EN_ANALOG = 1,给STOP 端口的电容充电时间,0=60μs,1=120μs,2=180μs,3=240μs,4=300μs
 #define EN_PEAK         0   //峰值检波使能,0:不使能
 #define EN_DISCHARGE    0   //检波放电使能,0:不使能
-#define CYCLE_TOF       0   //顺流逆流自动检测模式下,顺流逆流测量间隔时间,0=0.25×HZ60(20ms@50Hz),5ms
+#define CYCLE_TOF       1   //顺流逆流自动检测模式下,顺流逆流测量间隔时间,0=0.25×HZ60(20ms@50Hz),5ms
 #define EN_ERR_VAL      1   //溢出时 ALU 写入全 F 到第一个 STOP 结果寄存器与累加和结果寄存器,1=开启
 #define EN_DC           1   //stop端口充电模式;0=交流模式,1=直流模式
 #define FIRE0_DEF       1   //非工作情况下 FIRE 通道的默认状态; 0=高阻(数字模式),1=低(模拟模式)

+ 25 - 57
Users/tdc_tof/tof_isr.c

@@ -1,7 +1,7 @@
-
 #include "board.h"
 #include "tdc_tof.h"
 #include "alarm.h"
+#include "check.h"
 
 #define TOF_PWFW_DIFF ((uint16_t)(0x1620u * 25 / 100))
 #define TOF_PWFW_LOW ((uint16_t)(0x1620u * 40 / 100))
@@ -15,7 +15,7 @@ uint32_t CntErrEvent = 0;
 uint8_t TdcIntStep = 0xFFu;
 
 uint8_t TDC_SAMPLE_CNT = 0;//add by yuewei 261014 to count the tdc sample times
-uint8_t TDC_SAMPLE_TIMES_PER_SECOND = 1;//add by yuewei 261014 to define tdc sample times per 1 second
+uint8_t TDC_SAMPLE_TIMES_PER_RTC_INT = 1;//add by yuewei 261014 to define tdc sample times per RTC INT
 
 float SumToF;
 float LastSumToF;
@@ -84,7 +84,7 @@ void set_tdc_int_step(uint8_t int_step)
 
 // 可调滤波参数
 #define BUF_SIZE            5       // 窗口大小
-#define LPF_ALPHA           0.20f   // 一阶低通系数
+#define LPF_ALPHA           1.0f   // 一阶低通系数
 #define TOF_MAX_CHANNELS    1
 typedef struct
 {
@@ -232,7 +232,8 @@ void read_tof_and_convert_to_flow(void)
         }
         if(alarm_status(ERR_BLANK_PIPE))
         {
-            tdc_turn_on_off_high_clk(0);
+            tdc_turn_on_off_high_clk(0);//关闭MS1030高频时钟,降低功耗
+            TDC_SAMPLE_TIMES_PER_RTC_INT = 1;//每次RTC中断采集1次数据,空管情况下2秒1次中断
         }
         return;
     }
@@ -264,76 +265,43 @@ void read_tof_and_convert_to_flow(void)
     if (tof_state & (TOF_ST_METER | TOF_ST_CALIB))
     {
         DiffToFAvg += (DiffToF - DiffToFAvg) * (1.0f / 20);
-        DiffToFAvg2 += (DiffToF - DiffToFAvg2) * (1.0f / 2);
-        DiffToFAvg128 += (DiffToF - DiffToFAvg128) * (1.0f / 128);
-        
-        if (tof_flag & TOF_FLAG_VALID_FLOW)
+
+        if (fabsf(DiffToFAvg) > 0.45f)
         {
-            if (fabsf(DiffToFAvg) < 0.35f)
+            tof_flag |= TOF_FLAG_VALID_FLOW;
+            if(GetCheckState() == CHECKING)
             {
-                tof_flag &= ~TOF_FLAG_VALID_FLOW;
-                if (tof_state & TOF_ST_CALIB && CalibTime > CALIB_TIME_LTH)
-                {
-                    tof_flag |= TOF_FLAG_CALIB_DONE;
-                }
+                TDC_SAMPLE_TIMES_PER_RTC_INT = 20;//add by yuewei 261023,有水检定模式->流采集频次0.5秒20次
+            }
+            else
+            {
+                TDC_SAMPLE_TIMES_PER_RTC_INT = 3;//add by yuewei 261015,有水大于始动流量->流采集频次0.5秒3次
             }
         }
         else
         {
-            // modified by yuewei 20260519,加入n值,始动流量
-            // if (fabsf(DiffToFAvg) > 0.45f || fabsf(DiffToFAvg2) > 1.0f)
-            if (fabsf(DiffToFAvg * 100.00f) > Paramx.n || fabsf(DiffToFAvg2) > 1.0f)
+            tof_flag &= ~TOF_FLAG_VALID_FLOW;
+            if(GetCheckState() == CHECKING)
             {
-                tof_flag |= TOF_FLAG_VALID_FLOW;
-                TDC_SAMPLE_TIMES_PER_SECOND = 6;//add by yuewei 261015,有水大于始动流量->流采集频次1秒6次
+                TDC_SAMPLE_TIMES_PER_RTC_INT = 20;//add by yuewei 261023,有水检定模式->流采集频次0.5秒20次
             }
             else
             {
-                tof_flag &= ~TOF_FLAG_VALID_FLOW;
-                TDC_SAMPLE_TIMES_PER_SECOND = 2;//add by yuewei 261015,有水小于始动流量->流采集频次1秒2次
+                TDC_SAMPLE_TIMES_PER_RTC_INT = 1;//add by yuewei 261015,有水小于始动流量->流采集频次0.5秒1次
             }
         }
 
         // 是有效的流量
         if (tof_flag & TOF_FLAG_VALID_FLOW)
         {
-            TmpFloat = DiffToF * UsonicSpd * UsonicSpd * 0.00001f;
 
-            // 一次校准模式
-            if (tof_state & TOF_ST_CALIB)
+            // 正常计量模式
+            //DiffToF2Flow(DiffToF);
+            //add by yuewei 261015,当采集次数大于等于TDC_SAMPLE_TIMES_PER_RTC_INT时,才进行流量计算(节约功耗)
+            if(TDC_SAMPLE_CNT >= TDC_SAMPLE_TIMES_PER_RTC_INT)
             {
-                CumFlow += TmpFloat * pTdcItf->pipe_coe;
-                pTdcItf->check_flow(CumFlow, TmpFloat, WaterTemp);
-                if (tof_flag & TOF_FLAG_CALIB_FLOW)
-                {
-                    if (DiffToFAvg2 > 0.5f)
-                    {
-                        CalibSpdLvl += TmpFloat;
-                        CalibTemp += WaterTemp;
-                        CalibTime++;
-                    }
-                    else
-                    {
-                        tof_flag &= ~TOF_FLAG_CALIB_FLOW;
-                        if (CalibTime > CALIB_TIME_LTH)
-                        {
-                            CalibSpdLvl /= CalibTime;
-                            CalibTemp /= CalibTime;
-                            tof_flag |= TOF_FLAG_CALIB_FALL;
-                        }
-                    }
-                }
-            }
-            else
-            {
-                // 正常计量模式
-                //DiffToF2Flow(DiffToF);
-                //add by yuewei 261015,当采集次数大于等于TDC_SAMPLE_TIMES_PER_SECOND时,才进行流量计算(节约功耗)
-                if(TDC_SAMPLE_CNT >= TDC_SAMPLE_TIMES_PER_SECOND)
-                {
-                    DiffToF2Flow(DiffToFAvg);
-                } 
-            }
+                DiffToF2Flow(DiffToFAvg);
+            } 
         }
         else
         {
@@ -372,7 +340,7 @@ void tof_isr_convert_tof_to_flow(void)
         TDC_SAMPLE_CNT++;
         tdc_read_tof(TDC_CFG_DO_CKENA | TDC_CFG_DO_CKDIS);
         read_tof_and_convert_to_flow();
-        if(TDC_SAMPLE_CNT >= TDC_SAMPLE_TIMES_PER_SECOND)
+        if(TDC_SAMPLE_CNT >= TDC_SAMPLE_TIMES_PER_RTC_INT)
         {
             TdcIntStep = 0xFFu;
             TDC_SAMPLE_CNT = 0;