AB SLC 5/05 programming question

jvillaga

Member
Join Date
Mar 2009
Location
Phoenix, AZ
Posts
4
I have a floating point value (F12:0) that I need to copy to three 3 digit integer addresses (N12:0-N12:2).

I don't need the decimal portion, just the whole number.

In other words, I need the following:
If F12:0 = 999, then N12:0=0 N12:1=0 N12:2=999
If F12:0 = 999,999 then N12:0=0 N12:1=999 N12:2=999
If F12:0 = 999,999,999 then N12:0=999 N12:1=999 N12:2=999

I don't need to worry about rollover (1,000,000,000 just resets to 0,0,0 then continues from there).

Seems pretty easy, but I can't quite figure out how to do it!

thanks,

Jane
 
Think of division instruction [DIV]- use LIM instruction to filter your requirements before divide.
 
Note: this whole discussion begs the question of 'could the initial accumulation of this number be done using three integers instead of using a float?'

DIV will work great if you understand that rounding occurs. Any remainder of .5 or greater causes the destination to be rounded up. So we have to make sure that a remainder (caused by the numbers beneath the three we are extracting) does not cause a round up. We do this by subtracting 1/2 of the least significant digit we want to extract.

Let's try this. I'm going to use F12:1 and F12:2 as an intermediate holding registers. You can adjust as necessary.

MOV F12:0 F12:1 (This is just so that we don't change F12:0 in case you need it again)

Starting with F12:1 we want the top most 3 digits. (You already assured us that it can't go over 999,999,999.)

SUB F12:1, 500000 , F12:2 (We are subtracting half of the least significant digit that we want in the following DIV (1,000,000). Don't worry that this would cause 1,000,000 to change to 500,000. The DIV will worry about that.)

DIV F12:2, 1000000, N12:0 (The topmost 3 digits are now in N12:0)

MUL N12:0, 1000000, F12:2 (You're wondering, did we just undo what we did before? No - the multiplication used the now-rounded value. F12:2 now has the full value of the original top 3 digits only.)

SUB F12:1, F12:2, F12:1 (We take away the full value of the upper three digits. F12:1 now has 999,999 or less. Now we're going to get the next three.)

SUB F12:1, 500, F12:2 (Does this look familiar? Except we are now subtracting half of 1,000)

DIV F12:2, 1000, N12:1 (The middle 3 digits are now in N12:1)

MUL N12:1, 1000, F12:2

SUB F12:1, F12:2, N12:2 (We don't have to do the divide because only has the lower three digits are left as the result of the subtraction.)

That should do it. We had to jump through the subtraction hoops because of rounding. I can't tell if the SLC 5/05 has the LONG data type. If so the whole process would be easier. But that's for another thread.
 
Last edited:
Also, you need to consider that F12:0 (the floating point number) in the SLC is IEEE format... Any whole number over 8388608 will loose accuracy in the least significant digits. If you look at the number displayed in the SLC database it will show only 6 significant digits.
 
Depending on the count rate, and what you're counting, three counters could be used as well. I've seen this done before. All you have to do is move the CACC values into INT values of your choice.
 
I advise you to take HLeap's advice carefully. You might look at another number method to accumulate this count.

We might be able to help more if you could discuss the method of accumulating this number.
 

Similar Topics

I am just finishing up my project, which was my first experience with PLCs. I thank everyone that has helped me work through the RIO and analog...
Replies
11
Views
2,980
Hello, I've taken on yet another basket case old machine running an 7 slot SLC 5/03 PLC.... I have run into a situation where I see the same 4...
Replies
3
Views
5,625
Hello guys. Got Slc5/04 with 9pin d shell port in it. Have cheked some manuals and this port is an RS 232. I want to ask if I could use a generic...
Replies
3
Views
2,367
i have a slc 5/02, but i'm not sure wich software to use (i have both rslogix 500 and 5000) but the main problem is that i dont have the cable, i...
Replies
12
Views
5,727
On site computer is using 1784-PKTX. The computer is connecting to 1785-KA5. I can program the SLC 5/03 with DH+.(1784-PKTX to 1785-KA5 to SLC...
Replies
1
Views
1,746
Back
Top Bottom