- Quadrature Input (Mode 8) [UE9 Datasheet] | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver - Quadrature Input (Mode 8) [UE9 Datasheet]

Requires 2 timer channels used in adjacent pairs (0/1, 2/3, or 4/5). Even timers will be quadrature channel A, and odd timers will be quadrature channel B. The UE9 does 4x quadrature counting, and returns the current count as a signed 32-bit integer (2’s complement). The same current count is returned on both even and odd timer value parameters.

Writing a value of zero to either or both timers performs a reset of both. After reset, a read of either timer value will return zero until a new quadrature count is detected. If a timer is reset and read in the same function call, the read returns the value just before the reset.

4X Counting

Quadrature mode uses the very common 4X counting method, which provides the highest resolution possible.  That means you get a count for every edge (rising & falling) on both phases (A & B).  Thus if you have an encoder that provides 32 PPR, and you rotate that encoder forward 1 turn, the timer Value register will be incremented by +128 counts.

Z-phase support

Quadrature mode supports Z-Phase. When enabled this feature will set the count to zero when the specified IO line sees a logic high.

Z-phase is controlled by the value written to the timer during initialization. To enable z-phase support set bit 15 to 1 and set bits 0 through 4 to the DIO number that Z is connected to. EG: for a Z-line on EIO3 set the timer value to 0x800B or 32779. This value should be sent to both the A and B timers.

Note that the LabJack will only check Z when it sees an edge on A or B.

Z-phase support requires Control Firmware 2.11 or later.

2's Complement

Other timer modes return unsigned values, but this timer mode is unique in that it returns a signed value from -2147483648 to +2147483647.  That is, a 32-bit 2's complement value.  When you do a timer value read and get back a single float from the UD driver, the math is already done and you get back a value from -2147483648.0 to +2147483647.0, but when using the special channels 20x/23x/224 you get the LSW and MSW separately and have to do the math yourself.  Search for 2's complement math for your particular programming language.

In a language such as C++, you start by doing using unsigned 32-bit variables & constants to compute Value = (MSW * 65536) + LSW.  Then simply cast Value to a signed 32-bit integer.

In a language such as Java that does not support unsigned integers, do everything with signed 64-bit variables & constants.  First calculate Value = (MSW * 65536) + LSW.  If Value < 2147483648, you are done.  If Value >= 2147483648, do ActualValue = -1 * (4294967296 - Value).