Controllogix math to convert float number to scientific parts?

NetNathan

Lifetime Supporting Member
Join Date
Nov 2011
Location
Corona, CA
Posts
2,199
Jees...

Continuing from this thread...
http://www.plctalk.net/qanda/showthread.php?t=85341

I now have the correct pressure in Torr and mBar.

However, in the logic I am working in, the original developer converted his Torr reading to mantissa and exponent, and used the mantissa and exponent tags in the rest of the logic.....go figure.

What CPT instructions do I need to convert a number to mantissa and exponent?
I assume I need 1 CPT to compute mantissa and another CPT for the exponent.


Example:

Pressure reading is 0.0005 Torr
Scientific conversion = 5x10-4 Torr
5 is the mantissa
-4 is the exponent
 
I'm not aware of a function to do this. But I am thinking, have a tag for each. If the mantissa is greater than or equal to 10 subtract 1 from the exponent if less than 1 add 1 to the exponent. Then use xpy to find your multiplier and multiply the reading to find the mantissa.

May need to be in it's own routine on a loop until the mantissa is between 1 and 10.
 
I think this is relatively easy to accomplish. We need to get the number into the range 1 to 9.99999999, and work out what exponent does that.

You could do it with the following code, which uses an iterative loop

Number is negative ? Set a flag "Negative"
Convert the number to positive, use ABS, destination "Mantissa"
Mantissa < 1 ? Set a flag "Fractional"
Set tag "Exponent" to 0
[LBL=Loop]
GEQ Mantissa 1.0 LES Mantissa 10 JMP [Done]
XIC "Fractional", MUL Mantissa by 10, SUB 1 from Exponent
XIO "Fractional", DIV Mantissa by 10, ADD 1 to Exponent
JMP [Loop]
[LBL=Done]If "Negative" NEG Mantissa (restores the original sign)

Your two tags Mantissa and Exponent should now be correct.

PS I haven't actually tested this, but I think it should work...
 
NetNathan, this could be a nice candidate for an Add-On Instruction... Version 16 and above.
 
Daba...I will try your calc but this is how I ended up doing it....after a few hours of trying:

Torr_Tag = .0295

"LOG" instruction on Torr_Tag to get exponent in REAL_Tag = -1.52

"MOV" instruction of REAL_Tag to DINT_Tag to compress exponent value = -2

"CPT" instruction to divide Torr_Tag by 10 to the power of DINT_Tag to get mantissa: Torr_Tag /(10.0** DINT_Tag) = 3

Answer if combined = 3x10-2

This works as long as REAL_Tag result is less than 1, If Torr_Tag is greater than 1, I will have to do a subtract on the DINT_Tag to correct, I am working on that now, however customer is mainly interested in seeing values below 1 Torr.
The gauge reads to above atmosphere (ATM=760 TORR) and I want to resolve the complete range....because I just want to know how. I love challenges in logic....That is why it is called logic.
 
Last edited:
I was intrigued enough to write an add-on, you can have it if you want it, it took me about 20 minutes...
 
Be careful with your MOV REAL to DINT....

Logix5000 systems use a non-conventional rounding method where exactly x.5 is rounded to the nearest EVEN number, not upwards as is traditional.


0.5 -> 0
1.5 -> 2
2.5 -> 2
3.5 -> 4
4.5 -> 4

etc.

It's too late in the day for my brain to determine if that affects what you are doing. My Add-On available if you want it...
 
I think u may be able to do this by just decoding the fp tag. If you cps the fp to a dint, the mantissa & exponent are encoded as per the fp standard. Have done this the other way when I had a fp number as dint....
 
Lemming, if you know the IEEE standard for 32-bit storage of REAL numbers, please share. It will take me a while to find it.
 
Had a quick look and it's @ Wikipedia... I had to do it the other way when I was picking up a fp number from a widget ( can't even remember what it was...) over modbus as 2 int. I'll look it up in the morning when I'm back in front of my PC...
 
Daba,

Your add on worked perfect..
Thanks a million.

No problem. Glad to help.

If anyone else wants the Add-On they are welcome to it.

I can't say for definite that is 100% tested, but I've thrown what I consider to be some obscure REAL values at it (eg. -0.0000000000000000012345) and it seems to work fine.

The only thing I haven't done is trap for NaN (Not a Number), and +/- infinity values (which can certainly exist).

I'll have a look at doing this, and may send you an update if succesful.
 
The "Scientific Notation" instruction did a perfect job of indicating Mantissa and Exponent.

It works both on Torr and Microns through the complete range of the Vacuum Furnace as it "pumps down".

Range tested:
Atmosphere = 760 Torr
to
Furnace approx. ultimate = 10-6 Torr range

Gauge readings:
Torr : 760 to .000005
Microns : 760,000 to .005

As convert by your "Scientific Notation" instruction:
Torr : 7.6 x 10-2 to 5 x 10-6
Microns : 7.6 x 10+5 to 5 x 10-3

Obviously the original pressure number and the mantissa, carried several places below the decimal point, I just compressed for reading.
 
The "Scientific Notation" instruction did a perfect job of indicating Mantissa and Exponent.

It works both on Torr and Microns through the complete range of the Vacuum Furnace as it "pumps down".

Happy that it works for you in your application, and the range of your numbers.

I'm just concerned that, as an add-on instruction, it ought to be able to handle all eventualities of the input values.

The Add-On logic uses an iterative loop to normalise the exponent into the 1.0 to 9.99999 range, adjusting the exponent as it does so. The concern is that if fed with a +/-NaN or +/-Infinity, then the iterative loop would get stuck, and the task watchdog major fault will occur.
 

Similar Topics

'Morning All, I've run into something that is just annoying me on a CLX System using counter modules. The counter modules have 24 bit counters...
Replies
5
Views
12,401
Why does the controllogix redundancy modules use a single mode fiber vs multimode fiber?
Replies
1
Views
80
Hello, I have two 16 point input cards and 1 16 point output card showing module faulted on my IO tree in Logix Designer. The fault code is...
Replies
7
Views
214
Hello, My associate and I are trying to sync up two ControlLogix racks (7-slot chassis) with identical modules. We are able to see the secondary...
Replies
4
Views
193
Trying to setup a message read via Ethernet. I have the path setup as 1, 1, 2, 192.168.66.10 I get an error code 1, ext err 315. I am beating...
Replies
9
Views
231
Back
Top Bottom