AX1500 encoders serial bytes

14 years 7 months ago #29361291 by cpayne
Replied by cpayne on topic Re:AX1500 encoders serial bytes

Hi. I know I am a moron on the HEX stuff, so please help me a little. I guess I don't understand how to do HEX math that well. 0 - FFFFFFFE (4294967294) = - 4294967294?, how does this work when I have positive numbers say 0000004E (78), 0-78 = -78. I am getting the 4 hex numbers sent to a VB program with no problem, I am just missing how to do this HEX math of 0-value, isn't it always going to be negative?<BR>

Please Log in or Create an account to join the conversation.

14 years 7 months ago #29362042 by cosma
Replied by cosma on topic Re:AX1500 encoders serial bytes
In a nutshell, a negative number is represented in binary in what's called 2's complement.

to represent -1, you substract 1 from 0. You must know before hand how big your word is. If 8 bit, then -1 is FF, if 16 bit FFFF, if 32 bit FFFFFFFF.

To do the conversion, you need to first determine if the binary number is positive or negative. This is done simply by looking at the most significant bit of the word is "1". If it is, then substractign the number from 0 makes it positive again, and you know the sign already.

Note that this means that a number will be considered as positive as long as the most significant bit is 0. If 8-bit, the max positive number is 01111111 (7F) or 127. 8F is negative (-128).

See <A href="en.wikipedia.org/wiki/Two's_complement" target=_blank>en.wikipedia.org/wiki/Two's_complement

Please Log in or Create an account to join the conversation.

14 years 7 months ago #29363714 by cpayne
Replied by cpayne on topic Re:AX1500 encoders serial bytes
OK. so the range of the mailboxes is -127 to +127? Therefore, I can get the sign from any of the mailboxes? I could not get the uchip to sucessfully send the hex number to the VB program so I am sending the asc then converting it to decimal. So all I see is 0-255 at the VB program. If I look at the value of bit.7 (the eigth bit) on the uchip and its 1 of any of the mailboxes, then I know its negative correct? THanks for the help!


Please Log in or Create an account to join the conversation.

14 years 7 months ago #29363908 by cosma
Replied by cosma on topic Re:AX1500 encoders serial bytes
The mailbox has 4 bytes that must be assembled into a single 32-bit word

So the range is +/- 2bilion or so

Please Log in or Create an account to join the conversation.

14 years 7 months ago #29364110 by cosma
Replied by cosma on topic Re:AX1500 encoders serial bytes

Note that you can just take the data from the mailbox, assemble them so that you build the big hex number (example FFEEDDCC), put H in front (HFFEEDDCC) and send it to VB. VB knows that if the number starts with H, format is Hex. I may have the exact syntax wrong but that's the general idea. Look at the VB reference manual.

Please Log in or Create an account to join the conversation.

14 years 7 months ago #29364128 by cpayne
Replied by cpayne on topic Re:AX1500 encoders serial bytes

THanks. RIght now I am taking the 4 bytes and multpliing the MSB by 256^3, plus the next byte * 256^2, plus the next byte *256 + the LSB. It seems to be working fine. Its just the minus sign I have trouble with...

Please Log in or Create an account to join the conversation.

14 years 7 months ago #29364206 by cosma
Replied by cosma on topic Re:AX1500 encoders serial bytes
Dont worry about the sign until after you have assembled the 4 bytes into the single 32 bit. The sign will be the MSB of the 32-bit word.

Please Log in or Create an account to join the conversation.

Moderators: tonysantoni
Time to create page: 0.066 seconds