6/30/2013 3:37 PM | |
Posts: 378 Rating: (73) |
Dear All, I just found a means to convert from S5TIME data type to DECIMAL and also DECIMAL to S5TIME directly from WinCC. (Note that may be I am re-inventing the wheel and I have searched a lot and also I post here but I couldn’t find such kind of ways on converting) For simplicity I just ignored the millisecond and for now Let start with how S5TIME is encoded in binary form: It has a WORD length memory (16bit) let name it from right to left: BIT-0, BIT-1, BIT-2, BIT-3, BIT-4, BIT-5, BIT-6, BIT-7, BIT-8, BIT-9, BIT-10, BIT-11, BIT-12, BIT-13, BIT-14, BIT-15 and let group it in four bits length: Group-1 = BIT-0, BIT-1, BIT-2, BIT-3 Group-2 = BIT-4, BIT-5, BIT-6, BIT-7 Group-3 = BIT-8, BIT-9, BIT-10, BIT-11 Group-4 = BIT-12, BIT-13, BIT-14, BIT-15 If BIT-12 equals 0 and BIT-13 equals 1 the time value in seconds is expressed as: Group-3*100+ Group-2*10+ Group-1 If BIT-12 equals 1 and BIT-13 equals 1 the time value in seconds is expressed as: Group-3*1000+ Group-2*100+ Group-1*10 Example: In S5TIME format 0h1m34s00ms in binary form is 0010_0000_1001_0100 Group-1= 0100 = 4 Group-2= 1001 = 9 Group-3= 0000 = 0 BIT-13 = 1 BIT-12 = 0 Therefore the time value is = 0*100 + 9*10 + 4 = 94 Seconds = 1min34sec I have attached here a wincc 2008 project containing VB script to convert this time formats; On the attached example please pay attention on tags property of Change Value Rgs, AttachmentS5time.zip (169 Downloads) |
Last edited by: desmul24 at: 7/4/2013 8:09 PM |
|
This contribution was helpful to2 thankful Users |
6/30/2013 9:07 PM | |
Joined: 1/28/2009 Last visit: 4/26/2024 Posts: 6838 Rating: (1359) |
Hello desmul24 , There is some points to be cleared:Time base (the last decade) in s5 timer or SIMATIC Time has 4 states and you just considered 2 of them.When the value in BCD is 2 and 3 i.e second and 10 seconds respectively.I suggest using concept of "TIME" variable and count miliseconds.As you may know, numbers of miliseconds in a period of time makes the "TIME" format.Then if you are interested only in seconds just divide it to 1000.In this way you avoid problem of missing some data with milisecond resolution comming from controllers.I have not searched but you can check if it is implemented in WINCC Flexible. Thank you for time spending and sharing your project with us. Best regards Hamid Hosseini |
Last edited by: hdhosseini at: 6/30/2013 9:29 PM |
|
7/1/2013 4:18 PM | |
Posts: 378 Rating: (73) |
Dear hdhosseini, Thanks for your comments, and I already put on the script all four states on the script TIMEtoINT as follows: [code] Select Case TimeType Case 0 InResult=HundredSecondIndex Case 1 InResult=HundredSecondIndex*10+TenSecondIndex Case 2 InResult=HundredSecondIndex*100+TenSecondIndex*10+OneSecondIndex Case 3 InResult=HundredSecondIndex*1000+TenSecondIndex*100+OneSecondIndex*10 Case Else InResult=0 End Select [/code] The milisecond part is on Case 0 and if you need in milisecond just use InResult=HundredSecondIndex*1000+TenSecondIndex*100+OneSecondIndex*10 then the function returns in miliseconds but you are limited up to 9s990ms. Thanks and regards |
Last edited by: desmul24 at: 7/4/2013 8:11 PM |
|
7/1/2013 4:29 PM | |
Joined: 1/28/2009 Last visit: 4/26/2024 Posts: 6838 Rating: (1359) |
Hello again, I should review my knowledge on WINCC Flexible and scripting there.Is it possible to consider a 32-bit integer for keeping converting value from SIMATIC Timer to TIME.That will give you a much bigger time value around 2 hours that suffices for SIMATIC Timers.In S7 controllers, we set aside 32 bit for a TIME variable. Best regards Hamid Hosseini |
Last edited by: hdhosseini at: 7/1/2013 4:30 PM |
|
Follow us on