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.
Revision 2:1bf9f7b6bf29, committed 2013-03-25
- Comitter:
- humlet
- Date:
- Mon Mar 25 21:08:56 2013 +0000
- Parent:
- 1:9e595056c3da
- Child:
- 3:3944952c9eab
- Commit message:
- introduction of NeedfulThings lib
Changed in this revision
FtEncoder.cpp | Show annotated file Show diff for this revision Revisions of this file |
FtEncoder.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/FtEncoder.cpp Wed Mar 20 21:42:39 2013 +0000 +++ b/FtEncoder.cpp Mon Mar 25 21:08:56 2013 +0000 @@ -43,8 +43,8 @@ m_cursor &= c_nTmStmps-1; m_timeStamps[m_cursor] = getCurrentTimeStamp(); // restart the timeout - m_tmOut.detach(); - m_tmOut.attach_us(this, &FtEncoder::timeoutISR, m_standStillTimeout); + m_tmOut.remove(); + m_tmOut.insert(m_timeStamps[m_cursor]+m_standStillTimeout); ++m_cnt; m_callBack.call(); }
--- a/FtEncoder.h Wed Mar 20 21:42:39 2013 +0000 +++ b/FtEncoder.h Mon Mar 25 21:08:56 2013 +0000 @@ -4,7 +4,7 @@ #include "InterruptIn.h" #include "us_ticker_api.h" #include "FunctionPointer.h" -#include "Timeout.h" +#include "TimeoutTweaked.h" using namespace mbed; @@ -21,12 +21,12 @@ static const int c_nTmStmps = 1<<2; /// size of ringbuffer: Has to be 2^x InterruptIn m_encIRQ; - Timeout m_tmOut; + TimeoutTweaked m_tmOut; 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 + volatile uint32_t m_timeStamps[c_nTmStmps]; /// ringbuffer of edge timestamps FunctionPointer m_callBack;