Skip to main content

Report Encoders

Returns the MBx24 encoders counters representation in a bulk.

Request

012345678910111213141516171819202122232425262728293031
ID48

Request Structure

ByteValueSizeTypeDescription
0ID1BINMBx24 address (ID)
1481BINReport Encoders instruction code

Response

012345678910111213141516171819202122232425262728293031
ID48V1V2V3V4V5V6V7V8

Response Structure

ByteValueSizeTypeDescription
0ID1BINMBx24 address (ID)
1481BINReport Encoders instruction code
2V11BINEncoder 1 number of steps and magnitude values
3V21BINEncoder 2 number of steps and magnitude values
4V31BINEncoder 3 number of steps and magnitude values
5V41BINEncoder 4 number of steps and magnitude values
6V51BINEncoder 5 number of steps and magnitude values
7V61BINEncoder 6 number of steps and magnitude values
8V71BINEncoder 7 number of steps and magnitude values
9V81BINEncoder 8 number of steps and magnitude values

Remarks

After answering the report encoders instruction, the MBx24 resets all encoder counters to zero. Although it’s rare to happen, if no report is requested for a long period ( more than 5000ms ) and the encoders counter over rolls the maximum or minimum counting steps, it will be automatically set to 0, so those steps are lost. To prevent this, request a report within useful time, if encoders are present, to make the simulation updated and not lose encoder steps.

With this report, users receive the accumulated count of steps, positive or negative, in a byte array since last report. As answers are always in a byte type, these reported values have to be processed to be used. Each byte carries the step counter value but also its magnitude, i.e., which is the direction the encoder was rotated. The rotation magnitude may be positive, negative or none. This is represented by the Most Significant bit ( MSB ) of the value. If the MSB is 1, the value is negative.

Bit Position76543210
ValueMSB1010101

Table 3 - Encoder returned value if 85 steps In table 3, if MSB is 1, the resulting step counter is -85. If MSB is 0, the step counter is 85.

A simple way to retrieve steps count and magnitude:

a) Declare a variable for each value:

Int EncoderCounter;
byte ReportedValue;

b) Test if motion occurred:

if (ReportedValue == 0) {
return 0;
}
EncoderCounter = RetrieveValueFrom(ReportedValue);

c) Retrieve the value from a function:

Int RetrieveValueFrom(Int ReportedValue) {
if ((ReportedValue & 0x80) == 0x80) { // Test if it is negative
return (0x80 - ReportedValue) * -1; // If it is negative
}
return ReportedValue; // If it is positive
}

The firmware ensures that, when the number of steps is 0, the magnitude is also set to 0. This way the resulting reported byte for that particular encoder is 0 and not ‘-0’. This simplifies comparisons like in step b) of the example.

As can be deduced, each encoder step counter is truncated, meaning that only values from -127 to 127 will occur.