How to Write a Negative Value Using Modbus

Discuss anything that may not be product related here.
Post Reply
Posts: 13
Joined: Thu Jan 11, 2018 11:44 am

How to Write a Negative Value Using Modbus

Post by om_tech_support_PB » Wed Apr 24, 2019 12:59 pm

Q: I am using driver AZD-AD and am communicating via modbus/RS-485. One of my movements calls for an incremental movement of -2,000 steps. How do I write a negative value to a register?

A: First, it is important to know that we primarily only use the lower registers. For example, when writing positive 2,000 to the positional register of operational data #0, a typical message should look something like the following: 01 06 1803 07D0 and then your checksum. With 01 being the slave address, 06 being the function of writing, 1803 being the lower register of position #0 for the AZ driver (see photo 1 below), and 07D0 being 2,000.
Photo 1.png
Base addresses for operational data
Photo 1.png (69.14 KiB) Viewed 3516 times
However, writing a negative value requires writing to both upper and lower registers, and there are a few steps involved:
First, write FFFF to the upper register.
So using the example above, FFFF would be written to 1802h.

Second, take FFFF, or 65,535 in decimal, and add 1 to make it 65,536.

Next, add the negative value to 65,536.
65,536 + -2,000 = 63,536; and 63,536 = F830h
Therefore, F830h would be the value to write in lower register 1803h.
This would create a movement of -2,000 steps.

Now, there are two ways to do this- writing to a single register, or writing to multiple registers. When writing to a single register, first write FFFF to the upper register, then write the calculated value (F830) to the lower register. The messages would look like the following:
01 06 1802 FFFF (checksum)
01 06 1803 F830 (checksum)

Or if you have the capability to write to multiple registers, then FFFF can be written to 1802h, and F830 can be written to 1803h.

If you have any questions on this process, please contact Tech Support for assistance.

Post Reply