精准获取博途1200/1500PLC的中断时间值

       日常很多算法,比如数值积分、数值微分、 PID指令都需要在固定的步长里调用,中断程序提供了一个这样的基础步长,最小步长。我们可以利用这样的基础步长完成步长的变换。

       下面给大家介绍下在博途PLC里如何自动获取中断程序的中断时间值。

 一、中断时间读取FC

        利用这样的FC,我们可以自动读取对应中断程序的中断时间值,将时间值存储到全局变量表,之后其它数值算法都可以调用,不用一个个分别更改,提高效率降低出错概率。

2、1200PLC-SCL完整代码

FUNCTION "LCon_ReadCycleTimeS71200" : Real
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      OBnumber : Int;   // OB number; cyclic interupt
   END_VAR

   VAR_TEMP 
      tmpRetInt : Int;
      tmpPhase : UDInt;
      tmpStatus : Word;
      tmpCycleTime : UDInt;   // Cycle time in Microseconds
   END_VAR

   VAR CONSTANT 
      UNIT_ID : DWord := 16#1001_0000;
   END_VAR


BEGIN
	//------------------------------------------------------------------------------------------------------------------------
	//SIEMENS DF FA PMA APC 
	//------------------------------------------------------------------------------------------------------------------------
	//name          : ReadCycleTimeS71200
	//functionality : Cycle time identification for S7-1200 CPU
	//assignment    : Any
	//library       : LCon
	//------------------------------------------------------------------------------------------------------------------------
	//change log table:
	//version   date          expert in charge            changes applied
	//V1.0      10.11.2016    APC ERL                     Creation
	//V1.1      17.11.2016    APC ERL                     adapted to styleguide
	//=========================================================================================================================
	
	#LCon_ReadCycleTimeS71200 := 0.0;
	#tmpRetInt := QRY_CINT(OB_NR := #OBnumber, CYCLE => #tmpCycleTime, PHASE => #tmpPhase, STATUS => #tmpStatus);
	IF (#tmpStatus = 16#0014) THEN
	  IF #tmpRetInt = 0 THEN
	    #LCon_ReadCycleTimeS71200 := (UDINT_TO_REAL(#tmpCycleTime)) / 1000;                            //Conversion from microseconds to milliseconds
	  END_IF;
	END_IF;
	
END_FUNCTION

3、1500PLC-SCL完整代码

FUNCTION "LCon_ReadCycleTimeS71500" : Real
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
   VAR_INPUT 
      OBnumber : Int;   // OB number; cyclic interupt or synchronous operation
   END_VAR

   VAR_TEMP 
      tmpRetInt : Int;
      tmpCycleTime : UDInt;   // Cycle time in Microseconds
      tmpPhase : UDInt;
      tmpStatus : Word;
      tmpStartUpSi {InstructionName := 'SI_Startup'; LibVersion := '1.0'} : SI_Startup;
      tmpTopSi {InstructionName := 'SI_SynchCycle'; LibVersion := '1.0'} : SI_SynchCycle;
      tmpSiNone {InstructionName := 'SI_none'; LibVersion := '1.0'} : SI_none;
   END_VAR

   VAR CONSTANT 
      UNIT_ID : DWord := 16#1001_0000;
   END_VAR


BEGIN
	//------------------------------------------------------------------------------------------------------------------------
	//SIEMENS DF FA PMA APC / Mumbai,India | Erlangen, Germany
	//------------------------------------------------------------------------------------------------------------------------
	//name          : ReadCycleTimeS71500
	//functionality : Cycle time identification for S7-1500 CPU
	//assignment    : Any
	//library       : LCon
	//------------------------------------------------------------------------------------------------------------------------
	//change log table:
	//version   date          expert in charge              changes applied
	//V1.0      02.07.2012    APC GMC group                 Creation
	//V2.0      10.11.2016    APC ERL                       extended to read cycle time from synchronous cycle OBs
	//V2.1      17.11.2016    APC ERL                       adapted to styleguide
	//=========================================================================================================================
	
	#LCon_ReadCycleTimeS71500 := 0.0;
	
	#tmpRetInt := RD_SINFO(TOP_SI => #tmpSiNone, START_UP_SI => #tmpStartUpSi);
	
	IF #tmpSiNone.OB_Class = 30 THEN
	  #tmpRetInt := QRY_CINT(OB_NR := #OBnumber, CYCLE => #tmpCycleTime, PHASE => #tmpPhase, STATUS => #tmpStatus);
	  IF (#tmpStatus = 16#0014) THEN
	    IF #tmpRetInt = 0 THEN
	      #LCon_ReadCycleTimeS71500 := (UDINT_TO_REAL(#tmpCycleTime)) / 1000;                            //Conversion from microseconds to milliseconds
	    END_IF;
	  END_IF;
	  
	ELSIF #tmpSiNone.OB_Class = 61 THEN
	  #tmpRetInt := RD_SINFO(TOP_SI => #tmpTopSi, START_UP_SI => #tmpStartUpSi);
	  IF #tmpTopSi.OB_Nr = #OBnumber THEN
	    IF #tmpRetInt = 0 THEN
	      #LCon_ReadCycleTimeS71500 := DINT_TO_REAL(LTIME_TO_DINT(#tmpTopSi.SyncCycleTime)) / 1000000; // convert to milliseconds in REAL-Format
	    END_IF;
	  END_IF;
	ELSE
	  #LCon_ReadCycleTimeS71500 := 0.0;
	END_IF;
END_FUNCTION

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值