| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #include <stdint.h>
- #include "board.h"
- #include "tdc_tof.h"
- #include "bill.h"
- #include "check.h"
- #include "param.h"
- #include "alarm.h"
- #include "stat.h"
- // resistence(ohm) from 0 dgree to 55 dgree
- static const uint16_t NTC50KOhmX10Ary[] ={
- 2749, 2633, 2521, 2415, 2314, 2218, 2127, 2040,
- 1956, 1877, 1802, 1729, 1661, 1595, 1532, 1472,
- 1415, 1360, 1308, 1258, 1210, 1164, 1120, 1079,
- 1038, 1000, 963, 928, 894, 862, 831, 801,
- 773, 745, 719, 694, 670, 648, 624, 603,
- 583, 563, 544, 526, 508, 491, 475, 459,
- 444, 430, 416, 403, 390, 377, 365, 354
- };
- // tangent slope from 0 dgree to 55 dgree
- static const float NTC50KSlpAry[] ={
- -0.00855432f, -0.00898473f, -0.00944287f, -0.00991080f, -0.01041667f, -0.01091703f, -0.01146789f, -0.01201923f,
- -0.01261034f, -0.01322751f, -0.01386963f, -0.01451379f, -0.01522070f, -0.01592357f, -0.01666667f, -0.01748252f,
- -0.01824818f, -0.01912046f, -0.02000000f, -0.02096436f, -0.02178649f, -0.02283105f, -0.02392344f, -0.02493766f,
- -0.02604167f, -0.02717391f, -0.02840909f, -0.02967359f, -0.03095975f, -0.03225806f, -0.03355705f, -0.03521127f,
- -0.03649635f, -0.03816794f, -0.03968254f, -0.04149378f, -0.04310345f, -0.04484305f, -0.04672897f, -0.04878049f,
- -0.05076142f, -0.05263158f, -0.05494505f, -0.05681818f, -0.05952381f, -0.06172840f, -0.06410256f, -0.06666667f,
- -0.06944444f, -0.07194245f, -0.07462687f, -0.07751938f, -0.08064516f, -0.08333333f, -0.08771930f, -0.00282486f
- };
- #define NTC50K_SUM (sizeof(NTC50KOhmX10Ary)/sizeof(uint16_t))
- // start temperature of each row(no end temp)
- //modified by yuewei 20260409 start
- //static const float RowTemp_Ary[] = {
- // 5.0f, 15.0f, 25.0f, 35.0f, 45.0f
- //};
- /*
- static const float RowTemp_Ary[] = {
- 10.0f, 15.0f, 25.0f
- };
- */
- //modified by yuewei 20260520 start
- #if 1
- //#define ROW_NUM (sizeof(RowTemp_Ary)/sizeof(float))
- //#define COL_NUM (12)
- const uint16_t Quad_Cell_NUM = 28;
- //Quad_Cell_t Quad_Cell_Ary[ROW_NUM*COL_NUM] =
- Quad_Cell_t Quad_Cell_Ary[28] =
- {
- //温度补偿系数,总共8个温度点
- //格式:{温度, {常数:m, 系数:k}}
- //温度:5C -> 50C
- {5.000000, {0.000000f,0.952426f}},
- {10.000000,{0.000000f,0.966416f}},
- {25.000000,{0.000000f,1.000000f}},
- {30.000000,{0.000000f,1.008647f}},
- {35.000000,{0.000000f,1.016146f}},
- {40.000000,{0.000000f,1.022568f}},
- {45.000000,{0.000000f,1.027991f}},
- {50.000000,{0.000000f,1.032488f}},
- //流速等级补偿系数,总共20个流速点
- //{流速等级, {常数:m, 系数:k}},注意:流速等级如果设置0,则表示没有流量点需要修正
- //第1~10个流速点
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- //第11~20个流速点
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}},
- {0.000000,{0.000000f,0.000000f}}
- };
- #endif
- //modified by yuewei 20260520 end
- double FlowVol = 0.0f;
- double FwCumFlow;
- double BwCumFlow;
- double FlowTestCoe = 1.0f;
- float BwFlowThres = (-1.0f) * (Q1 * 1.6f * 1000.0f * 1000.0f / 3600.0f); //less -Q2
- tdc_itf_t TdcItf = {
- .bw_flow_flag = 0,
- .ch_bit_map = 3,//yw 0->3, 3->15
- .blank_flag = 0,
- .pipe_coe = 0.1168745, //modified by yuewei 20260610 2.288299->0.1168745
- .path_skew = {0.000f, 0.000f, 0.000f, 0.000f},
- .ch_num = 1,
- .mux_ch_no = {0, 1, 2, 3},
- .mux_switch = 1,
- .ntc_num = NTC50K_SUM,
- .ntc_ohm_ary = NTC50KOhmX10Ary,
- .ntc_slp_ary = NTC50KSlpAry,
- //modified by yuewei 20260520 start
- //.row_num = ROW_NUM,
- //.col_num = COL_NUM,
- //.row_temp_ary = RowTemp_Ary,
- //modified by yuewei 20260520 end
-
- .quad_cell_ary = Quad_Cell_Ary,
- .set_blank = set_pipe_blank,
- .clr_blank = clr_pipe_blank,
- .flow_vol = tdc_flow_itf,
- .check_flow = SetCheckFlow
- };
- float var_dtof_buf[180];
- uint32_t test_var_flag = 0;
- uint32_t test_var_cnt = 0;
- #define VAR_TEST_BUF_SIZE (sizeof(var_dtof_buf) / sizeof(var_dtof_buf[0]))
- void test_dtof_var(void) {
- double var = 0;
- double avg = 0;
- int i;
- int cnt = VAR_TEST_BUF_SIZE;
- if (test_var_flag == 0) {
- return;
- }
- var_dtof_buf[test_var_cnt % VAR_TEST_BUF_SIZE] = get_diff_tof();
- test_var_cnt++;
- if (test_var_cnt > cnt) {
- test_var_flag = 0;
- test_var_cnt = 0;
- for (i = 0; i < cnt; i++) {
- avg += var_dtof_buf[i];
- }
- avg /= cnt;
- for (i = 0; i < cnt; i++) {
- var += (var_dtof_buf[i] - avg) * (var_dtof_buf[i] - avg);
- }
- var /= cnt - 1;
- printf("\nThe average of %ds dtof is %lfps\n", cnt, avg * 1000);
- printf("The var of %ds dtof is %lf(unit: 10ps)\n", cnt, var * 10000);
- }
- }
- void tdc_flow_itf(double flow_vol, float tmp_float) {
- FlowVol = flow_vol;
- //add by yuewei 20260519
- float rtc_interrupt_time_seconds = get_rtc_interrupt_time();
- #if defined(CHECK_CORRECT_ENABLE)
- float FlowCorrFactor = CheckFlowCorrectFactor(WaterTemp, (uint16_t)tmp_float);
- FlowVol *= FlowCorrFactor; // unit:cm^3/s = ml/s
- #endif
- //20260429
- //add by yuewei 20260327 start
- //static double last_vol = 0.0f;
- //FlowVol = last_vol * (1.0f - VOL_FILTER_ALPHA) + FlowVol * VOL_FILTER_ALPHA;
- //last_vol = FlowVol;
- //add by yuewei 20260327 end
- //LOG("vol = %.6f\n",FlowVol*0.000001f * 3600);
- //20260429
- /*
- if (FlowVol > BwFlowThres) {
- CumFlow += FlowVol/2;
- TdcItf.bw_flow_flag = 0;
- } else {
- TdcItf.bw_flow_flag = 1;
- }
-
- if (FlowVol >= 0) {
- FwCumFlow += FlowVol/2;
- SetBillVol(FlowVol, 0);
- } else {
- BwCumFlow += (0 - FlowVol/2);
- SetBillVol(0, (0 - FlowVol));
- }
- */
- CumFlow += FlowVol * rtc_interrupt_time_seconds;
-
- if (FlowVol >= 0)
- {
- TdcItf.bw_flow_flag = 0;
- FwCumFlow += FlowVol * rtc_interrupt_time_seconds;
- SetBillVol(FlowVol, 0);
- }
- else
- {
- TdcItf.bw_flow_flag = 1;
- BwCumFlow += (0 - FlowVol * rtc_interrupt_time_seconds);
- SetBillVol(0, (0 - FlowVol));
- }
-
- //modified by yuewei 20260319 start
- //SetBillCumFlow(CumFlow, FwCumFlow, BwCumFlow);
- SetCheckFlow(CumFlow, tmp_float, WaterTemp);
- SetStatFlow(FlowVol);
- //modified by yuewei 20260319 end
- }
- void set_pipe_blank(uint8_t ch) {
- if ((TdcItf.blank_flag & (0x00000001 << ch)) == 0) {
- Alarm(ERR_CH0 + ch, 1, ch);
- }
- if (TdcItf.blank_flag == (TdcItf.ch_bit_map & ~(0x00000001 << ch))) {
- Alarm(ERR_BLANK_PIPE, 1, TdcItf.ch_bit_map);
- }
- TdcItf.blank_flag |= (0x00000001 << ch);
- }
- void clr_pipe_blank(uint8_t ch) {
- if ((TdcItf.blank_flag & (0x00000001 << ch)) != 0) {
- Alarm(ERR_CH0 + ch, 0, ch);
- }
- if (TdcItf.blank_flag == (0x00000001 << ch)) {
- Alarm(ERR_BLANK_PIPE, 0, 0);
- }
- TdcItf.blank_flag &= ~(0x00000001 << ch);
- }
|