Demand Peripherals     Robotics and Automation Made Easy

QUAD2: Dual Quadrature Decoder

The dual quadrature decoder provides two independent channels of quadrature decoding at a maximum frequency of one MHz. The time required to accumulated the pulse counts is also reported so you can get an accurate estimate of the frequency of the input even at low frequency.



The QUAD2 peripheral is often paired with either the GPIO4 card or the GPIO4-ST card.

The quadrature inputs are on pins 1 and 2 and on pins 3 and 4. A positive step indicates that the lower numbered input pin (1 or 3) went high before the higher numbered pin (2 or 4). That is, the lowered numbered pin leads the quadrature cycle. The maximum input frequency for the decoder is 1 Megahertz.


The video below reviews quadrature encoding and how to get the most from your quad2 peripheral.



The dual quadrature decoder offers a configurable update rate and a select()'able interface to the latest readings.

counts : The quadrature step counts and the number of seconds it took to accumulate those counts. The first number is a signed integer that is the step count and (by the sign) the direction of the first quadrature input. The second number is a float that is the number of seconds it took to accumulate the step count. The third and fourth numbers are the count and accumulation time for the second input channel.

This resource is read-only. You can use the dpcat command and select() to get continuous updates into your program.

update_rate : Update period for the counts resource in milliseconds. The dpcat command and select() on counts will will give a readable file descriptor every update_rate milliseconds. Setting this to zero turns off all output from the quadrature decoder. The update period must be between 0 and 60 milliseconds in steps of 10 milliseconds. That is, valid values are 0, 10, 20, 30, 40, 50, or 60 milliseconds.

This is a read-write resource and works with dpset and dpget but not dpcat.



Imagine that the sample rate is 10 milliseconds and that the channel 0 input step rate is about 160 hertz. A sample output from 'counts' might be:

    1   0.007472   0   0.000000
    0   0.000000   0   0.000000
    1   0.007476   0   0.000000
    1   0.007474   0   0.000000
    0   0.000000   0   0.000000

You can not get an accurate frequency from the count alone but by including the accumulation time you can see that the input frequency is about 133.8 Hertz. The accumulation time is measured to the microsecond which usually gives about four digits of accuracy to a frequency estimate.

The output is both frequency and interval based. This is the best of both worlds in that it is accurate for high frequency inputs and equally accurate for very low frequency inputs.


FPGA Defined Peripherals
User Interface
FPGA Configuration
FPGA Buttons & LEDs
Host Tx/Rx Interface
AVR Interface
Stereo Audio Amplifier
Text LCD and Keypad
Quad WS2812 Interface
Quad Slide Pot
IR Recv/Xmit
6 Digit LCD
RC Decoder
Keyfob RF Decoder
Rotary Encoder Interface
Quad Touch Interface
Motion Control
Dual DC Motor Controller
Dual Quadrature Decoder
Quad 13 Bit Servo
Bipolar Stepper Controller
Unipolar Stepper Controller
Simple Input / Output
Quad Binary Output
Quad Binary Input
Octal Input/Output
32 Channel Binary Output
32 Channel Binary Input
Quad Serial Output
Octal Serial Output
Octal 12-bit ADC
Quad Ping))) Interface
Pololu QTR Interface
Octal SRF04 Interface
Generic I2C
Generic SPI
Octal 8-Bit DAC
Quad Digital Potentiometer
Quad PWM Output
Quad PWM Input
Quad Event Counter
Real Time Clock
Dual Pulse Generator

Interface Cards
Control Cards
User Interface
Stereo Audio Amplifier
IR Recv/xmit
Six Digit LCD Display
Keyfob RF Receiver
Rotary Encoder
Quad Switch Card
Text LCD / keypad
Quad Slide Pot
Quad Touch Interface
Motion Control
Dual 7-amp H-bridge
Quad Open Drain Driver
Quad 10 Amp Relay Card
Input / Output
Octal 8-Bit DAC
Quad Digital Potentiometer
Octal 12-bit ADC
Octal SRF04
I2C Prototyping
SPI Prototyping
USB 2.0 Hub
Real Time Clock
Octal Input/Output
32 Channel Input
32 Channel Output
Power Distribution Card
15 Amp Power Distribution
5 Volt Switching Regulator
ATX Power Break-Out Card
Disk Drive Power Break-Out
MP43 Aluminum Mounting Plate
WW4 Large Prototyping Card
WW2 Prototyping Card
WW1 Small Prototyping Card
SMP SMD Prototyping Card