Advertisement
adfox83

Runtime counter S7

Sep 14th, 2021
1,629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SCL 1.26 KB | None | 0 0
  1. TYPE "udtRuntimeCountS"
  2. VERSION : 0.1
  3.    STRUCT
  4.       usSec : USInt;   // Seconds
  5.       usMin : USInt;   // Minutes
  6.       diHours : DINT;   // Hours
  7.       bReset : BOOL;   // Counter reset
  8.    END_STRUCT;
  9.  
  10. END_TYPE
  11.  
  12. FUNCTION "fcRunTimeS" : VOID
  13. { S7_Optimized_Access := 'TRUE' }
  14. VERSION : 0.1
  15.    VAR_INPUT
  16.       bEnable : BOOL;   // Counter enable
  17.       bClock1s : BOOL;   // 1s clock positive flank
  18.    END_VAR
  19.  
  20.    VAR_IN_OUT
  21.       udtRuntimeCounter : "udtRuntimeCountS";   // Runtime data
  22.    END_VAR
  23.  
  24.  
  25. BEGIN
  26.     (*
  27.         fcPRunTimeS
  28.        
  29.     *)
  30.    
  31.     // -- Counter reset
  32.     //
  33.     IF #udtRuntimeCounter.bReset THEN              
  34.         #udtRuntimeCounter.usSec    := 0;
  35.         #udtRuntimeCounter.usMin    := 0;
  36.         #udtRuntimeCounter.diHours  := 0;
  37.         #udtRuntimeCounter.bReset   := FALSE;
  38.     END_IF;
  39.    
  40.     // -- Enabled and 1 second pulse
  41.     //
  42.     IF #bEnable AND #bClock1s THEN                                  
  43.         #udtRuntimeCounter.usSec += 1;
  44.         IF #udtRuntimeCounter.usSec >= 60 THEN
  45.             #udtRuntimeCounter.usSec := 0;
  46.             #udtRuntimeCounter.usMin += 1;
  47.         END_IF;
  48.        
  49.         IF #udtRuntimeCounter.usMin >= 60 THEN
  50.             #udtRuntimeCounter.usMin := 0;
  51.             #udtRuntimeCounter.diHours += 1;
  52.         END_IF;
  53.     END_IF;
  54. END_FUNCTION
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement