SLC 32b math

Lakee911

Member
Join Date
May 2006
Location
Columbus, OH
Posts
98
I need to multiply a float (0 - 36) by 1,000,000 and then totalize this. What I am thinking of doing is using the 32b math operations, but I'm not sure exactly how it will work.

Let's say that I take this float and multiply it by 1,000,000.0 it will of course come back as a float and not a integer. That's bad. How do I fix that>?

Second, how do I utilize S:13 and S:14 for 32b add operations?

Thanks,
Jason
 
That's a good point ... but I would like to know hown many total gallons. ... or well, maybe at least how many thousand gallons. That would give me X.XXX million gallons. Maybe I'll just multiply by 1000 ... but 36 x 1000 = 36,000 which is above 32,767. :(
 
You are simply running up against the encoding limits on your system. Scaling by a factor, any factor, won't help; especially if using floating point numbers.

Eventually, even if you maintain a count as a real, you will not be able to add a new value to it as it will fall outside of the machine epsilon value of the floating point representation. AFAIK, the SLC deals only with 32 bit floating point values, which at most can contain 7 digits of precision. You are already at that limit by multiplying 36 * 1,000,000.

Break it down into two (or more) separate integer counters, one for units (0-999), one for thousands (0,000 - 999,000) (continue as necessary).

Re-aggregate the values in a higher end system if necessary (HMI, Database, etc).
 
You will have to convert the float to a 16 bit integer ranged 0 to 3600, and then do a 16 bit multiply by 10,000. You'll get an integer overflow in the destination register and the 32 bit result will be in the math registers. After the multiply make sure you clear the overflow minor error bit or the processor will fault at the end of the scan.

If you are just wanting to display the data then go with Ron's suggestion or use a large volume unit (kgal?) in the PLC and then multiply that by some conversion factor at the HMI instead of the PLC.
 
Last edited:
Questions ...

When I have an OVERFLOW and the result (of an ADD or MUL) is moved into S:13 (lo) and S:14 (hi), what happens to the sign-bit of S:13 and in my destination?

When I use an STI, I'm assuming that the subroutine that I designate will only be executed once. I'm assuming one shots won't be needed on (certain) math functions. Righto?

Thanks
 
The sign bit of the result is preserved in the math register. The destination register contains the unsigned integer overflow, however since the SLC always interprets bit 15 as a sign bit then you will see a negative number in the data monitor if bit 15 is set.

An STI performs a single scan for each configured time period, independent of the main scan. So a 500mSEC STI runs twice a second. As for whether one shots are needed I can't say without seeing your code.
 
Please correct if I'm mistaken, but on the SLC, an overflow of an integer field will also result in setting the minor error bit, which must be cleared before the end of the scan, or the processor hard faults.
 
That is correct Ron. If a programmer wants to use the math register for 32 bit math he must correct any minor error bits before the end of the scan. IMO, its good practice to watch the minor error bits anyways.
 

Similar Topics

I’m attempting to send a temperature from a SLC-5/02 to an EZiMarquee display. The vendor said to use a MSG instruction to send the data to the...
Replies
1
Views
86
Hello all. I have a few SLCs in my plant and of late we've seen a weird issue: The system will be running normally and then randomly the outputs...
Replies
2
Views
101
I am working on setting up a Prosoft Datalogger model PLX51-DLplus-232. This unit will be collecting data from a SLC 5/05 on the DB9 port set to...
Replies
3
Views
104
I have a redundant ControlLogix being set up. This program reads a value from a remote site which happens to be SLC PLC. Rockwell mentions SLC...
Replies
2
Views
96
Hello, I have a ControlLogix redundant controller being set up. The program reads a value from a remote site which hosts a SLC PLC. Rockwell...
Replies
0
Views
80
Back
Top Bottom