Siemens STL Counter

TrainS7

Member
Join Date
Mar 2016
Location
NAIROBI
Posts
5
Hi, am not an expert on Siemens STL, but I have and object to do on Siemens S7 400 using STL, kindly advice.

Objective:
- Cumulatively Count pulses that are generated nonstop after every 1 hour starting midnight (0:00,1:00,2:00,3:00...23:59)
- Store this value, till midnight then rest the memory ready for the next day count.

Any clues will be appreciated, below is my attempt.

L MB 103
L B#16#0
<>I
JC END0
L MB 104
L B#16#0
<>I
JC END0
FR C 200
T C 200
L "_641EI102A01X01"
ITD
T "DummyDint"
L "DummyDint"
DTR
T DB17.DBD18
L MB 103
L B#16#0
<>I
JC END0
L MB 104
L B#16#59
R C 200
END0: NOP 0
 
I think you're overcomplicating it. Why you must use STL?
And if you use STL why use old S5 counter which can only count to 999
You can use an int counter like SFB0, SFB1, SFB2
or count with a INT, DINT or DWORD directly in STL
 
- Cumulatively Count pulses that are generated nonstop after every 1 hour starting midnight (0:00,1:00,2:00,3:00...23:59)
How this pulse is generated , at what frequency?

- Store this value, till midnight then rest the memory ready for the next day count.
Do you want to count how many pulse are in 24 H?
I don't understand a lot, you're not clear.
 
Hi
The pulses are generated by a sensor as items pass.
The frequency is not consistent. But the counting has to be done within a period of 1 hour store the count. Then start another count for a period of 1 hour and repeat same cycle.

It's just a simple counter but the trick is on the 1 hour duration...PLC time managed. The one hour must be identical to PLC time.

Hope this is clearer
 
What this means is all the 1 hour counts or values are saved and not over written until midnight then reset to 0 value ready for next day count.
 
I hope I have understood and met your requirements.
Compile this FB1 source and call it on OB1.
P.S: Don't forget to generate the instance DB.
Code:
FUNCTION_BLOCK FB 1
TITLE =
VERSION : 0.1


VAR_INPUT
  IN_Sensor : BOOL ;    //Input Triger
END_VAR
VAR_OUTPUT
  FILL_RET_VAL : INT ;    
END_VAR
VAR
  Triger_Edge : BOOL ;    
  RESET : BOOL ;    
  RESET_EDGE : BOOL ;    
  Hour_Counter_00 : DINT ;    
  Hour_Counter_01 : DINT ;    
  Hour_Counter_02 : DINT ;    
  Hour_Counter_03 : DINT ;    
  Hour_Counter_04 : DINT ;    
  Hour_Counter_05 : DINT ;    
  Hour_Counter_06 : DINT ;    
  Hour_Counter_07 : DINT ;    
  Hour_Counter_08 : DINT ;    
  Hour_Counter_09 : DINT ;    
  Hour_Counter_10 : DINT ;    
  Hour_Counter_11 : DINT ;    
  Hour_Counter_12 : DINT ;    
  Hour_Counter_13 : DINT ;    
  Hour_Counter_14 : DINT ;    
  Hour_Counter_15 : DINT ;    
  Hour_Counter_16 : DINT ;    
  Hour_Counter_17 : DINT ;    
  Hour_Counter_18 : DINT ;    
  Hour_Counter_19 : DINT ;    
  Hour_Counter_20 : DINT ;    
  Hour_Counter_21 : DINT ;    
  Hour_Counter_22 : DINT ;    
  Hour_Counter_23 : DINT ;    
  Offset : INT ;    
END_VAR
VAR_TEMP
  AR2_DW : DWORD ;    
  BVAL : BYTE ;    
