Encoder Formula
Encoder Formula
1
A simple form of an encoder is that of a playing card attached to a
bicycle such that it makes a clicking sound as the wheel rotates. The
playing card makes a clicking sound each time a spoke snaps past the
card. The sound made by the card changes as the speed of the
wheel changes. If you attach the output of an encoder to an amplifier
and a speaker, you would hear clicking just like you do when a playing
card snaps across the spokes of a bicycle wheel.
o Basic Types of Encoders:
There are two basic kinds of encoder information: absolute and
relative. Absolute provides a code which tells you the exact position
of the wheel. Incremental encoders just measure how far the wheel
has moved.
o Quadrature Encoders:
The most common type of incremental encoder uses two output
channels (A and B) ) that are offset from one another by 1/4 of a cycle
(90 degrees). This type of signal is referred to as quadrature and
allows the user to determine not only the speed of rotation but its
directions well. By examining the phase relationship between
the A and B channels, one can determine if the encoder is turning
clockwise (B leads A) or counterclockwise (A leads B). See the
figures below.
If B leads A, for example, the disk rotates in a clockwise direction.
2
If A leads B, then the disk rotates in a counter-clockwise direction.
Linear Actuator: Encode the Position and Velocity of a Rack and Pinion.
4
o Formulas:
Formula for distance traveled / pulse (tick distance):
5
• Hardware Used in the Labs:
o PIC18F4331 Microcontroller:
The main feature of this microcontroller is that it is able to
automatically count pulses from a standard quadrature encoder.
The Quadrature Encoder Interface (QEI) decodes speed and motion
sensor information. It can be used in any application that uses a
quadrature encoder for feedback. See page 170 +/- in the datasheet.
Purchase at:
http://www.microchipdirect.com/ProductSearch.aspx?Keywords=PIC1
8F4331 or at http://parts.digikey.com/1/parts/562472-ic-pic-mcu-
flash-4kx16-44tqfp-pic18f4331-i-pt.html
Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39616b.pdf
o Xavien 2 Motor Driver “XDDCMD-1”:
The “XDDCMD-1” is a dual DC motor driver designed for driving
motors rated at +12V to +55V at up to 3A continuous (6A Peak) per
motor. A minimum +12V is required to operate the “XDDCMD-1”:
The “XDDCMD-1” is based around two of the National Semiconductor
LMD18200T H-bridge semiconductors. The power must be
connected with the proper polarity or the unit will destroy the
LMD18200Ts. Replacement LMD18200Ts available at Digikey (for
about $14.00 each):
http://search.digikey.com/scripts/DkSearch/dksus.dll?lang=en&site=U
S&WT.z_homepage_link=hp_go_button&KeyWords=LMD18200T-
ND&x=0&y=0
Xavien 2 Motor Driver “XDDCMD-1”, Available at:
http://www.encodergeek.com/Xavien_Amplifier.html
The user manual is available at:
http://k5systems.com/XDDCMD_user_manual.pdf
o Small Motor with Quadrature Incremental Encoder:
Motors are designed to run at 6 to 12 volts DC and they draw less
than 3 amps with locked rotor. These DC motors use 2 phase
(quadrature) incremental encoders to detect the speed of the motor
and the distance it has travelled.
The motors are available at:
http://www.encodergeek.com/DCMtr_SMALL.html
• Reference Book: Running Small Motors with PIC Microcontrollers by Harpit Singh
Sandhu (Chapter 15). See: http://www.amazon.com/Running-Small-Motors-PIC-
Microcontrollers/dp/0071633510/ref=sr_1_2?ie=UTF8&s=books&qid=1263737650&
sr=8-2-spell
6
Cornerstone Electronics Technology and Robotics II
Encoders Basics with PIC18F4331 Lab 1 – 4331_encoder1
• Purpose: The purpose of this lab is to acquaint the student with the basic
operation of an encoder hardware and circuit.
• Apparatus and Materials:
o 1 – Breadboard with +5 V and +12V Power Supplies
o 1 – PIC18F4331 Microcontroller, Datasheet at:
http://ww1.microchip.com/downloads/en/DeviceDoc/39616b.pdf
o 1 – 4 MHz Crystal
o 2 – 22pF Capacitors
o 1 – Xavien 2 Motor Driver “XDDCMD-1”, Available at:
http://www.encodergeek.com/Xavien_Amplifier.html
The user manual is available at:
http://k5systems.com/XDDCMD_user_manual.pdf
o 1 – Small Motor with Quadrature Incremental Encoder:
The motors are available at:
http://www.encodergeek.com/DCMtr_SMALL.html
o 1 – Hantronix HDM16216H-5-300S 16x2 LCD, Jameco #618003 See:
http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-
1&productId=618003&catalogId=10001&freeText=618003&app.products.ma
xperpage=15&storeId=10001&search_type=jamecoall&ddkey=http:StoreCat
alogDrillDownView
o 2 – 20 K Potentiometer
o 1 – 4.7 K Resistor
• Procedure:
o Wire the PIC18F4331_hpwm_motor_encoder circuit as shown on the next
page.
o Program the PIC18F4331 with 4331_encoder1.pbp. See:
http://cornerstonerobotics.org/code/4331_encoder1.pbp
o Before connecting the 12V power source:
Rotate the encode wheel in both directions and observe the count on
the LCD display.
Also note that changes in the motor power potentiometer R2 are
reflected on the LCD display.
o Now connect the +12V power supply. If the count decreases in the 65,000s,
switch the two encoder leads into the PIC18F4331.
7
8