9/19/2012 10:11 PM | |
Joined: 12/4/2009 Last visit: 3/19/2025 Posts: 453 Rating:
|
Experts, I've been using Siemens TIMER_P (FB5) function for a while, and today I have noticed one very stange situation. Namely, I have two FB5 calls inside OB35 cycle. One of them is on-delay timer with TIME0 preset of 120.0s, and another is also delay-on with 86400.0s TIME0 preset. Sample time is 0.1s. Nothing else is being executed inside CPU. The whole program is simulated in PLCSIM. When I output PTIME parametars to MD100 and MD200 respectively, it turns out that first timer counts faster than the other one. Time lap increases with time, and in few minutes I have more than 1s of gap between them. Since FB5 is a cycle-dependent function, as far as my knowledge is concered theese timers should count-down at the same speed. Any help on this matter is highly appreciated. |
Last edited by: crazyCow at: 4/17/2016 12:23:07 AMIf this post actually helped, you may consider using the Rate button above. |
|
9/20/2012 1:11 PM | |
Joined: 9/23/2005 Last visit: 3/28/2025 Posts: 4971 Rating:
|
I looked in Step7 libs and I can't find this FB. Where have you found it ? |
Regards, |
|
9/20/2012 5:48 PM | |
Joined: 1/28/2009 Last visit: 3/29/2025 Posts: 6867 Rating:
|
Hello, Timer_p or FB5 is part of CFC library. In CFC library you have elements for S7300 and S7400.I test the scenario you have mentioned and the result was satisfactory in PLCSIM. I called the function in a Chart and compile all my project there.I attached all you need in attachment.My recommendation, try use this function in CFC.For STEP7 with LAD/STL/FBD editor use Simatic or IEC timers . Best regards, Hamid Hosseini AttachmentFB5.zip (286 Downloads) |
This contribution was helpful to
1 thankful Users |
9/20/2012 8:39 PM | |
Joined: 12/4/2009 Last visit: 3/19/2025 Posts: 453 Rating:
|
Dear Hamid, thank you for your reply. I took your advice about having my blocks in CFC and the result is indeed satisfactory. This solution is kind-of remedy for my problem, but now I'm even more confused. I am aware of that FB5 is a block form CFC library, but anyhow CFC is nothing more than some sort of higher programming language. At compilation stage, it should be translated to S7 code whatsoever. Having two FB5 calls in CFC OB35 runtime group should be identical situation to calling them directly in OB35 without CFC being used at all. As an illustration I have attached two printscreens from my test project. It is obvious that after 199s, timer with 86400.0 preset value has counted down to 86197s, and that there is more than 3s of gap between theese two timers. Could it be that this is PLCSIM bug? Or CFC blocks should be called exclusively from CFC, which would truly compromise my PLC programming knowledge... AttachmentFB5_CONFUSION.zip (237 Downloads) |
Last edited by: crazyCow at: 4/17/2016 12:23:46 AMIf this post actually helped, you may consider using the Rate button above. |
|
9/21/2012 7:48 AM | |
Joined: 10/7/2005 Last visit: 3/27/2025 Posts: 3043 Rating:
|
Hello kjurlina good news first, the way I see it it, it is neither a PLCSIM bug nor is yourPLC programming knowledge compromised. The issue with FB5 "TIMER_P" is that it uses Floating Point math to subtract "SAMPLE_T" from "TIME0" every time the FB is called. In your original example you call FB5 every 100ms via OB35 and correctly declared "SAMPLE_T" as 0.1 (ms). You will in this case see a"drift" in the actual time outputs "PTIME" betweenthe call with a "TIME0" setpoint of 86400.0 (sec.) and the other call with 120.0 (sec.). Reason being is that you aresubtracting a very small value (0.1)from a very large valuevalue(86400.0) and the required exponent alignment will lead to rounding errors and inaccuracies (see also the FAQ How accurately can I calculate with REAL numbers that are used in extensive formulas? for more on this). This is also the reason that the inbuilt help for FB5 warns that "The difference between TIME0 and SAMPLE_T may not be more than 10^7" (if you were to break this rule you won't get any subtraction happening anymore, you are currently only running "borderline"). The way I see it, you will have the same problem when called in the same fashion from a "pure" CFC enviroment and here's my theory why you and hdhosseinido NOT seethis problem apearing in this case: FB5's default "SAMPLE_T" is 1 sec (hidden input in CFC) and you would certainly get a better results if called from a 1 sec. cyclic interrupt OB (check you CFC Run sequence andcyclicinterrupt OB time). It could also be that it is indeed called from a 0.1 sec cyclic interrupt OB, but that a "reducation ratio" has been appliedwhich would also improve the result (check your runtime group properties). Attached is a screendump with the results of pure CFC calls.. The top one with a 0.1 secondscall of FB5 (= same problem as when called directly in a LAD/FBD/STL program), the bottom one with a 1.0 seconds call of FB5 (= no problem anymore, should work just as well when done so ina LAD/FBD/STL program). I hope this helps |
Last edited by: fritz at: 9/21/2012 8:41 AMfixed up screendump Cheers |
|
This contribution was helpful to
3 thankful Users |
9/21/2012 8:13 AM | |
Joined: 12/4/2009 Last visit: 3/19/2025 Posts: 453 Rating:
|
Dear fritz, this is what I needed. I knew that exponent alignment can lead to rounding errors, but I didn't see this case as a big deal regarding numbers difference. One can take the whole REAL range and make a correct conclusion that this difference (0.1 - 86400.0) is not big enough to disrupt floating point math so much. And this truly is a big accumulating rounding mistake. If I loose 3s in three minutes, that merely means that it would go up to more than 5 minutes for the whole day. This is a good reason to go back to S7 timers or any other solution. I never actually liked REAL number format anyhow Thank you for your help. |
Last edited by: crazyCow at: 4/17/2016 12:24:17 AMLast edited by: crazyCow at: 7/24/2017 11:15:10 PMIf this post actually helped, you may consider using the Rate button above. |
|
This contribution was helpful to
1 thankful Users |
6/19/2017 8:38 AM | |
Joined: 12/9/2010 Last visit: 10/8/2022 Posts: 623 Rating:
|
Hi crazyCow, Test on actual PLC and share the results here. While simulation, other processes are also running in PC processor. Please share FB5 block as I also could not find it. |
If you like the comment, rate it (right top) or thank it (left bottom). |
|
6/20/2017 6:14 PM | |
Joined: 9/3/2014 Last visit: 3/13/2019 Posts: 4766 Rating:
|
New question published by Ram_BahrainSteel is split to a separate thread with the subject FB5 block, Sample_T has changed. Best regards |
We are working on a new user interface with better overview and more relevance.
Follow us on