12/24/2019 4:10 AM  
Joined: 10/20/2019 Last visit: 2/17/2020 Posts: 9 Rating: (0) 
hi dears according to the link below and a PNG that i have attached https://support.industry.siemens.com/cs/ww/en/view/13406965 i can't understand the steps of programming and variables definition . is there anyone help me to understand fluencly this program? tnx in advanced  
Last edited by: Jen_Moderator at: 12/25/2019 12:51:28New subject after splitting. Optimized link Last edited by: kamy2019 at: 12/29/2019 15:23:39 

12/30/2019 11:15 AM  
Joined: 9/23/2005 Last visit: 2/16/2020 Posts: 2450 Rating: (373) 
Rewrite this code in text and add here, then I can think of. 
Regards, 

12/30/2019 10:09 PM  
Joined: 1/28/2009 Last visit: 2/18/2020 Posts: 6616 Rating: (1249)

Hello ,
The block is a bit difficult to analyze because of using SFC64 for time measurement. Mostly we use the time difference between to cyclic interrupts in CPU as Delta T for integral calculation.You can consider it constant and the user need to provide it as sample or cycle input like the one in FB41 as PID.Here , you don't need to provide Delta T because it is calculated internally. The other things that you need to know is the trapezoid areal calculation and you can google it. I summarized all important points in the following Youtube video , you need to test it online for more clues. I hope it helps, hdhosseini 
2/4/2020 10:57 PM  
Joined: 10/20/2019 Last visit: 2/17/2020 Posts: 9 Rating: (0) 
thank you Jacek d need to be noted after i spent time to analyze the codes i could figure out what is going on but what , confuses me are lines which i have signed those with ????????? mark. VAR_OUTPUT OUT:REAL; RESET_ACTIVE:BOOL; END_VAR VAR OUT_LOW:REAL; LAST_IN:REAL; LAST_OUT:REAL; LAST_TIME:REAL; ACTUAL_TIME:REAL; X:REAL; N:INT; END_VAR //RESET OF VALUES RESET_ACTIVE:=RESET; IF RESET=TRUE THEN OUT:=0.0; OUT_LOW:=0.0; LAST_OUT:=0.0; LAST_TIME:=ACTUAL_TIME; ACTUAL_TIME:=TIME_TO_DINT(TIME_TCK())/1000.0; X:=0.0; N:=0; ELSIF ENABLE=FALSE THEN N:=0; ELSE //FIRST INTEGRAL CYCLUS IF N=0 THEN ACTUAL_TIME:=TIME_TO_DINT(TIME_TCK())/1000.0; LAST_TIME:=ACTUAL_TIME; LAST_IN:=IN; N:=1; ELSE // INPUT ACTUAL_TIME:=TIME_TO_DINT(TIME_TCK())/1000.0; //OVERFLOW CORRECTION IF ACTUAL_TIME<LAST_TIME THEN X:=(ACTUAL_TIMELAST_TIME+2147483.647)*(IN+LAST_IN)/2; ELSE X:=(ACTUAL_TIMELAST_TIME)*(IN+LAST_IN)/2; END_IF; LAST_TIME:=ACTUAL_TIME; LAST_IN:=IN; // INTEGRAL CALCULATION LAST_OUT:=OUT; OUT:= LAST_OUT+X; OUT_LOW:=(OUTLAST_OUT)X+OUT_LOW; //??????????? IF OUT_LOW<>0 THEN IF ABS(OUT/OUT_LOW)<10000000 THEN LAST_OUT:=OUT; OUT:=OUTOUT_LOW; OUT_LOW:=(OUTLAST_OUT)+OUT_LOW; //????????????? END_IF; END_IF; END_IF; END_FUNCTION_BLOCK as far as this line is always zero : OUT_LOW:=(OUTLAST_OUT)X+OUT_LOW; so what is the functionality of rest codes??? thank you so much 
Last edited by: kamy2019 at: 02/04/2020 23:08:36Last edited by: kamy2019 at: 02/04/2020 23:09:18Last edited by: kamy2019 at: 02/04/2020 23:09:51 

2/4/2020 11:08 PM  
Joined: 10/20/2019 Last visit: 2/17/2020 Posts: 9 Rating: (0) 
thank you too dear hdhosseini your video gave me a good view of understanding the codes related to N variable's functionality. in this project sampling time is extracted from SFC64 so with CPU's cycle time all the samples will be taken and question is this what if i want to limit my sampling time to OB35? i mean what will be changed in program's lines.is it enough to remove the codes related to ACTUAL_TIME:REAL; variable and let to FB to be called in each OB's cycle time?could you please guide me how to implement the codes and blocks? thank you so much 
2/5/2020 8:42 AM  
Joined: 1/28/2009 Last visit: 2/18/2020 Posts: 6616 Rating: (1249)

Your code is become drastically simpler.In line that X is calculated such as X:=(ACTUAL_TIMELAST_TIME+2147483.647)*(IN+LAST_IN)/2; simply substitute (ACTUAL_TIMELAST_TIME+2147483.647) with a constant (CYCLE) sampling period known as input of FB. CYCLE*(IN+LAST_IN)/2; Remove all unnecessary sections related to time measurement and test your program again. 
This contribution was helpful to1 thankful Users 
2/5/2020 8:46 AM  
Joined: 9/23/2005 Last visit: 2/16/2020 Posts: 2450 Rating: (373) 
Actually it is not. Reason for this is finite resolution of floating point numbers. Have a look at Kahan summation algorithm. 
Regards, 

This contribution was helpful to3 thankful Users 
2/6/2020 3:57 AM  
Joined: 10/20/2019 Last visit: 2/17/2020 Posts: 9 Rating: (0) 
dear jacek d; Actually it is not. Reason for this is finite resolution of floating point numbers. Have a look atKahan summation algorithm. i got it. so many thanks 
This contribution was helpful to1 thankful Users 
Follow us on