EEEN21000
GROUP 30 Line Following Buggy
Loading...
Searching...
No Matches
QEI.h File Reference
#include "mbed.h"
Include dependency graph for QEI.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  QEI
 Handle reading pulses from encoder. More...
 

Macros

#define PREV_MASK   0x1
 Mask for the previous state in determining direction. More...
 
#define CURR_MASK   0x2
 Mask for the current state in determining direction. More...
 
#define INVALID   0x3
 XORing both states where both bits have changed. More...
 

Macro Definition Documentation

◆ PREV_MASK

#define PREV_MASK   0x1

Mask for the previous state in determining direction.

Author
Aaron Berk

LICENSE

Derivative work created in Jan 2021 by D.Smart, which has the following changes:

  • Update for MBED OS 6 ('callback' added to member ISRs)
  • Added counter for non-grey-code transitions
  • Added set functions to initialize counts to known values
  • Added get functions for error counters

No copyright claim is being made on these changes.

Copyright (c) 2010 ARM Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DESCRIPTION

QEI.

A quadrature encoder consists of two code tracks on a disc which are 90 degrees out of phase. It can be used to determine how far a wheel has rotated, relative to a known starting position.

Only one code track changes at a time leading to a more robust system than a single track, because any jitter around any edge won't cause a state change as the other track will remain constant.

Encoders can be a homebrew affair, consisting of infrared emitters/receivers and paper code tracks consisting of alternating black and white sections; alternatively, complete disk and PCB emitter/receiver encoder systems can be bought, but the interface, regardless of implementation is the same. Rotational position in degrees can be calculated by:

\( rotational\ position\ =\ \frac{pulse\ count}{X\ \cdot \ N} \cdot \ 360\\\)

Where X is the encoding type [e.g. X4 encoding => X=4], and N is the number of pulses per revolution.

Linear position can be calculated by:

\( linear\ position\ =\ \frac{pulse\ count}{X\ \cdot \ N} \cdot \ \frac{1}{PPI}\\\)

Where X is encoding type [e.g. X4 encoding => X=44], N is the number of pulses per revolution, and PPI is pulses per inch, or the equivalent for any other unit of displacement. PPI can be calculated by taking the circumference of the wheel or encoder disk and dividing it by the number of pulses per revolution.

◆ CURR_MASK

#define CURR_MASK   0x2

Mask for the current state in determining direction.

◆ INVALID

#define INVALID   0x3

XORing both states where both bits have changed.