JMotor
Loading...
Searching...
No Matches
Public Member Functions | List of all members
JEncoderQuadraturePinChange Class Reference

uses a pin change interrupt library to support more pins than attachInterrupt(). More...

#include <JEncoderQuadraturePinChange.h>

Inheritance diagram for JEncoderQuadraturePinChange:
Inheritance graph
[legend]
Collaboration diagram for JEncoderQuadraturePinChange:
Collaboration graph
[legend]

Public Member Functions

 JEncoderQuadraturePinChange (byte _encoderAPin, byte _encoderBPin, float _distPerCountFactor=1.0, bool _reverse=false, unsigned long _slowestIntervalMicros=100000UL)
 constructor, sets pins and settings
 
void setUpInterrupts (void(*_isrAPointer)(void), void(*_isrBPointer)(void))
 set up pins and interrupts
 
void turnOffInterrupts ()
 disable interrupts and stop monitoring encoder
 
- Public Member Functions inherited from JEncoderQuadrature
long zeroCounter ()
 reset the counter of how far the encoder has turned
 
float getVel ()
 calculates velocity in distance per second where distance was set by setdistPerCountFactor()
 
long getCounter ()
 returns how far the encoder has turned from the zero position
 
float getPos ()
 returns how far the encoder has turned from the zero position converted to distance
 
float getDistPerCountFactor ()
 returns a conversion factor between encoder ticks and distance that can be set for the encoder
 
void setDistPerCountFactor (float _factor)
 set the conversion factor between encoder ticks and distance
 
void setReverse (bool _reverse)
 reverse readings of encoder
 
bool hasDirection ()
 can this encoder measure direction or just speed
 
bool isVelNew ()
 could be useful for only recalculating a control loop if there's new velocity data
 
void run ()
 if an encoder needs to have some code called each loop (like absolute encoder polling encoder and calculating amount turned)
 
void ISRA (void)
 
void ISRB (void)
 
- Public Member Functions inherited from JEncoder
virtual void setRev (bool _rev)
 empty function for directionless encoders to override
 

Additional Inherited Members

- Protected Member Functions inherited from JEncoderQuadrature
 JEncoderQuadrature (byte _encoderAPin, byte _encoderBPin, float _distPerCountFactor=1.0, bool _reverse=false, unsigned long _slowestIntervalMicros=100000UL)
 constructor, sets pins and settings
 
- Protected Attributes inherited from JEncoderQuadrature
byte encoderAPin
 
byte encoderBPin
 

Detailed Description

uses a pin change interrupt library to support more pins than attachInterrupt().

Interrupt library (tested with v1.1.0): https://github.com/GreyGnome/EnableInterrupt
platform: AVR (standard Arduinos)

Note
make sure to call setUpInterrupts() when your code starts

Constructor & Destructor Documentation

◆ JEncoderQuadraturePinChange()

JEncoderQuadraturePinChange::JEncoderQuadraturePinChange ( byte  _encoderAPin,
byte  _encoderBPin,
float  _distPerCountFactor = 1.0,
bool  _reverse = false,
unsigned long  _slowestIntervalMicros = 100000UL 
)
inline

constructor, sets pins and settings

Parameters
_encoderAPinone channel of quadrature encoder
_encoderBPinother channel of quadrature encoder
_distPerCountFactorconversion factor for getting distance in an actual unit
_reversefalse(default)
_slowestIntervalMicrosafter this many microseconds without an encoder tick velocity is set to zero.

Member Function Documentation

◆ setUpInterrupts()

void JEncoderQuadraturePinChange::setUpInterrupts ( void(*)(void)  _isrAPointer,
void(*)(void)  _isrBPointer 
)
inlinevirtual

set up pins and interrupts

Parameters
_isrAPointerglobal function that calls internal ISRA, to use with enableInterrupt
_isrBPointerglobal function that calls internal ISRB, to use with enableInterrupt

Reimplemented from JEncoderQuadrature.

◆ turnOffInterrupts()

void JEncoderQuadraturePinChange::turnOffInterrupts ( )
inlinevirtual

disable interrupts and stop monitoring encoder

Note
use setUpInterrupts to start encoder again

Reimplemented from JEncoderQuadrature.


The documentation for this class was generated from the following file: