Machsupport Forum

Mach Discussion => Brains Development => Topic started by: ulihuber on January 15, 2016, 01:44:54 AM

Title: Modbus input of signed integer
Post by: ulihuber on January 15, 2016, 01:44:54 AM
Hi,

I have a VFD (Danfoss FC-102) connected to my Mach3 by ModbusRTU.
After some ostacles on my way (too short communication timeout,  address registers different from the manual), I managed to get it connected and to control start/stop, direction and speed.
Now I wanted to read out the actual speed, but this is coded as a signed interger (if bit 15 is low, bits 0-14 give the positive value, otherwise negative).
The Mach3 Modbus plugin treats the number as a unsigned integer so that a zero is represented by 2^15 (=32768).
I did not find any way to change the readout method. In addition I am missing bitwise logical operations in the formulas in the Mach3 brain.
So my solution was doing it in brain logic.
(http://www.uhu-servo.de/Brain_signed_integer.jpg)
(You'll recognize that I use a fake input for being able to simulate in the warm office...)

It works, but I wonder if there is a smarter way or a trick for the conversion.

Thanks
Uli