0% found this document useful (0 votes)
53 views8 pages

Encoder Formula

Uploaded by

orkunaztek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views8 pages

Encoder Formula

Uploaded by

orkunaztek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Encoders Basics with PIC18F4331

Cornerstone Electronics Technology and Robotics II


• Administration:
o Prayer
• Shaft Encoders:
o Definition: A rotary or shaft encoder is a device that converts the angular
position of a shaft or axle to an analog or digital electrical code, making it an
angular measuring device. The encoder feedback signal is sent to the
system that controls the speed, position, and the direction of rotation of the
shaft.
o A typical encoder uses optical sensor(s), a moving mechanical component,
or a special reflector to provide a series of electrical pulses.
o Basic operation of an optical encoder:
 The continuous infrared light beam from the light source is aimed
through a circular disc with an alternating opaque and transparent
pattern toward the light sensor. The circular disc is fixed onto a
rotating shaft. As the disk rotates, the opaque/transparent pattern
interrupts the light emitted onto the light sensor, generating a digital or
pulse signal output called a tick. As the shaft increases its rotational
speed, the encoder will count more ticks. See the diagram below:

Image from: http://zone.ni.com/devzone/cda/tut/p/id/4623


 Drawing showing encoder action and resulting output voltages:

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.

o Uses: Shaft encoders precisely measure angular movement of rotating


shafts. Shaft encoders are used in printers, plotters, tape drive, positioning
tables, automatic handlers, robotics, factory automation, medical equipment
and high quality instrumentation.
o Industrial Uses:

Measuring Wheel: Measure Distance Traveled for a Cut-to-Length Operation

Linear Position: Position of a Work Table through a Ball Screw


3
Conveyor Belt: Determine Relative Position, Direction and Speed of Travel in a Bi-directional
Conveyor Belt

Linear Actuator: Encode the Position and Velocity of a Rack and Pinion.

Images From http://www.motion-control-info.com/optical-


encoder_design_guide.html

o Applications in Robotics: In robotics, shaft encoders enable the robot’s


program to measure the rotation of its wheels and to then determine:
 Rotational speed of the wheel which can then be used to control the
speed of the wheel (motor control).
 The position of the robot from a known starting point (navigation).
 Typically in robotics, only one encoder sensor is used since the
direction of the motor is already known.
o The number of holes in the encoder disk gives the resolution of the encoder;
the higher the number of holes in an encoder, the higher the resolution.

4
o Formulas:
 Formula for distance traveled / pulse (tick distance):

Distance / pulse = ΠD/H


Where:
Π = 3.14
D = Diameter or the wheel
H = Number of pulses counted in one revolution of the encoder
For example, if:
D = 10 cm
H = 256 pulses in one revolution of the encoder
Then,
Distance / pulse = (3.14 * 10 cm) / 256 pulses
Distance / pulse = 0.12 cm/pulse
(The calculation is an approximation due to the slippage between the wheel and surface.)
• A rule of thumb: The distance/pulse (tick distance) should be
about one thousandth of the distance between the wheels.
 Formula for a Rotating Wheel’s Linear Speed:

Linear Speed = (ΠD*(C/H))/t


Where:
Π = 3.14
D = Diameter or the wheel
C = Number of pulses counted during time t
H = Number of pulses counted in one revolution of the encoder
t = Time for the number of pulses C to be counted
For example, if:
D = 5 cm
C = 20 pulses counted during time t
H = 40 pulses in one revolution of the encoder
t = 0.5 seconds to count C pulses
Then,
Linear Speed = (3.14 * 5 cm * (20 pulses / 40 pulses)) / 0.5 seconds)
Linear Speed = 15.7 cm/sec

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

You might also like