Interface for the encoder of the red fischertechnik motors
Simple Interface for the simple encoder of the red fischertechnik motors.
The interface counts both, rising and falling edges, resulting in 150 counts per revolution. The interface also provides a speed measurement updated with each edge.
Connect the green wire to GND, the red one to +3.3V and the black signal line to any of mbed numbered pins. Additionally connect the signal line via a pullup resitor to +3.3V. A 10K resistor works fine.
Diff: FtEncoder.h
- Revision:
- 1:9e595056c3da
- Parent:
- 0:8cb1142a88d5
- Child:
- 2:1bf9f7b6bf29
--- a/FtEncoder.h Thu Mar 14 18:27:24 2013 +0000 +++ b/FtEncoder.h Wed Mar 20 21:42:39 2013 +0000 @@ -8,34 +8,37 @@ using namespace mbed; -/// Simple Interface for the encoder of the red fischertechnik motors +/// Simple Interface for the simple encoder of the red fischertechnik motors. +/// The interface counts both, rising and falling edges, resulting in 150 counts per revolution. +/// The interface also provides a speed measurement updated with each edge. /// @note Connect the green wire to GND, the red one to +3.3V and the /// black signal line to any of mbed numbered pins. Additionally connect the signal line /// via a pullup resitor to +3.3V. A 10K resistor works fine. /// class FtEncoder { - static const float c_speedFactor = 1e6/75.0; // 1/(µs * 150/2) edges per revolution) - static const int c_nTmStmps = 1<<2; + static const float c_speedFactor = 1e6/75.0; /// 1/(µs * 150/2) edges per revolution) + static const int c_nTmStmps = 1<<2; /// size of ringbuffer: Has to be 2^x InterruptIn m_encIRQ; Timeout m_tmOut; - volatile unsigned int m_cnt; - unsigned int m_standStillTimeout; - volatile unsigned int m_cursor; - unsigned int m_timeStamps[c_nTmStmps]; - bool m_ready; + volatile unsigned int m_cnt; /// edge counter + unsigned int m_standStillTimeout; + volatile unsigned int m_cursor; /// ringbuffer cursor + uint32_t m_timeStamps[c_nTmStmps]; /// ringbuffer of edge timestamps FunctionPointer m_callBack; /// ISR called on rising and falling encoder edges void encoderISR(); + /// ISR called on edge timeout i.e. standstill + void timeoutISR(); public: /// create a simple interface to the encoder connected to the given pin - /// @param name of the pin the black encoder signl wire is connected to + /// @param name of the pin the black encoder signal wire is connected to /// @param standStillTimeout After this time [µs] without any encoder edge getSpeed() returns zero FtEncoder(PinName pwm, unsigned int standStillTimeout=50000);