How to copying bits from a float to bit file using AB.

At first informative, then astounding! I learned from this thread that COP doesn't work the same way on MicroLogix as on other AB processors but that there is another instruction CPW that does that job. I also learned that some people are unable or unwilling to accept the straight-forward answer.

I was immediately suspicious of Ron B's solution so did some experimenting. I don't have any appropriate hardware so used softlogix5. Without any further comment, here is what I did and the results I got.

4 unconditional rungs:
COP #B3:0 #F8:0 1
MOV F8:0 L9:0
COP #F8:0 #B3:2 2
COP #F8:0 #L9:1 1

All referenced words cleared and put in run mode
bits 0 & 1 in B3:1 set to '1'
F8:0 displays !NaN!.0
L9:0 displays 0
B3:2 and B3:3 display exact copy of B3:0 and B3:1
L9:1 displays 196608 (words transposed)
 
Yo, Gerry,

I assume no offense was meant - and I assure you none was taken - when you said:
I was immediately suspicious of Ron B's solution so did some experimenting.
Heck, I was suspicious too - which is why I took home a MicroLogix1500 and played around with it to confirm what I was seeing. Unless I made a typographical error in my “reporting” (and I’m not above that sort of thing) then I can guarantee that what I said was correct.

The problem with what you’ve just posted (in #31) is that most of this code can’t be entered into a MicroLogix1500. Only your second rung can actually be compiled and run. All of the other rungs give "Operand sizes do not match!" errors.

This is the same type of mistake I was making when I first tackled Peter’s problem - I was trying out code on an SLC-5/04 processor (which was very handy) and I didn’t realize (at first) that the MicroLogix1500 is so very DIFFERENT from the SLC. Once I fired up a Micro, things really got interesting. I see that you’re using Softlogix5 for your experiments. Since your code won’t even compile in a MicroLogix1500, that’s obviously going to present some problems - and lead to some incorrect conclusions.

Sounds like you and I are both on the same wave-length of trying to learn by doing. Here’s an offer. If you’ve got some code (similar to that above) that you can compile for a MicroLogix1500 program, post it and I’ll run it for you when I get a chance. I can’t promise how soon I’ll be able to get around to it though - my work is starting to pile up. It shouldn't take more than a day or two though.
 
Ron,

Absolutely no offense intended!

The main object of my experiment was to test the proposition that any random bit pattern landing in a floating point register could be recovered by MOVing it through a long integer.

My results indicate that it is easy to get a bit pattern resulting in an invalid floating point number and since a MOV attempts to preserve value rather than bit pattern, moving !NaN! yields 0. I have experimented some more to test the basis for my initial suspicion that the bit pattern for a valid FP number is completely different from the binary representation in a long integer.

The bit pattern for 3.0 is 0100 0000 0100 0000 0000 0000 0000 0000
MOVing this to a long int gives a value of 3 - pattern 0000 0000 0000 0000 0000 0000 0000 0011

As for my little program: the initial COPy into F8:0 is to simulate the arrival of status info from Peter's motion controller. The bit pattern of the status is not expected to represent a valid floating point number, but even if it did, converting it to an integer destroys the information. Yes, I used COP instructions because I was using softlogix5. If I was using a micrologix 1500, I would have used the CPW instruction for my tests. The last line COPying F8:0 to L9:1 is just to record something I hadn't expected - the transposition of the two 16-bit words. I have no idea whether the micro will do the same thing.
beerchug
 
More Info on MicroLogix CPW

The Micrologix's CPW command works as if the processor is a little endian or intel type of processor. If I..

CPW #L20:0 #N7:0 2
CPW #N7:0 #L20:1 2

the number in L20:0 get copied to L20:1 accurately as one expects it should.

The copying of bits from L20:0 to N7:0 and N7:1 are as follows

Code:
L20:0    N7:0    N7:1
    1       1       0
    2       2       0
65535      -1       0
65536       0       1
   -1      -1      -1
-65535      1      -1
-65536      0      -1

I have done a lot of copying bits from one format to another just to make sure I don't get fooled again. The MicroLogix's CPW command works in a very intuitive way if you are familiar with little endian processors where the least significant word gets copied to the lower address. This applies to bits as well.

The info in this thread should be in a Rockwell application note.
 

Similar Topics

I'm not super familiar with the Micrologix line of processors, but I am pretty familiar with RSLogix 500. I'm trying to simply copy a string to...
Replies
4
Views
296
Hi All, I am looking to copy and paste a routine. I know this has to be done offline. My question is, when I go back online, these tags are...
Replies
6
Views
549
Hello everyone, friends. I need help with something related to SCL. In a FB, I need to copy the value in the DB to the DB at another address. I...
Replies
3
Views
1,378
Hello all! Is it possible to COP a SINT array to a UDT structured the same as a SINT array, except all BOOL bits? I have a module that has an...
Replies
5
Views
3,158
Hello, looking for a way to capture and display the accumulated time for a retentive timer in rslogix 500 on a microligix 1400 plc example move...
Replies
3
Views
1,645
Back
Top Bottom