END_VAR
BEGIN
NETWORK
TITLE =

      TAR2  #AR2_DW; 

      L     DW#16#87000000; 
      LAR1  ; 
      L     B [AR1,P#15.0]; 
      BTI   ; 
      ITD   ; 
      T     #Offset; 

      L     B [AR1,P#15.0]; 
      L     B#16#0; 
      ==I   ; 
      =     #RESET; 

NETWORK
TITLE =

      A     #RESET; 
      FP    #RESET_EDGE; 
      JCN   YYY; 

      L     B#16#0; 
      T     #BVAL; 

      CALL SFC   21 (
           BVAL                     := #BVAL,
           RET_VAL                  := #FILL_RET_VAL,
           BLK                      := P#DIX 6.0 BYTE 92);

YYY:  NOP   0; 
NETWORK
TITLE =


      L     #Offset; 
      JL    YNOP; 
      JU    YB00; 
      JU    YB01; 
      JU    YB02; 
      JU    YB03; 
      JU    YB04; 
      JU    YB05; 
      JU    YB06; 
      JU    YB07; 
      JU    YB08; 
      JU    YB09; 
      JU    YB10; 
      JU    YB11; 
      JU    YB12; 
      JU    YB13; 
      JU    YB14; 
      JU    YB15; 
      JU    YB16; 
      JU    YB17; 
      JU    YB18; 
      JU    YB19; 
      JU    YB20; 
      JU    YB21; 
      JU    YB22; 
      JU    YB23; 
YNOP: JU    END; 

YB00: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_00; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_00; 
      JU    END; 

YB01: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_01; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_01; 
      JU    END; 

YB02: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_02; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_02; 
      JU    END; 

YB03: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_03; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_03; 
      JU    END; 

YB04: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_04; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_04; 
      JU    END; 

YB05: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_05; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_05; 
      JU    END; 

YB06: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_06; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_06; 
      JU    END; 

YB07: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_07; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_07; 
      JU    END; 

YB08: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_08; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_08; 
      JU    END; 

YB09: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_09; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_09; 
      JU    END; 

YB10: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_10; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_10; 
      JU    END; 

YB11: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_11; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_11; 
      JU    END; 

YB12: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_12; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_12; 
      JU    END; 

YB13: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_13; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_13; 
      JU    END; 

YB14: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_14; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_14; 
      JU    END; 

YB15: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_15; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_15; 
      JU    END; 

YB16: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_16; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_16; 
      JU    END; 

YB17: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_17; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_17; 
      JU    END; 

YB18: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_18; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_18; 
      JU    END; 

YB19: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_19; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_19; 
      JU    END; 

YB20: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      L     #Hour_Counter_20; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_20; 
      JU    END; 

YB21: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_21; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_21; 
      JU    END; 

YB22: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_22; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_22; 
      JU    END; 

YB23: A     #IN_Sensor; 
      FP    #Triger_Edge; 
      JNB   END; 
      L     #Hour_Counter_23; 
      L     L#1; 
      +D    ; 
      T     #Hour_Counter_23; 

END:  LAR2  #AR2_DW; 
      SAVE  ; 
      BE    ; 
END_FUNCTION_BLOCK
 
Hi ,
Below another counter method management in fc.
Please , add the reset counter code at the midnight!
Regards.

FC8.jpg
 

Similar Topics

Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
593
I'm having trouble trying to convert this code to ladder, anyone able to help me? A M4.0 A M4.1 A M117.0 AN M17.7 A ( A I38.6 AN I3.7 O ( A M4.5...
Replies
8
Views
1,172
Hello, I am still new to STL. But from what I understand is the JC mnemonic should jump if RLO = 1. If we review both pictures the M0bf RLO = 1...
Replies
5
Views
1,015
Hello, I am working on a project to upgrade some old S5-100U processors. The programs are all uploaded and I don't have descriptors...ugh. Be that...
Replies
4
Views
1,116
I really struggle with STL in Siemens Step 7 Classic. I'll learn chunks, but then I don't use it enough to retain and build on the knowledge. When...
Replies
17
Views
3,144
Back
Top Bottom