Jump to content

Problème pour additionner des variables de temps


Recommended Posts

Bonjour , je travaille sur un projet d'où je suis bloquer sur les variables de temps .Je dois utiliser des heures fixes .  J'utilise le logicielle visilogic.

Pour mon exemple, j'ai 2 variables , l'heure et les minutes a soustraire . Variables 1  : 14h00 , variable 2 : 20mn , le résultat est 13h40.

Dans mon IHM , j'utilise les variables TIMES FONCTIONS  et sous ladder je les convertir en NUM TO BCD, puis j'utilise le bloc SUB pour le calcul et le résultat converti en BCD TO NUM .

Et pour finir , je le compare avec SI 31 pour enclencher un évènement. 

Le problème est je m'arrive pas a faire le calcul et le comparer vu que les valeurs sont différentes.

Je me comprend ou est le problème et je vous remercie d'avance pour être aide .

Link to comment
Share on other sites

  • MVP 2023

This is not something I've ever had to do, but my first thought would be enter the time in UTC format for Variable 1 and an ML or DW for Variable 2, then do the appropriate math before  subtracting Variable 2 from Variable 1. After that, a little more math before comparing to SI 31. The Help file provides plenty of information about these functions to assist you.

I'm sure someone will come along who has done this before and will provide a ridiculously easy solution.

Link to comment
Share on other sites

  • MVP 2023

Goggles translation:

Hello, I am working on a project where I am stuck on time variables. I have to use fixed times. I am using visilogic software.
For my example, I have 2 variables, the hour and the minutes to subtract. Variables 1: 2:00 p.m., variable 2: 20 minutes, the result is 1:40 p.m.
In my HMI, I use the TIMES FONCTIONS variables and under ladder I convert them into NUM TO BCD, then I use the SUB block for the calculation and the result converted into BCD TO NUM.
And finally, I compare it with SI 31 to trigger an event.
The problem is I can't do the calculation and compare it since the values are different.
I understand myself where the problem is and thank you in advance for being help.

 

I'm a bit confused.    Do the 2:00PM and 20 minutes change?

But like Flex suggests I think I'd be doing everything using UTC calcs.

cheers, Aus

Link to comment
Share on other sites

Bonjour et merci pour votre aide.
Pour mon projet on m'oblige d'utiliser le BCD pour les variables 1 (MI 1) et variables 2 (MI2) .
Dans mon exemple , lorsque que l'on rentre l'HEURE (ex: 5h ) et 10 mn , je dois lancer une sonnerie pour 5h50 et a 6h une deuxième sonnerie se lance .
Je pense que mon erreur vient  de ADD MI1 et MI2 et le résultat est plus en BCD. Je me vois pas comment je peux faire .

Je joins 2 photo de mon program.
 

google traduction

Hello and thank you for your help.
For my project I am forced to use the BCD for variables 1 (MI 1) and variables 2 (MI2).
In my example, when we enter the TIME (ex: 5h) and 10 mn, I have to start a ringing for 5:50 a.m. and at 6 a.m. a second ringing starts.
I think my error comes from ADD MI1 and MI2 and the result is more in BCD. I do not see myself how I can do.

I attach 2 photos of my program.

IHM.jpg

PROGRAM.jpg

Link to comment
Share on other sites

Bonjour 

J'ai réussit a en BCD l'addition des variables , j'obtiens bien l'heure souhaiter mais l'opération pour soustraire me donne pas la bonne valeur.

J'ai ajouter  6 (hex : 0110)  dans des exemple de calcul  que je vois sur internet mais c'est toujours pas .

Quelqu'un a t'il une solutions ?

Google traduction:

Hello

I succeeded in adding the variables in BCD, I got the desired time, but the operation to subtract gave me the wrong value.

I added 6 (hex: 0110) in some example calculation that I see on the internet but it's still not.

Does anyone have a solution?

 

 

ihm.jpg

program.jpg

Link to comment
Share on other sites

  • MVP 2023

First off, for what you're doing Hex and BCD are the same for display purposes as far as the time value setpoints are concerned.  I would remove all the NUM to BCD blocks as all they do is confuse things.  BCD conversion doesn't work if the hex value is more than 9 anyway.

This problem is not trivial.

The time functions package values as two bytes in one word, which is why you can't use regular math on them.  They are not considered as one number.  You've got one half of the word which is base 10 with a rollover at 24 and the other half which is base 10 with a rollover at 60.  They must be considered and operated on separately.

For example - for a time value of 5:30-

The number in the MI will be 0510h  (1296 dec).

Let's say you want to add 30 minutes - 0030h 

So  0510h + 0030h = 0540h ->  5:40.     Yay!

BUT....

Subtract 30 minutes using a normal SUB block.  What we want is 4:40.

0510h - 0030h = 4E0h.  No!

The error is A0h or decimal 10.

OR - add 55 minutes  using the ADD block ->6:05

0510h + 0055h = 565h.  No, this isn't any good, either.

I do not have an immediate solution to your problem as I've not solved this one before, but basically if you want to do math on Unitronics Time Function values you'll need to examine the values first and then choose from a couple of math block possibilities to get the right answer. 

 

Joe T.

 

 

 

 

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