› PLCGurus.NET Live & Interactive Forum › PLC Questions and Answers › General Automation Questions › Wonderware script subtraction problem!
- This topic has 7 replies, 4 voices, and was last updated 4 years, 6 months ago by
Stixoffire.
- AuthorPosts
- February 1, 2019 at 6:03 pm #3696
Anonymous
Karma: 0Rank: PadawanI have a script to do simple subtraction and the difference is incorrect. My script takes an I/O tag of 24hr total flow from a flow meter and moves the value to a memory integer tag before the next 24hr period. When the next 24hr total is updated, the previous total is subtracted from the newest total to give the previous days total flow.
The problem is the subtraction is not correct. When I do the subtraction, I find that the script subtraction is off by 20,000 or so. The 24hr total comes from an I/O tag. The value is stored in the PLC at midnight, and intouch reads it as a 32bit integer. It is always correct when it gets to intouch. What am I doing wrong? I (like others) am learning intouch/wonderware the hard way, on the job training. I’m sure its something I’m doing wrong but I can’t seem to figure it out.
Any help would be greatly appreciated.
February 5, 2019 at 8:29 am #3697mrincredible
ParticipantKarma: 53Rank: PadawanHi Marc,
It is difficult to say from your post here without seeing your script etc. Have you considered doing the math in the controller? Basically create three integer words, i.e., Flow_Old, Flow_New and then a Flow_Result that will store the result of the subtraction between Flow_Old and Flow_New. Then just send the result to inTouch which you say is working no problem.
Probably not the answer you’re looking for but maybe a work-around until you get your script sorted out.
Cheers!
February 5, 2019 at 9:41 am #3699Anonymous
Karma: 0Rank: PadawanHere is the script I have:
IF $Hour == 23 THEN Totalwellprev = Totalwell; END IF; IF $Hour == 1 THEN Totalwellyesterday = Totalwell – Totalwellprev; END IF;
I have considered doing the math in the controller and I think that may be a better way to go.
Thanks for the input.
February 5, 2019 at 10:02 am #3704mrincredible
ParticipantKarma: 53Rank: PadawanI think the problem is you’re overwriting the Totalwellprev with the updated information before computing the new total. When you are computing the “Totalwellyesterday” you are subtracting “Totalwellprev” which at this point you’ve overwritten with “Totalwell” information. Essentially, it looks to me like you are subtracting “Totalwell” from “Totalwell” to compute your “Totalwellyesterday”.
Hope that helps.
February 5, 2019 at 10:20 am #3709cajunconfigurator
ModeratorKarma: 187Rank: JediSo at 2300 you are clocking total well previous as the lifetime total correct? Then at 0100 you are subtracting lifetime total including today’s production by total – today’s production? Do I have that correct?
just to ask, is there any reason you aren’t just pulling those volumes from the flow computer?
-Scooter
February 5, 2019 at 10:59 am #3710Anonymous
Karma: 0Rank: PadawanI was trying to spread things out timewise. Totalwell comes from the controller and is only written/changed at midnight. At Wonderware the totalprev is overwritten by totalwell at 11 pm. Totalwell then changes at 12 and the subtraction happens at 1 am. The strange part is that the difference the script has been coming up with is close to correct. Some days it is off by 20k , the next day it is off by 43k. The difference is always less than what it should be. When I look at he values of Totalprev in wonderware it is correct and the Totalwell value is correct so it has to be related to the subtraction in the script or the format of the number. I think I am going to focus on performing this step in the controller.
Thanks for your help.
February 5, 2019 at 11:15 am #3711Anonymous
Karma: 0Rank: PadawanSean,
Thats correct. Lifetime total in the controller is “captured” every night at 12. I have moved the totalwell value to totalwellprev at 11. At 12 the script see’s the new captured Totalwell and subtracts Totalwellprev from it at 1am.
March 22, 2019 at 3:31 am #3822Stixoffire
ParticipantKarma: 172Rank: JediJust a Question.
1: You are using InTouch and not Application System Platform ?
2: As a design standpoint – let your HMI be an HMI.. do your math in the PLC.
3: InTouch : Looking at your code- what triggers your script to run ?
4: If Hour is between 23 and 1 nothing happens.
You say your Intouch Tag has the correct value ?
If this were me, I would do the calculation all in one IF statement and 1 Time Stamp because At Hour 23 it has one value and at hour 1 it has another value …
If $Hour==MyTimeInterval
MyIntervalPLCTimeVal = CurrentPLCVal;
MyPreviousPLCTimeVal = MyPreviousPLCTimeVal – MyIntervalPLCTimeVal
EndIf;However this code can have an Issue – your value can be NEGATIVE if you have no previous time value!!
- AuthorPosts
- You must be logged in to reply to this topic.