EEEN21000
GROUP 30 Line Following Buggy
|
Handle reading pulses from encoder. More...
#include <QEI.h>
Public Types | |
enum | Encoding { X2_ENCODING , X4_ENCODING } |
typedef enum QEI::Encoding | Encoding |
Public Member Functions | |
QEI (PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding=X2_ENCODING) | |
Constructor. More... | |
void | reset (void) |
Reset the encoder. More... | |
int | getCurrentState (void) |
Read the state of the encoder. More... | |
int | getInvalidCount (void) |
Read the number of invalid counts. More... | |
int | getPulses (void) |
Read the number of pulses recorded by the encoder. More... | |
int | getRevolutions (void) |
Read the number of revolutions recorded by the encoder on the index channel. More... | |
void | setPulses (int newCount) |
Set the current pulse count in case you want to init it. More... | |
void | setRevolutions (int newRevs) |
Set the current revolution count in case you want to init it. More... | |
Private Member Functions | |
void | encode (void) |
Update the pulse count. More... | |
void | index (void) |
Called on every rising edge of channel index to update revolution count by one. More... | |
Private Attributes | |
Encoding | encoding_ |
InterruptIn | channelA_ |
InterruptIn | channelB_ |
InterruptIn | index_ |
int | pulsesPerRev_ |
int | prevState_ |
int | currState_ |
volatile int | invalid_ |
volatile int | pulses_ |
volatile int | revolutions_ |
Handle reading pulses from encoder.
typedef enum QEI::Encoding QEI::Encoding |
enum QEI::Encoding |
QEI::QEI | ( | PinName | channelA, |
PinName | channelB, | ||
PinName | index, | ||
int | pulsesPerRev, | ||
Encoding | encoding = X2_ENCODING |
||
) |
Constructor.
Reads the current values on channel A and channel B to determine the initial state.
Attaches the encode function to the rise/fall interrupt edges of channels A and B to perform X4 encoding.
Attaches the index function to the rise interrupt edge of channel index (if it is used) to count revolutions.
channelA | mbed pin for channel A input. |
channelB | mbed pin for channel B input. |
index | mbed pin for optional index channel input, (pass NC if not needed). |
pulsesPerRev | Number of pulses in one revolution. |
encoding | The encoding to use. Uses X2 encoding by default. X2 encoding uses interrupts on the rising and falling edges of only channel A where as X4 uses them on both channels. |
void QEI::reset | ( | void | ) |
Reset the encoder.
Sets the pulses and revolutions count to zero.
int QEI::getCurrentState | ( | void | ) |
Read the state of the encoder.
int QEI::getInvalidCount | ( | void | ) |
Read the number of invalid counts.
int QEI::getPulses | ( | void | ) |
Read the number of pulses recorded by the encoder.
int QEI::getRevolutions | ( | void | ) |
Read the number of revolutions recorded by the encoder on the index channel.
void QEI::setPulses | ( | int | newCount | ) |
Set the current pulse count in case you want to init it.
[in] | newCount | is the count to set it to. |
void QEI::setRevolutions | ( | int | newRevs | ) |
Set the current revolution count in case you want to init it.
[in] | newRevs | is the count to set it to. |
|
private |
Update the pulse count.
Called on every rising/falling edge of channels A/B.
Reads the state of the channels and determines whether a pulse forward or backward has occured, updating the count appropriately.
|
private |
Called on every rising edge of channel index to update revolution count by one.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |