From: kyz Date: Mon, 15 Jul 2024 03:27:29 +0000 (+0800) Subject: 增加电流互感器可选择功能 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=b7f09d39143800fcb8f0510cf09422f3e0a2beeb;p=yn%2Fweldingcontroller.git 增加电流互感器可选择功能 --- diff --git a/tools_v2/test.py b/tools_v2/test.py index 5805897..5c2f43b 100644 --- a/tools_v2/test.py +++ b/tools_v2/test.py @@ -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 ) ) ) diff --git a/tools_v2/test.ui b/tools_v2/test.ui index 7fce658..536354e 100644 --- a/tools_v2/test.ui +++ b/tools_v2/test.ui @@ -205,7 +205,7 @@ - 2 + 3 @@ -2823,6 +2823,97 @@ + + + + 20 + 660 + 421 + 101 + + + + 传感器选择 + + + + + 20 + 40 + 71 + 31 + + + + 电流互感器 + + + + + + 320 + 20 + 81 + 71 + + + + 写入 + + + + + + 240 + 20 + 81 + 71 + + + + 读取 + + + + + + 100 + 40 + 131 + 31 + + + + false + + + false + + + true + + + + 默认值 + + + + + 400A 2.5 +/- 0.625V + + + + + 400A 2.5 +/- 2.0V + + + + + 600A 2.5 +/- 0.625V + + + + diff --git a/user/user.h b/user/user.h index ec8d07f..7df0dbf 100644 --- a/user/user.h +++ b/user/user.h @@ -33,6 +33,13 @@ #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; diff --git a/user/user_adc.c b/user/user_adc.c index f6a1f7b..af6d3c4 100644 --- a/user/user_adc.c +++ b/user/user_adc.c @@ -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 ){ diff --git a/user/user_app.c b/user/user_app.c index 8caf5c0..5b3cef9 100644 --- a/user/user_app.c +++ b/user/user_app.c @@ -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; } diff --git a/user/user_cdc_rx_2.c b/user/user_cdc_rx_2.c index bdebe98..8595457 100644 --- a/user/user_cdc_rx_2.c +++ b/user/user_cdc_rx_2.c @@ -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 );