Wonderware script subtraction problem!

https://www.linkev.com/?a_fid=ics-eng

This topic contains 7 replies, has 4 voices, and was last updated by Ken S Ken S 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3696
    Marc Twidwell
    Marc Twidwell
    Participant
    • Topics: 1
    • Replies: 3
    • Total Posts: 4
    Karma: 16
    Rank: Padawan

    I 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.

    #3697
    Mister Incredible
    Mister Incredible
    Participant
    • Topics: 8
    • Replies: 16
    • Total Posts: 24
    Karma: 48
    Rank: Padawan

    Hi 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!

    #3699
    Marc Twidwell
    Marc Twidwell
    Participant
    • Topics: 1
    • Replies: 3
    • Total Posts: 4
    Karma: 16
    Rank: Padawan

    Here 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.

    #3704
    Mister Incredible
    Mister Incredible
    Participant
    • Topics: 8
    • Replies: 16
    • Total Posts: 24
    Karma: 48
    Rank: Padawan

    I 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.

    #3709
    Cajun Configurator
    Sean Terrell
    Moderator
    • Topics: 6
    • Replies: 29
    • Total Posts: 35
    Karma: 184
    Rank: Jedi

    So 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

    #3710
    Marc Twidwell
    Marc Twidwell
    Participant
    • Topics: 1
    • Replies: 3
    • Total Posts: 4
    Karma: 16
    Rank: Padawan

    I 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.

    #3711
    Marc Twidwell
    Marc Twidwell
    Participant
    • Topics: 1
    • Replies: 3
    • Total Posts: 4
    Karma: 16
    Rank: Padawan

    Sean,

    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.

    #3822
    Ken S
    Ken S
    Participant
    • Topics: 3
    • Replies: 14
    • Total Posts: 17
    Karma: 35
    Rank: Padawan

    Just 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!!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login Register