ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus message two's complement

I am using Lookout to control a variable speed drive via Modbus ethernet.  If I send a number from 0 to 20000 to address 400002, it adjusts speed in the forward direction from 0 to 100%.  I need to send the "two's complement" of that number to control reverse speed.  Simply sending -20000 is not producing reverse direction on the drive.  How do I send a two's complement of a number?

0 Kudos
Message 1 of 10
(9,592 Views)

I need to use Lookout to control a variable speed drive by using two's complement for the negative direction.  It appears, the Lookout data member does not allow you to enter a negative number to write to Modbus 40002 or 40003.  Any way around this?

0 Kudos
Message 2 of 10
(9,158 Views)

Were you able to find an answer to the 2's compement problem?

0 Kudos
Message 3 of 10
(9,157 Views)

Use the float datamembers

-----------------------------------------------------------------------
Forshock - Consult.Develop.Solve.
0 Kudos
Message 4 of 10
(9,152 Views)

Thanks for this.  Can you be a bit (pardon the pun) more descriptive as to how a floating point number ends up in Modbus 40003 as two's complement?

0 Kudos
Message 5 of 10
(9,146 Views)

I myself do not have the time to make an example, but this could help point you in the right direction.

 

http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

http://planetcalc.com/747/

http://twos-complement.calculator.io/

-----------------------------------------------------------------------
Forshock - Consult.Develop.Solve.
0 Kudos
Message 6 of 10
(9,142 Views)

Basically what I discovered, behind the math geeks' mumbo jumbo, is that any binary number greater than half of the range is the equivalent of a negative number.  So for a 16 bit integer, which has a decimal range of  0 to 65535, any number greater than 32767 is a negative of a number below 32766.  This of course limits the decimal range to -32766 to +32767.  

 

If I want to transfer the value +10000 the integer value would be 10000.  If I want to transfer -10000 the integer value would be (65535 - 10000) which is 55535.

 

If I want to transfer the value +25535 the integer value would be 25535.  If I want to transfer -25535 the integer value would be 40000. 

 

Let me put it a more intuitive way.  Positive numbers count forward from zero.  Negative numbers count backwards from 65535, or whatever the top decimal number of the binary range is.

Message 7 of 10
(9,090 Views)

Glad you got it figured out.

 

And thanks for posting a solution

-----------------------------------------------------------------------
Forshock - Consult.Develop.Solve.
0 Kudos
Message 8 of 10
(9,084 Views)

After some googling of 2's complement and significant trial and error, I managed the same result.  I like your explanation but one still has to shake his head a few times while scaling this math.  I am working with a ABB ACS 600 drive.  ABB was no help in this matter.  I will let them know the solution.  Thanks

0 Kudos
Message 9 of 10
(9,072 Views)

That's funny.  The original question was from when I was working with an ABB ACS 550 drive, and I found ABB to be no help on this question as well.  In every other question for which I have called their tech support, they have been excellent, but this one issue was a dead end.  "Just send over the two's complement"  "What is that?"  "I don't know, just send it over" 

0 Kudos
Message 10 of 10
(9,038 Views)