Jump to content

Setting Timer from a Formula


gsd

Recommended Posts

Hello first time poster and entry level user to the Unitronics products. 

I have a current project where I would like to set a Timer duration based off of a calculation from a formula. 

Basically the formula is: (A*XX)

I would like to populate the timer duration based off the output from that formula.  I believe I need a TON Timer as I want it to set an output once it has timed out. 

Is this possible?  How do I set the timers duration based off the my formula output?

 

See attached image for what i am intending to do. 

 

Thank you

Capture.JPG

Link to comment
Share on other sites

I created a Timer Tag and found the "preset" "current" and "out" tags. 

How can i set the preset time based on what is output from my formula?  Currently i have my formula outputting a REAL # 

I see the Timer preset tag is a unsigned integer 32 bits long type.  Can someone guide me as to how I can translate my formula output into the timer preset?

Im sorry if this is really basic.  I am a newbie when it comes to this kind of stuff. 

Thank you

Capture2.JPG

Link to comment
Share on other sites

  • MVP 2021

First of all, why is your formula outputting a REAL number? You should avoid that if at all possible. Do your calculations with integers and keep track of the decimal place (in your mind) as you go. Then you can use the number to whatever decimal precision you require with some simple math.

The timer Preset is in milliseconds, so if you want the preset to be 6 seconds, use the number 6000. If the preset is 3 minutes & 40 seconds, then the preset value would be 220,000. Make sure your calculated value is in milliseconds (do whatever math is required to obtain milliseconds), then place that number into the Preset operand.

Link to comment
Share on other sites

6 minutes ago, Flex727 said:

First of all, why is your formula outputting a REAL number? You should avoid that if at all possible. Do your calculations with integers and keep track of the decimal place (in your mind) as you go. Then you can use the number to whatever decimal precision you require with some simple math.

The timer Preset is in milliseconds, so if you want the preset to be 6 seconds, use the number 6000. If the preset is 3 minutes & 40 seconds, then the preset value would be 220,000. Make sure your calculated value is in milliseconds (do whatever math is required to obtain milliseconds), then place that number into the Preset operand.

Thanks for the response Flex727

I guess i'm using REAL # out of ignorance.  I will change the type back to integer.  

With that being said how do i automatically populate the timer's countdown time? (converting from milliseconds isn't an issue)  Let me give you some more background:

The formula output is dependent on what the HMI user inputs to the numeric box on the HMI screen.  So the formula output will constantly be changing every-time the timer is reset and a new value is input into the numeric box. 

So I need the Timers count down time to "auto populate" with  the value from the formula output being presented to it at the time.  The count down time is not a static value.

I must be using the wrong ladder logic functions because I couldn't find a function that would allow me to populate into the Timers Struct.  

Let me toil some more and I will report back if I find my mistake.  

 

Thank you!

Link to comment
Share on other sites

Good News! 

 

Using the "Store" function It looks like I'm able to place my formula "output" into the "tag to store" box which in turn allows me to set the timer "preset" by setting that in the B "Store in to tag" box. 

Now I just gotta make sure i carry out my integer math properly. 

 

Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...