增加电流互感器可选择功能
authorkyz <kongyuzhong@google.com>
Mon, 15 Jul 2024 03:27:29 +0000 (11:27 +0800)
committerkyz <kongyuzhong@google.com>
Mon, 29 Jul 2024 01:11:20 +0000 (09:11 +0800)
tools_v2/test.py
tools_v2/test.ui
user/user.h
user/user_adc.c
user/user_app.c
user/user_cdc_rx_2.c

index 5805897644cefa39016f29cda0be20ccb295f3b8..5c2f43bbb88207b5e6fa340d484dc8423d86abf7 100644 (file)
@@ -115,6 +115,10 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         self.btn_gas_read.released.connect( self.on_btn_gas_read )
         self.btn_gas_write.released.connect( self.on_btn_gas_write )
 
+        self.btn_curr_sensor_read.released.connect( self.on_btn_curr_sensor_read )
+        self.btn_curr_sensor_write.released.connect( self.on_btn_curr_sensor_write )
+
+
         self.btn_flow_alarm_read.released.connect( self.on_btn_alarm_read )
         self.btn_flow_alarm_write.released.connect( self.on_btn_alarm_write )
 
@@ -219,7 +223,7 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         self.on_btn_gas_read()
     def on_btn_alarm_write( self ):
         if self.ser_open():
-            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBL", 0xFF, 0xFF, int( 1000*float(self.lineEdit_flow_low_alarm.text() ) ) ) )
+            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBLB", 0xFF, 0xFF, int( 1000*float(self.lineEdit_flow_low_alarm.text() ) ), 0xFF ) )
             self.ser_close()
 
     def on_btn_gas_read( self ):
@@ -228,7 +232,16 @@ class App( QDialog, ui_welding.Ui_Dialog ):
             self.ser_close()
     def on_btn_gas_write( self ):
         if self.ser_open():
-            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBL", self.cb_flow_sel.currentIndex(), self.cb_gas_sel.currentIndex(), 0xFFFFFFFF ) )
+            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBLB", self.cb_flow_sel.currentIndex(), self.cb_gas_sel.currentIndex(), 0xFFFFFFFF, 0xFF ) )
+            self.ser_close()
+
+    def on_btn_curr_sensor_read( self ):
+        if self.ser_open():
+            self.tx_cmd( cmd = 0xC0 )
+            self.ser_close()
+    def on_btn_curr_sensor_write( self ):
+        if self.ser_open():
+            self.tx_cmd( cmd = 0xC1, data=struct.pack( ">BBLB", 0xFF, 0xFF, 0xFFFFFFFF, self.cb_curr_sensor_sel.currentIndex() ) )
             self.ser_close()
 
     def on_btn_rpt_period_read( self ):
@@ -724,10 +737,13 @@ class App( QDialog, ui_welding.Ui_Dialog ):
         elif cmd == 0x00BE and len(data)==4: #上报周期读取
             self.lineEdit_rpt_period.setText(  str( struct.unpack( '>L', data )[0] ) )
         elif cmd == 0x00C0 and len(data)>=2: #读取参数2
-            flow, gas, alarm_x1000 = struct.unpack( ">BBL", data )
+            flow, gas, alarm_x1000 = struct.unpack( ">BBL", data[:6] )
             self.cb_flow_sel.setCurrentIndex( flow )
             self.cb_gas_sel.setCurrentIndex( gas )
             self.lineEdit_flow_low_alarm.setText( "%.1f"%(alarm_x1000/1000))
+            if len( data)>=7:
+                curr_sensor = struct.unpack( ">B", data[6:7])[0]
+                self.cb_curr_sensor_sel.setCurrentIndex( curr_sensor )
         elif cmd == 0x00C2 and len(data)>=4: #读取参数2
             t = struct.unpack( ">L", data[:4])[0]
             self.label_rtc.setText( time.strftime( "%Y/%m/%d-%H:%M:%S", time.localtime( t ) ) )
index 7fce658e253175963c014be6957df51da61de724..536354e36da13f3565c2ee8403d1f56ca0c1b5bb 100644 (file)
      </rect>
     </property>
     <property name="currentIndex">
-     <number>2</number>
+     <number>3</number>
     </property>
     <widget class="QWidget" name="tab">
      <attribute name="title">
          </property>
         </widget>
        </widget>
