# Binary math and absolute encoders

## An absolute encoder, while necessary and useful, can offer some challenges if the user doesn’t understand the mathematics of how they work and function.

07/12/2016

There are numerous applications that employ encoders in automation control. The purposes are too numerous to list. However, there is one type of encoder that is used that does offer some challenges to those unfamiliar with the mathematics of how they work: The absolute encoder.

An absolute encoder provides a unique number that reflects the angle of rotation, typically coupled to a shaft. These encoders will typically be characterized by their resolution, reflected in the number of increments per revolution, and the type of output, either binary or Gray code. The resolution is important in that this reflects the number of slices that the full rotation of the shaft is cut up into; examples are 16 (4-bit), 256 (8-bit), 4096 (12-bit), etc. The type of encoding is relevant to how the sensor is configured which we will not be getting into this aspect at this time. Suffice it to say that the end result is simply a number in the controller that is monitoring the encoder.

For the purpose of this example, we will be assuming an 8-bit resolution. This is designed to primarily keep the numbers and bit patterns manageable.

Provided that the encoder never makes a full revolution, there is no need to go much further. However, this is almost never the case. As such, we have to be concerned with how to determine either the amount of rotation that has been experienced or what is the final encoder value based on desired rotation. The fact that the encoder will "rollover" can give those unfamiliar with binary math some concern, which has led to complex code being written to address this issue. The good news is that this does not need to occur; this is where binary arithmetic can step in and save the day.

For the encoder in question, the range of values returned will range from 0 to 255 (8-bit). The controller type that this unit is connected to is assumed to support various bit resolutions with its decimal numbers and 2's complement numerical handling. We will also assume a "forward" rotation; the opposite will be mentioned later. Now that the stage has been set, let's take a look at the numbers.

For the first example, let's assume an initial value/reading of 192 and the new value of 225. This is very simple (assuming that it didn't make a complete revolution) and is easily handled with subtraction. 225 - 192 = 33.

The next case is a bit more complicated. In this case the encoder has rolled over.

Depending on the type of controller there might be more than 16 bits in the binary representation; the operations will be the same, however.

In these cases, there will be logic applied that tries to determine if there was a roll over and subsequently compensating with some further math. While the additional math cannot be avoided, the additional logic can. The use of a logical AND instruction produces the desired result. Since this is an 8-bit encoder, we simply need to perform a Boolean AND operation with the decimal number 255 (binary 11111111).

In this case, the encoder advanced by 101 units.

The elegance of this is that the principle works in the other direction as well. In this case we want to see what the new reading would be if we want to advance by a specific number (this is an addition operation).

By applying this property continuously to the equation, whether through addition or subtraction, allows for consistent code to be developed with no additional branching logic to be applied to keep the code as concise as possible. This step can be applied iteratively in the case of multiplication.

It should be evident at this point that whether the encoder is coupled with the shaft in either rotational direction, the only thing that needs to be considered is whether or not addition or subtraction is to be applied given the operation (determining the amount of rotation or calculating the new position). This method works for any binary consistent encoder, meaning the values are evenly divisible on a bit boundary. Values such as 0 to 355 (for degrees) will not work in the same way.

Not only does an absolute encoder ensure complete angular reproducibility, but the operations required are simple and straightforward. We just need to keep this simple mathematical principle in mind.

This post was written by Jeff Monforton. Jeff is a senior engineer and consultant at Maverick Technologies, a leading automation solutions provider offering industrial automation, strategic manufacturing, and enterprise integration services for the process industries. Maverick delivers expertise and consulting in a wide variety of areas including industrial automation controls, distributed control systems, manufacturing execution systems, operational strategy, business process optimization, and more.

Maverick Technologies is a CSIA member as of 7/12/2016.

