You are on page 1of 23

# Lecture 9:

Pulse Module (eQEP)
ECEN 442:
DSP Based
Electromechanical Motion Control
Spring 2017
Advanced Electric Machines & Power Electronics (EMPE) Lab
Learning Objectives
Incremental Shaft Encoder
Describe physical structure and basic operation principles
Translation of Encoder Pulses into Motion Data
Explain relationship between encoder pulses and shaft motion
eQEP Module
In lab, you will configure the eQEP module for measuring shaft
rotation data from an incremental shaft encoder
Calculate shaft speed using fixed-time and fixed-
distance approaches

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 2 / 23
Encoders

## It has mechanical and electronic parts

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 3 / 23
Incremental Encoders
Incremental encoders do NOT generate a code
corresponding to the shaft position
Absolute encoders do
Instead, incremental encoders generate pulses based
on shaft movement
Relative movement of the shaft can be measured by
counting these pulses (edges)
Usually, the act of counting is not done by the encoder
The eQEP module takes care of it
By measuring the time elapsed between pulses, rotor
speed can be calculated

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 4 / 23
What is an Incremental Quadrature Encoder?
A digital (angular) position sensor
photo sensors spaced /4 deg. apart
slots spaced deg. apart /4
light source (LED)

QEPA

QEPB
shaft rotation

## Incremental Optical Encoder Quadrature Output from Photo Sensors

A very basic way to measure position is to count pulses on A or B
Suppose 1000 lines on the disk
Then 250 pulses on A or B indicate a shaft rotation of 90 RELATIVE to
its initial position
2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 5 / 23
The Encoder: Lines
1 line

1 3

2 4

1 line

## 1 line = 4 quadrature edge or clock events

Counting edges on both A and B results in a 4x the resolution
2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 6 / 23
What is the point of using two light sensors?

## What does the additional Index Line do?

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 7 / 23
eQEP Module
The eQEP module is a logic circuit inside the DSP
A peripheral
It facilitates measurement of position and speed with
minimum CPU intervention
and counts them
The eQEP hardware also extracts direction data and
reflects it in the QEPSTS:QDF flag bit
The eQEP decodes the encoded data

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 8 / 23
eQEP Module
The decoder submodule of the eQEP module generates a
QCLK clock pulse on every edge of the QA and QB signals
Counting the number of edges instead of pulses doubles the
position measurement resolution
Use of two light sensors again doubles the resolution.
If there are 1000 lines on the disk:
The resolution is 4*1000 clock pulses per revolution
That means the smallest detectable shaft movement is
360/4000
Some Encoders have built-in decoders, i.e., they generate
work with such encoders. (The QDECCTL:QSRC should be
set to 1)
2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 9 / 23

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 10 / 23
Decoding Direction
At each QCLK interval, only 1 of the QEP signals changes status
The optical sensors are mounted with a 90 phase shift
Counting the number of edges instead of pulses doubles the position
measurement resolution
If a change of status in both is detected, the QFLG:PHE error flag will
be set and an interrupt may be requested

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 11 / 23
Delfino eQEP

## Has 3 eQEP modules

Each eQEP module has 4 input pins multiplexed with
GPIO pins
Have to configure GPxGMUX and GPxMUX
Recommended to change GPxGMUX while GPxMUX = 0
GPxQSEL should be set to 0 (synchronous operation)

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 12 / 23
eQEP
Measures position by counting QCLK pulses in the 32-bit eQEP Position
Counter Register (QPOSCNT)
The QPOSCNT increments on a QCLK pulse when the direction signal
(QDIR) is one (forward)
The QPOSCNT decrements on a QCLK pulse when the direction signal
(QDIR) is zero (reverse)
The position counter has 32 bits
Cannot exceed the range [0 , 232-1]
The maximum value of QPOSCNT is imposed by the programmer via
the QPOSMAX register, and its minimum is zero
It wraps around to zero when it overflows (instead of going to QPOSMAX+1)
It jumps to QPOSMAX upon an underflow (instead of going to -1)
It can also be configured to reset to zero upon a Unit Time-Out event via
the QEPCTL:PCRM field

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 13 / 23
eQEP Main Signals

QPOSMAX=3999 (0xF9F)

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 14 / 23
Simple Speed Measurement Method
Configure the eQEP module and reset QPOSCNT to 0
Configure one of the CPU or ePWM timers to periodically
request an interrupt
Inside the ISR, read and then reset QPOSCNT
This value indicates the shaft rotation during the timer period
Divide the movement by the timer period to find speed
If required, scale the result to the desired unit (rpm, rad/sec, etc)

## This approach fixes the time period and measures the

distance traveled during each interval
Speed sampling rate is determined by the period of the timer

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 15 / 23
Speed Measurement Using eQEPs
Unit Timer
Use the eQEPs 32-bit Unit Timer, i.e., QUTMR
It always operates at the CPU clock (non-prescalable)
Automatically resets to zero when it hits its period register
value (QUPRD)
Generates a Unit Time-Out pulse upon resetting
The QPOSCNT value is automatically captured and saved in the
QPOSLAT register
An interrupt is requested from the PIE
The program can read the latched value in the ISR and
calculate speed
The numerator of v(k) depends on rotor speed,
The denominator is fixed and does not depend on speed.
2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 16 / 23
Speed Measurement Using eQEPs
Unit Timer
Angular velocity formula

x(k) - x(k - 1)
v(k ) ,
T

## The numerator of v(k) depends on rotor speed

The denominator is fixed and does not depend on speed
v(k) = most recent speed sample

## T = QUTMR period value

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 17 / 23
Speed Measurement using eQEPs
Unit Timer

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 18 / 23
Problem with the Unit Timer Position
Measurement Approach
What is the problem with this unit timer position
measurement approach?
Hint: think about the velocity formula

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 19 / 23
Speed Measurement Over a Unit Distance
Instead of counting pulses in a unit of time, this approach
measures the elapsed time during a unit of distance
Unit of distance is a multiple of QCLK edges
The previous approach fixed time and measured distance
This approach fixes distance and measures time
It uses the eQEPs Capture Timer
If an application requires high accuracy at low and high
speeds?
Switch between the two approaches based on the motor speed

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 20 / 23
Comparison of Speed Measurement
Approaches
Fixed time interval

## Good for high speed

Numerator goes to ~0 at low speed
Fixed distance interval

## Good for low speed

Denominator goes to ~0 at high speed

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 21 / 23
Comparison of Speed Measurement
Approaches

Fixed
time
approach

Fixed
distance
approach

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 22 / 23
eQEP Module Block Diagram
Measure the elapsed time
between the unit position events;
used for low speed measurement
Generate periodic
Capture
calculations clock mode
clock to indicate proper
operation of the motion EQEPxA/XCLK
control system
32-Bit Unit EQEPxB/XDIR
QEP Decoder EQEPxI
Watchdog

SYSCLKOUT
Position Counter
& Compare
Generate the direction and
clock for the position counter
Measure rotor in quadrature count mode
movement and generate
a sync output and/or
interrupt on a position
compare match

2017 Texas A&M University Advanced Electric Machines & Power Electronics (EMPE) Lab 23 / 23