+       <widget class="QGroupBox" name="groupBox_25">
+        <property name="geometry">
+         <rect>
+          <x>20</x>
+          <y>660</y>
+          <width>421</width>
+          <height>101</height>
+         </rect>
+        </property>
+        <property name="title">
+         <string>传感器选择</string>
+        </property>
+        <widget class="QLabel" name="label_38">
+         <property name="geometry">
+          <rect>
+           <x>20</x>
+           <y>40</y>
+           <width>71</width>
+           <height>31</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>电流互感器</string>
+         </property>
+        </widget>
+        <widget class="QPushButton" name="btn_curr_sensor_write">
+         <property name="geometry">
+          <rect>
+           <x>320</x>
+           <y>20</y>
+           <width>81</width>
+           <height>71</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>写入</string>
+         </property>
+        </widget>
+        <widget class="QPushButton" name="btn_curr_sensor_read">
+         <property name="geometry">
+          <rect>
+           <x>240</x>
+           <y>20</y>
+           <width>81</width>
+           <height>71</height>
+          </rect>
+         </property>
+         <property name="text">
+          <string>读取</string>
+         </property>
+        </widget>
+        <widget class="QComboBox" name="cb_curr_sensor_sel">
+         <property name="geometry">
+          <rect>
+           <x>100</x>
+           <y>40</y>
+           <width>131</width>
+           <height>31</height>
+          </rect>
+         </property>
+         <property name="editable">
+          <bool>false</bool>
+         </property>
+         <property name="duplicatesEnabled">
+          <bool>false</bool>
+         </property>
+         <property name="frame">
+          <bool>true</bool>
+         </property>
+         <item>
+          <property name="text">
+           <string>默认值</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>400A 2.5 +/- 0.625V</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>400A 2.5 +/- 2.0V</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>600A 2.5 +/- 0.625V</string>
+          </property>
+         </item>
+        </widget>
+       </widget>
       </widget>
      </widget>
     </widget>
index ec8d07f5c1e181d9f0e9144325396ac78b1a5565..7df0dbfaa80667dd4c018a69325110d004533ca5 100644 (file)
 #define HW_V3  3
 #define HW_V4  4
 
+//电流互感器类型配置
+#define CURR_SENSOR_DEFAULT    0   //默认值, 按照主板硬件版本, 串口屏版本为 400A/ 2.5V+/-0.625V类型, 断码屏版本为400A 2.5V+/-2.0V
+#define CURR_SENSOR_400A_625   1   //400A -- 2.5V+/-0.625V
+#define CURR_SENSOR_400A_2000  2   //400A -- 2.5V+/-2.000V
+#define CURR_SENSOR_600A_625   3   //600A -- 2.5V+/-0.625V
+#define CURR_SENSOR_NR         4   //4种类型
+
 #define  FLOW_SPEED_FS         50   //流量计满量程50L/min
 #define  PRESSURE_KPA_FS       700  //气压最大量程 700Kpa
 
@@ -177,7 +184,8 @@ typedef struct{
        uint32_t offline_max_time;   //0:离线不锁定; >0:允许离线时间 秒   //使用RTC获取时间
        uint32_t offline_start_time; //0:未开始计时; >0:离线开始时间点 秒 //使用RTC获取时间
        uint32_t fix_flow_x10;  //固定流量值单位0.1L, 大于0 小于50L,焊接时忽略焊接电流,固定按这个值供气。
-       uint8_t reserved[12];
+       uint8_t  curr_sensor;  //电流互感器类型
+       uint8_t reserved[11];
        uint8_t flag;
 }dev_cfg_v2_t;
 
index f6a1f7b7e0d1c98763b0f188dd6452a1cc973cf5..af6d3c4e471645c314d092278318f124a96f2c28 100644 (file)
@@ -199,6 +199,57 @@ float vol_to_speed( float vol )
     return speed;
 }
 