The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by Control Engineering subscribers. Vote now (if qualified)!
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Digitalization integration, process sensors, edge computing, fog computing, condition monitoring, and motors
DCS visibility, alarm management, motors and drives, robotic machining, Engineers' Choice winners
Factory automation controllers, Ethernet updates, System Integrator of the Year roundtable, Inside Process and VFDs
This article collection contains several articles on how advancements in vision system designs, computing power, algorithms, optics, and communications are making machine vision more cost effective than ever before.
Programmable logic controllers (PLCs) represent the logic (decision) part of the control loop of sense, decide, and actuate. As we know, PLCs aren’t the only option for making decisions in a control loop, but they are likely why you’re here.
This digital report explains how plant engineers and subject matter experts (SME) need support for time series data and its many challenges.
Focus on power systems, process safety, electrical and power systems, edge computing in the oil & gas industry
Product of the Year winners, Pattern recognition, Engineering analytics, Revitalize older pump installations
Control room technology innovation; Practical approaches to corrosion protection; Pipeline regulator revises quality programs
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by Control Engineering subscribers. Vote now (if qualified)!
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Digitalization integration, process sensors, edge computing, fog computing, condition monitoring, and motors
DCS visibility, alarm management, motors and drives, robotic machining, Engineers' Choice winners
Factory automation controllers, Ethernet updates, System Integrator of the Year roundtable, Inside Process and VFDs
This article collection contains several articles on how advancements in vision system designs, computing power, algorithms, optics, and communications are making machine vision more cost effective than ever before.
Programmable logic controllers (PLCs) represent the logic (decision) part of the control loop of sense, decide, and actuate. As we know, PLCs aren’t the only option for making decisions in a control loop, but they are likely why you’re here.
This digital report explains how plant engineers and subject matter experts (SME) need support for time series data and its many challenges.
Focus on power systems, process safety, electrical and power systems, edge computing in the oil & gas industry
Product of the Year winners, Pattern recognition, Engineering analytics, Revitalize older pump installations
Control room technology innovation; Practical approaches to corrosion protection; Pipeline regulator revises quality programs
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.
The Engineers' Choice Awards highlight some of the best new control, instrumentation and automation products as chosen by Control Engineering subscribers. Vote now (if qualified)!
The System Integrator Giants program lists the top 100 system integrators among companies listed in CFE Media's Global System Integrator Database.
Each year, a panel of Control Engineering and Plant Engineering editors and industry expert judges select the System Integrator of the Year Award winners in three categories.
This eGuide illustrates solutions, applications and benefits of machine vision systems.
Learn how to increase device reliability in harsh environments and decrease unplanned system downtime.
This eGuide contains a series of articles and videos that considers theoretical and practical; immediate needs and a look into the future.
Digitalization integration, process sensors, edge computing, fog computing, condition monitoring, and motors
DCS visibility, alarm management, motors and drives, robotic machining, Engineers' Choice winners
Factory automation controllers, Ethernet updates, System Integrator of the Year roundtable, Inside Process and VFDs
This article collection contains several articles on how advancements in vision system designs, computing power, algorithms, optics, and communications are making machine vision more cost effective than ever before.
Programmable logic controllers (PLCs) represent the logic (decision) part of the control loop of sense, decide, and actuate. As we know, PLCs aren’t the only option for making decisions in a control loop, but they are likely why you’re here.
This digital report explains how plant engineers and subject matter experts (SME) need support for time series data and its many challenges.
Focus on power systems, process safety, electrical and power systems, edge computing in the oil & gas industry
Product of the Year winners, Pattern recognition, Engineering analytics, Revitalize older pump installations
Control room technology innovation; Practical approaches to corrosion protection; Pipeline regulator revises quality programs
Automation Engineer; Wood Group
System Integrator; Cross Integrated Systems Group
Jose S. Vasquez, Jr.
Fire & Life Safety Engineer; Technip USA Inc.
This course focuses on climate analysis, appropriateness of cooling system selection, and combining cooling systems.
This course will help identify and reveal electrical hazards and identify the solutions to implementing and maintaining a safe work environment.
This course explains how maintaining power and communication systems through emergency power-generation systems is critical.