Signed & Unsigned Integers

dbh6

Lifetime Supporting Member
Join Date
Jan 2013
Location
Central, NJ
Posts
552
Hello All,

Quick question, in Logix 5000 i noticed that you cannot specify a UINT data type (Integer that cannot accept negative numbers) only option from what i know are INT, DINT, SINT, reason why i'am asking this is because i'am currently writing logic for error codes for a Yaskawa V1000 drive, I correctly mapped the Input and Output Assembly instances through implicit messaging, however the error code tag which is an INT is displaying -28672 decimal which i believe is a signed decimal value alas the negative number, but i could be wrong. I know you can change the style to hex, which i did and tested to have a hex value of 16#9000 which equates to 36864 decimal, so basically what i'm trying to get at is, be able to display 36864 as a decimal value instead of -28672. Once more i know changing the style can solve the issue but i just want to know how to do it the other way for reference purposes. Thanks.
 
If your Yaskawa drive is using unsigned integers, and can send values greater than 32,767 in a 16-bit register, then a Logix5000 INT tag will misinterpret the value when bit 15 is set.

The problem is that that bit 15 of an INT tag isn't used for "value", it is the sign bit.

There is a work-around....

Use a COP instruction to move the 16-bit UINT data from the drive into a 32-bit DINT tag in the controller. Don't use a MOV instruction, which will still "see" the UINT as a signed INT.

A DINT will be capable of holding the whole range of the UINT values (0-65,535), without misinterpreting them.
 
@ daba i just tried it, and its working, so to understand what had happend the COP instruction copies the integer value into the Lower INT of the DINT tag, that way bits after the 16th bit are all 0, therefore the negative goes away because, we are now reading from bits 0 all the way to bit 31, so the bit pattern looks like this
Hex = 9000
Decimal = 36864
Binary = 00000000000000001001000000000000

If you have further remarks please let me know. Thanks
 
@ daba also in relation to this, do you know how to write in ladder on a conversion formula from decimal to Hex??
 
@ daba i just tried it, and its working, so to understand what had happend the COP instruction copies the integer value into the Lower INT of the DINT tag, that way bits after the 16th bit are all 0, therefore the negative goes away because, we are now reading from bits 0 all the way to bit 31, so the bit pattern looks like this
Hex = 9000
Decimal = 36864
Binary = 00000000000000001001000000000000

If you have further remarks please let me know. Thanks

You are correct, the 16-bit unsigned integer becomes the lower 16 bits of a 32-bit signed integer, so the highest bit of the unsigned integer is now seen as bit 15 of a 32-bit signed number. In this way, bit 15 of the unsigned INT, which has numerical significance, is put into bit 15 of the 32-bit signed DINT, so that the numerical significance is retained.

To be absolutely certain that nothing can go wrong with this, it would be preferable to precede the COP with a CLR of the DINT destination of the COP instruction, to ensure that none of the bits 16 to 31 can be on.

Another method that would work equally well would be to use a BTD instruction. BTD the 16-bits from the unsigned INT into the lower 16-bits of the signed DINT.

Your choice, but the COP is more efficient.
 

Similar Topics

Is there a way in CX-Programmer to ad UINTs together with an instruction without a compiler warning. Ladder Rung: Warning: Instructions...
Replies
2
Views
1,223
Hello, I'm using the MSG command with RSLogix 500. The values are being read in as signed integers. Is there a way I can read them in as an...
Replies
10
Views
6,471
Ok, I just want to make sure I'm understanding this correctly. I know that in PanelBuilder32 I can select signed or unsigned integers. I have...
Replies
6
Views
4,308
Is there any way to force Wonderware to see a number as an unsigned integer? I have Wonderware 9.5, getting numbers from an AB PLC5/80E, and...
Replies
11
Views
13,590
I'm having to make an AOI to use with a generic ethernet device because the manufacturer does not provide an AOP. I just want to do a sanity check...
Replies
13
Views
1,151
Back
Top Bottom