+float vol_to_curr( float vol )
+{
+    uint8_t sensor;
+    float v_base = 2.5f; //2.5v
+    float v_range = 0.625; //0.625v /2.0v
+    uint32_t curr_max  = 400; //400A
+       float curr;
+
+    if( g_dev.cfg2.curr_sensor == CURR_SENSOR_DEFAULT ){
+        if( g_dev.hw_ver == HW_V2 ){
+            sensor = CURR_SENSOR_400A_625;
+        }else{
+            sensor = CURR_SENSOR_400A_2000;
+        }
+    }else{
+        sensor = g_dev.cfg2.curr_sensor;
+    }
+    
+    if( sensor== CURR_SENSOR_400A_2000 ){
+        v_range = 2.0f;
+        curr_max = 400;        
+    }else if( sensor== CURR_SENSOR_400A_625 ){
+        v_range = 0.625f;
+        curr_max = 400;
+    }else if( sensor== CURR_SENSOR_600A_625 ){
+        v_range = 0.625f;
+        curr_max = 600;
+    }
+    curr = curr_max * ( vol - v_base)/v_range;
+    return curr;
+}
+
+int32_t  is_curr_valid( float curr )
+{
+    uint8_t sensor;
+       uint32_t curr_max;
+
+    if( g_dev.cfg2.curr_sensor== CURR_SENSOR_600A_625 ){
+        curr_max = 600;
+    }else{
+               curr_max = 400;
+       }
+
+       if( curr > - curr &&  curr < curr_max+100 ){
+               return 1;
+       }else{
+               return 0;
+       }
+
+}
+
 void user_adc_task( void* unused )
 {
     uint32_t raw;
@@ -282,7 +333,7 @@ void user_adc_task( void* unused )
          if( uxBits & EVENT_ADC2_UPDATE ){
             //电流互感器 ADC2
             HAL_ADC_Start_DMA( &hadc2, (uint32_t*)&adc2_raw[0], ADC2_RAW_NRS );
-
+#if 0
             if( g_dev.hw_ver == HW_V2 ){
                 //HW_V2 互感器输出 400A -- 2.5V +/-0.625V
                 for( int32_t i=0; i< ADC2_RAW_NRS; i++ )
@@ -294,7 +345,12 @@ void user_adc_task( void* unused )
                                //额定输入  Ipn = 400A, 测量范围 Ipm = pn*1.2, //电流  = (V-2.5)/0.625 * Ipn
                 for( int32_t i=0; i< ADC2_RAW_NRS; i++ )
                     adc2_curr[i] = (adc2_raw_copy[i] * VREF*2/0xffff - 2.5f)/2.000f*400;
+
              }
+#else
+            for( int32_t i=0; i< ADC2_RAW_NRS; i++ )
+                adc2_curr[i] = vol_to_curr( adc2_raw_copy[i] * VREF*2/0xffff );
+#endif
 
             if( g_dev.debug_report == 2 ){   //发送调试数据到pc,
                 extern uint32_t dbg_report_raw_current;
@@ -327,7 +383,9 @@ void user_adc_task( void* unused )
                 g_dev.welding_current = 0;
             }
 
-            if( g_dev.welding_current < -400 || g_dev.welding_current > 500 ){ //HW_V4的互感器不接读数为-470A,HW_V2的互感器不接读数-590A
+            //if( g_dev.welding_current < -400 || g_dev.welding_current > 500 ) //HW_V4的互感器不接读数为-470A,HW_V2的互感器不接读数-590A
+                       if( !is_curr_valid( g_dev.welding_current ) )
+                       {
                 //HW_V2传感器输出范围  2.5-0.65 到2.5+0.65
                                //HW_V4传感器输出范围  2.5-2.00 到2.5+2.00
                 if( curr_err > 10 ){
index 8caf5c0086a89b3d808b57bfefb5d528f0dfdd02..5b3cef9a515d56b6e82fd2e1b80a2d7e003a6c71 100644 (file)
@@ -338,6 +338,9 @@ int32_t dev_cfg_v2_load( dev_cfg_v2_t *cfg )
        if( cfg->fix_flow_x10 > 500 ){
                cfg->fix_flow_x10 = 0;
        }
+    if( cfg->curr_sensor >= CURR_SENSOR_NR  ){
+        cfg->curr_sensor = CURR_SENSOR_DEFAULT;
+    }
     return 0;
 }
 
index bdebe984cfe87c5a10b5fb2bf1d8084fc8054521..859545787e751aa3ed00f7d766b1f648570fbbb6 100644 (file)
@@ -627,16 +627,19 @@ int32_t handle_cdc_pkt( cdc_pkt_t *pkt )
         case 0xC0: //参数v2 读取  -- 流量计选择1B 气体1B, 流量低报阈值 4B...
             resp[0] = g_dev.cfg2.flowmeter;
             resp[1] = g_dev.cfg2.gas;
-                                               put_u32_big( &resp[2], g_dev.cfg2.flow_low_alarm_x1000 );
-            tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 6 );
+                       put_u32_big( &resp[2], g_dev.cfg2.flow_low_alarm_x1000 );
+                       resp[6] = g_dev.cfg2.curr_sensor;
+            tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 7 );
             break;
         case 0xC1: //参数v2 写入 -- 流量计选择1B,气体选择1B 流量低报阈值 4B -- ... 
             if( pkt->pdata[0] <= FLOWMETER_MAX )
                 g_dev.cfg2.flowmeter = pkt->pdata[0];
             if( pkt->pdata[1] <= GAS_MAX )
                 g_dev.cfg2.gas = pkt->pdata[1];
-                                               if( get_u32_big( &pkt->pdata[2] ) != 0xFFFFFFFF )
-                                                         g_dev.cfg2.flow_low_alarm_x1000 = get_u32_big( &pkt->pdata[2] );
+            if( get_u32_big( &pkt->pdata[2] ) != 0xFFFFFFFF )
+                g_dev.cfg2.flow_low_alarm_x1000 = get_u32_big( &pkt->pdata[2] );
+            if( pkt->pdata[6] < CURR_SENSOR_NR )
+                g_dev.cfg2.curr_sensor = pkt->pdata[6];
             dev_cfg_v2_store( &g_dev.cfg2 );
             resp[0] = 1;
             tx_n = wrap_resp_pkt( tx_pkt, pkt->cmd, resp, 1 );