Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
Sensors/IncrementalEncoder/IncrementalEncoder.h
- Committer:
- shimniok
- Date:
- 2018-11-30
- Revision:
- 25:bb5356402687
- Parent:
- 0:a6a169de725f
File content as of revision 25:bb5356402687:
#ifndef __INCREMENTALENCODER_H
#define __INCREMENTALENCODER_H
#include "mbed.h"
/** An interface for a simple, 1-track, incremental encoder. If using a simple reflectance sensor, then a voltage comparator
* circuit will be required to generate the pulsetrain. See: http://www.bot-thoughts.com/2011/03/avc-bot-wheel-encoders.html
*
*/
class IncrementalEncoder
{
public:
/** Create an incremental encoder interface. Increments counter at every rise and fall signal
*
* @param pin -- the pin to which a digital pulsetrain is sent
*/
IncrementalEncoder(PinName pin);
/** Get ticks since last call
*
* @returns the number of ticks since the last call to this method
*/
unsigned int read();
/** Get total tick count since last reset
*
* @returns total ticks since the last reset or instantiation
*/
unsigned int readTotal();
/** Get total rise tick count
*
* @returns total rise ticks
*/
unsigned int readRise();
/** Get total fall tick count
*
* @returns total fall ticks
*/
unsigned int readFall();
/** Read time interval between ticks
*
* @returns filtered time between encoder pulses
*/
unsigned int readTime();
/** Reset the tick counter
*
*/
void reset();
private:
Timer _t;
unsigned int _lastTime;
unsigned int _time;
unsigned int _lastTicks;
unsigned int _ticks, _rise, _fall;
bool _new;
InterruptIn _interrupt;
void _increment();
void _incRise();
void _incFall();
};
#endif