S7-1500 读取V90/S120/S210/G120的常用驱动参数

S7-1500 读取V90/S120的常用驱动参数

此程序已更新,可以下载例子程序

https://files.cnblogs.com/files/lion-zheng/PLC_async_drive.zip

1

不需要理解非周期通讯,调用这个FB就可以读取常用的驱动状态,程序块已经封装了非周期通讯功能。

故障代码、报警代码、扭矩、电流、直流母线电压、电机温度、驱动器温度
功率、转速

本文地址
http://www.cnblogs.com/lion-zheng/p/7853852.html

非周期通讯参考资料可在在西门子中文下载中心 搜索 非周期
http://www.ad.siemens.com.cn/download/

2

此功能块的输入管脚

name type datatype description
Hardware_ID in HW_IO Profinet/Profibus网络标识ID *
Drive_Number in int V90/CU310 = 1, G120 = 2
Pulse in bool 连接5HZ或2.5HZ的脉冲信号
V90 in bool 区分驱动类型,V90 = 1, cu310 = 0

*HardwareID是以上参数中比较特别的一个,可以在TIA portal的Device configuration中找到。
如果一个设备有两个HardwareID,那么很可能,两个都可以用。

HardwareID也可以在TIA portal的Tags -> Default tag table -> System constants 中找到。

功能块的输出管脚

name type datatype description
FaultNumber out DINT 故障代码
AlarmNumber out DINT 报警代码
ActualTorque out real 扭矩
ActualCurrent out real 电流
DCvoltage out real 直流母线电压
MotorTemp out real 电机温度
DriveTemp out real 驱动器温度
ActualPower out real 电机实际功率
ActualRPM out real 电机实际转速

功能块的调用效果,2个V90,1个CU310,可见只有HardwareID管脚略有不同

至此为止,你应该已经知道了此FB的功能和使用方法。下文是一些程序内部实现的细节。

3

在编写此程序块时,发现一个 WRREC 和 RDREC 程序块的特点。
当我们读取参数时,需要先调用WRREC来发送命令给驱动器,WRREC会返回Done信号。然而这个Done信号只保证了发送完成,并无法确认驱动已经准备好。因此我们需要延时一段时间,等待驱动准备好数据。V90需要大约50ms,S120需要30ms。延时后,再调用RDREC。发现此问题感谢我们的朋友 @内存1KB 的提醒。

1)正确的状态,WRREC之后,立即发送RDREC,出现故障

  1. 正确的时序,WRREC之后,延时50ms,再发送RDREC,没有故障

4

程序的细节

  • 定义报文头
  • 定义每一个需要读取的参数
  • 调用WRREC
  • 延时,并调用RDREC
  • 输出变量到FB接口

//Telegram head
#write_record[0] := #task;
#write_record[1] := 01;//01 read-task, 02 write-task
#write_record[2] := INT_TO_BYTE(#Drive_Number);
#write_record[3] := 16#9;//number of parameter

//Parameter1 r2131 (16#853) fault number
#write_record[4] := 16#10;
#write_record[5] := 16#01;//number of index
#write_record[6] := 16#8;//parameter number
#write_record[7] := 16#53;//parameter number
#write_record[8] := 16#0;//first index number = 0
#write_record[9] := 16#0;//first index number = 0

//Parameter2 r2132 (16#854) alarm number
#write_record[10] := 16#10;
#write_record[11] := 16#01;//number of index
#write_record[12] := 16#8;//parameter number
#write_record[13] := 16#54;//parameter number
#write_record[14] := 16#0;//first index number = 0
#write_record[15] := 16#0;//first index number = 0

//Parameter3 r31 (16#1F) actual torque smoothed
#write_record[16] := 16#10;
#write_record[17] := 16#01;//number of index
#write_record[18] := 16#0;//parameter number
#write_record[19] := 16#1F;//parameter number
#write_record[20] := 16#0;//first index number = 0
#write_record[21] := 16#0;//first index number = 0

//Parameter4 r26 (16#1A) DC voltage smoothed
#write_record[22] := 16#10;
#write_record[23] := 16#01;//number of index
#write_record[24] := 16#0;//parameter number
#write_record[25] := 16#1A;//parameter number
#write_record[26] := 16#0;//first index number = 0
#write_record[27] := 16#0;//first index number = 0

//Parameter5 r27 (16#1B) ActualCurrent
#write_record[28] := 16#10;
#write_record[29] := 16#01;//number of index
#write_record[30] := 16#0;//parameter number
#write_record[31] := 16#1B;//parameter number
#write_record[32] := 16#0;//first index number = 0
#write_record[33] := 16#0;//first index number = 0

//Parameter6 r21 (16#15) ActualRpm
#write_record[34] := 16#10;
#write_record[35] := 16#01;//number of index
#write_record[36] := 16#0;//parameter number
#write_record[37] := 16#15;//parameter number
#write_record[38] := 16#0;//first index number = 0
#write_record[39] := 16#0;//first index number = 0

//Parameter7 r32 (16#20) ActualPower
#write_record[40] := 16#10;
#write_record[41] := 16#01;//number of index
#write_record[42] := 16#0;//parameter number
#write_record[43] := 16#20;//parameter number
#write_record[44] := 16#0;//first index number = 0
#write_record[45] := 16#0;//first index number = 0

//Parameter8 r35 (16#23) MotorTemp
//Parameter8 r632 (16#278)
#write_record[46] := 16#10;
#write_record[47] := 16#01;//number of index
IF #v90 THEN
    #write_record[48] := 16#2;//parameter number
    #write_record[49] := 16#78;//parameter number
ELSE
    #write_record[48] := 16#0;//parameter number
    #write_record[49] := 16#23;//parameter number
END_IF;
#write_record[50] := 16#0;//first index number = 0
#write_record[51] := 16#0;//first index number = 0

//Parameter9 r37 (16#25) DriveTemp
#write_record[52] := 16#10;
#write_record[53] := 16#01;//number of index
#write_record[54] := 16#0;//parameter number
#write_record[55] := 16#25;//parameter number
#write_record[56] := 16#0;//first index number = 0
#write_record[57] := 16#0;//first index number = 0

#R_TRIG_Instance(CLK:=#Pulse);
#WRREC_REQ := #R_TRIG_Instance.Q AND NOT #WRREC_BUSY AND NOT #REREC_BUSY;

#WRREC_Instance(REQ:=#WRREC_REQ,
                ID:=#Hardware_ID,
                INDEX:=47,
                DONE=>#WRREC_DONE,
                BUSY=>#WRREC_BUSY,
                ERROR=>#WRREC_ERROR,
                STATUS=>#WRREC_STATUS,
                RECORD:= #write_record);

#IEC_Timer_0_Instance(IN := #Pulse,
                      PT := T#100MS);

//#R_TRIG_Instance_1(CLK := #IEC_Timer_0_Instance.Q,
//                   Q => #REREC_REQ);

#REREC_REQ := #WRREC_DONE;
#RDREC_Instance(REQ:= #REREC_REQ,
                ID:= #Hardware_ID,
                INDEX:= 47,
                VALID=> #REREC_VALID,
                BUSY=> #REREC_BUSY,
                ERROR=> #REREC_ERROR,
                STATUS=> #REREC_STATUS,
                RECORD:= #read_record);

    //byte 0,1,2,3 telegram head
    
    //byte 4,5,6,7 ,parameter 1 ,r2131,fault code
    "Tag_23" := #read_record[6];
    "Tag_24" := #read_record[7];
    #FaultNumber := WORD_TO_DINT("Tag_25");
    
    //byte 8,9,10,11 ,parameter 2,r2132,alarm code
    "Tag_23" := #read_record[10];
    "Tag_24" := #read_record[11];
    #AlarmNumber := WORD_TO_DINT("Tag_25");
    
    //byte 12,13,14,15,16,17 ,parameter 3, r31 actual torque
    "Tag_23" := #read_record[14];
    "Tag_24" := #read_record[15];
    "Tag_26" := #read_record[16];
    "Tag_27" := #read_record[17];
    #ActualTorque := "Tag_28";
    
    //byte 18,19,20,21,22,23 ,parameter 4, r26 DC voltage
    "Tag_23" := #read_record[20];
    "Tag_24" := #read_record[21];
    "Tag_26" := #read_record[22];
    "Tag_27" := #read_record[23];
    #DCvoltage := "Tag_28";
    
    //byte 24,25,26,27,28,29 ,parameter 5, r27 actual current
    "Tag_23" := #read_record[26];
    "Tag_24" := #read_record[27];
    "Tag_26" := #read_record[28];
    "Tag_27" := #read_record[29];
    #ActualCurrent := "Tag_28";
    
    //byte 30,31,32,33,34,35 ,parameter 6, r21 actual RPM
    "Tag_23" := #read_record[32];
    "Tag_24" := #read_record[33];
    "Tag_26" := #read_record[34];
    "Tag_27" := #read_record[35];
    #ActualRPM := "Tag_28";
    
    //byte 36,37,38,39,40,41 ,parameter 7, r32 actual POWER
    "Tag_23" := #read_record[38];
    "Tag_24" := #read_record[39];
    "Tag_26" := #read_record[40];
    "Tag_27" := #read_record[41];
    #ActualPower := "Tag_28";
    
    //byte 42,43,44,45,46,47 ,parameter 8, r35 MOTOR TEMP
    "Tag_23" := #read_record[44];
    "Tag_24" := #read_record[45];
    "Tag_26" := #read_record[46];
    "Tag_27" := #read_record[47];
    #MotorTemp := "Tag_28";
    
    //byte 48,49,50,51,52,53 ,parameter 9, r35 MOTOR TEMP
    "Tag_23" := #read_record[50];
    "Tag_24" := #read_record[51];
    "Tag_26" := #read_record[52];
    "Tag_27" := #read_record[53];
    #DriveTemp := "Tag_28";

posted on 2017-11-17 22:37  lion_zheng  阅读(12136)  评论(5编辑  收藏  举报

导航