LINT math operations not supported for some Logix processors

AlfredoQuintero

Lifetime Supporting Member
Join Date
Feb 2015
Location
Yokohama
Posts
1,551
Hello: Some time ago I wrote some basic code for a GuardLogix, in which I needed to add and subtract tags of LINT data type. When tried to use the same program on a L30ER, had my rude awakening on learning that these processors do not support LINT data types for basic math functions such as addition and subtraction.
So I am trying to figure out how to subtract long integers in an L30ER.
I am actually trying to write a program that calculates the program's running time. Perhaps there is a better way of doing this than using GSV.
I deserve all the the scolding and humiliation for not knowing this so very basic stuff after all my years working with Rockwell. I did try for some hours, but could not figure out. Hence, will be grateful for the advice of our learned PLCTALK.net Rockwell experts.
 
I deserve all the the scolding and humiliation for not knowing this so very basic stuff after all my years working with Rockwell. I did try for some hours, but could not figure out. Hence, will be grateful for the advice of our learned PLCTALK.net Rockwell experts.

Don't victim blame yourself, it was a perfectly reasonable expectation. There is no good reason that you should expect it to not work, you can do math with all of the reset of the types.
 
From here:

  • Attribute: CurrentValue:
  • Data type: DINT[2]; DT; LINT
    • N.B. DT and LINT are not available in CompactLogix
  • Instruction: GSV; SSV
  • Description:
    • Current value of the wall clock time. The number of microseconds elapsed since 0000 hours 1 January 1970.
    • Note: You can set this value to no later than 12/29/2068.
    • The CST and WALLCLOCKTIME objects are mathematically related in the controller. For example, if adding the CST CurrentValue and the WALLCLOCKTIME CSTOffset, the result is the WALLCLOCKTIME CurrentValue
Sidebar
The interesting thing is the number of microseconds from the 1/1/1970 epoch until 12/29/2068:
Code:
$ python

>>> import datetime
>>> import math

>>> td=datetime.datetime(2068,12,29)-datetime.datetime(1970,1,1)

>>> math.log10(td.total_seconds()*1e6) / [B]math.log10(2)[/B]

51.472299620979975
Which is suspiciously close to the 53 implicit mantissa bits in double-precision IEEE-754 (cf. here) i.e. LREAL in Logix (not Compact), which to me suggests ControlLogix might be doing some of the math with LREALs internally.

But if we assume those DINTs are COPies of the LINT, then that means the Most-Significant DINT (MSDINT) will never be negative, so the only fiddly bits required will be in the LSDINT.
Anyway, the preferred method would be to use the AOI.

If you want to roll your own, to get the time between two DINT[2] times from a GSV CurrentValue instruction, THEN[2] and NOW[2], the following might work without risk of overflow:
MUL 65536.0 0.065536 FourGConstant
MOV 0.000001 OneMConstant
LES NOW[1] THEN[1] ADD NOW[0] 1 NOW[0]
CPT RUNNINGTIME "(NOW[1] * OneMConstant) - (THEN[1] * OneMConstant) + (FourGConstant * (NOW[0] - THEN[0]))"
Where the tags FourGConstant, OneMConstant and RUNNINGTIME are REAL tags. There is of course some loss of resolution (up to 256µs, just over a quarter of a millisecond, or maybe double that, I think), but if the running time is over ~16 seconds then that will not matter.

N.B. Assumes index 0 of the NOW[2] and THEN[2] arrays refers to their GSV CurrentValue MSDINTs; swap the [0]s and [1]s if index 1 refers to the MSDINT.
 
Last edited:
dmroeder, drbitboy, thanks very much for the follow-up. As always, illuminating.
The math explained by drbitboy makes me think that I am grateful to know that I will not be around 12/29/2068 to have to deal with all the problems that you grandchildrenn will have to deal due to this issue.
 
dmroeder, drbitboy, thanks very much for the follow-up. As always, illuminating.
The math explained by drbitboy makes me think that I am grateful to know that I will not be around 12/29/2068 to have to deal with all the problems that you grandchildrenn will have to deal due to this issue.


It's going to be awkward when they clone your mind into an android, with the sole purpose of using your unique knowledge, of doing 64bit math using a 32bit processor, to solve the Y2K68 bug.


But I think the 2038 bug is fast approaching us in our actual liftime (and timeline).
 
Funny that 2038 issue also applies to the IEC61131-3 ‘DATE’ type (signed 32-bit measuring seconds). I guess they’ll fudge with a new Epoch and the type will forever be a small rolling window.
 
So why modify the time base to indicate a date?
Why not have a "Ticks" data type?

Speaking of 64-bit shenanigans this morning:
Was working in Studio 5000 on a math library and found out that you can't use the SIZE() function on an array of LREAL. ;)
 
Last edited:
So why modify the time base to indicate a date?
Why not have a "Ticks" data type?

Speaking of 64-bit shenanigans this morning:
Was working in Studio 5000 on a math library and found out that you can't use the SIZE() function on an array of LREAL. ;)

LOL, almost nailed it :)

I wish they had a SizeOf() instruction so you can get how many bytes something is.
 

Similar Topics

I am updating some of my code that I give customers to put on their plant PLC to communicate with our PLCs. I would like to use an LINT in my...
Replies
13
Views
2,741
Hello I have a 13 digit number I need use so a DINT is out. The number originates as a String, and I need to put that number into a LINT. I saw...
Replies
5
Views
3,150
Hello! I am building a program and transferring a lot of data. To get everything to fit, I am sending multiple LINT values. How can I breakup...
Replies
8
Views
2,738
We have a running appaction ab 5000 plc and a HMI server and 2 thin clients out at oper stations. My question is on the thin client we are...
Replies
0
Views
1,566
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
389
Back
Top Bottom