Receiver interface for the fischertechnik IR control set

Dependencies:   NeedfulThings

Receiver interface for the fischertechnik IR control set.

An mbed port of the code found on this ft community WIKI page The ft IR remote control uses some kind of RC-MM Protocol . When any of the controls is applied the remote control sends updates at a rate of at 1/120ms or 1/90ms depending on the senders frequency setting. Each message delivers the complete remote control status encoded into 30 bits. The structure of the message can be seen in FtControlSetMessage.h.

I assume that the ft control set works fine with standard 38kHz IR detectors. I have used a CHQ0038 from a broken DVD Player. It can be connected directly to the mbed: GND, VCC->3.3V and the signal line to any of the numbered mbed gpios.

The PDM timing of the ft IR control set isn't that exact. Thus receive errors occur quite frequently. I am observing an error rate somewhere between 3% and 5%. This driver "ignores" up to 3 consecutive receive errors, i.e. it just indicates an error but still provides the last correctly received message, before it resets the message to zero after the fourth error.

Committer:
humlet
Date:
Sat Mar 16 23:48:57 2013 +0000
Revision:
0:a3a07eb0c1dd
Child:
1:3904ef8c606e
control set smoke test, get it running

Who changed what in which revision?

UserRevisionLine numberNew contents of line
humlet 0:a3a07eb0c1dd 1 #ifndef FTCONTROLSETRECEIVER_H
humlet 0:a3a07eb0c1dd 2 #define FTCONTROLSETRECEIVER_H
humlet 0:a3a07eb0c1dd 3
humlet 0:a3a07eb0c1dd 4 #include "FtControlSetSignal.h"
humlet 0:a3a07eb0c1dd 5 #include "InterruptIn.h"
humlet 0:a3a07eb0c1dd 6 #include "FunctionPointer.h"
humlet 0:a3a07eb0c1dd 7 #include "Timeout.h"
humlet 0:a3a07eb0c1dd 8
humlet 0:a3a07eb0c1dd 9 using namespace mbed;
humlet 0:a3a07eb0c1dd 10
humlet 0:a3a07eb0c1dd 11 /// Receiver interface for the fischertechnik IR control set
humlet 0:a3a07eb0c1dd 12 ///
humlet 0:a3a07eb0c1dd 13 /// An mbed port of the code found on this <A HREF="http://www.ftcommunity.de/wiki.php?action=show&topic_id=36">ft community WIKI page</a>
humlet 0:a3a07eb0c1dd 14 /// The ft IR remote control uses some kind of <A HREF="http://www.sbprojects.com/knowledge/ir/rcmm.php"> RC-MM Protocol </A>.
humlet 0:a3a07eb0c1dd 15 /// When any of the controls is applied the remote control sends updates at a rate of 1/90ms~12Hz.
humlet 0:a3a07eb0c1dd 16 /// Each signal delivers the complete remote control status encoded into 30 bits.
humlet 0:a3a07eb0c1dd 17 /// The structure of the signal is can be seen in FtControlSetSignal.h.
humlet 0:a3a07eb0c1dd 18 /// The protocol uses Pulse Distance Modulation (PDM) with two bits (dibit) per pulse, hence four different
humlet 0:a3a07eb0c1dd 19 /// distances. A transmission consists of 16 pulses (15 distances) for a total of 30 bits.
humlet 0:a3a07eb0c1dd 20 ///
humlet 0:a3a07eb0c1dd 21 /// The control set works fine with standard 38kHz IR detectors. I have used a CHQ0038 from broken DVD Player.
humlet 0:a3a07eb0c1dd 22 /// It can be onnected directly to the mebed: GND, VCC->3.3V and the signal line to any of the numbered mbed gpios.
humlet 0:a3a07eb0c1dd 23 class FtControlSetReceiver
humlet 0:a3a07eb0c1dd 24 {
humlet 0:a3a07eb0c1dd 25 InterruptIn m_pulseIRQ;
humlet 0:a3a07eb0c1dd 26 Timeout m_timeOutTimer;
humlet 0:a3a07eb0c1dd 27
humlet 0:a3a07eb0c1dd 28 uint32_t m_timeOut;
humlet 0:a3a07eb0c1dd 29 uint32_t m_rxBuffer;
humlet 0:a3a07eb0c1dd 30 FtControlSetSignal m_lastSignal;
humlet 0:a3a07eb0c1dd 31 uint32_t m_nPulses;
humlet 0:a3a07eb0c1dd 32 uint32_t m_timeOfLastEdge;
humlet 0:a3a07eb0c1dd 33 uint8_t m_nOnes;
humlet 0:a3a07eb0c1dd 34
humlet 0:a3a07eb0c1dd 35 FunctionPointer m_callBack;
humlet 0:a3a07eb0c1dd 36
humlet 0:a3a07eb0c1dd 37 void pulseISR();
humlet 0:a3a07eb0c1dd 38 void timeOutISR();
humlet 0:a3a07eb0c1dd 39 inline void reset();
humlet 0:a3a07eb0c1dd 40
humlet 0:a3a07eb0c1dd 41 static const uint32_t c_pulseLeghthDelta = 100;
humlet 0:a3a07eb0c1dd 42 static const uint32_t c_pulseLengthOffset = 795-c_pulseLeghthDelta/2;
humlet 0:a3a07eb0c1dd 43
humlet 0:a3a07eb0c1dd 44 public:
humlet 0:a3a07eb0c1dd 45
humlet 0:a3a07eb0c1dd 46 uint32_t dbg1;
humlet 0:a3a07eb0c1dd 47 uint32_t dbg2;
humlet 0:a3a07eb0c1dd 48 uint32_t dbg3;
humlet 0:a3a07eb0c1dd 49 uint32_t dbg4;
humlet 0:a3a07eb0c1dd 50
humlet 0:a3a07eb0c1dd 51
humlet 0:a3a07eb0c1dd 52 /// Create a receiver
humlet 0:a3a07eb0c1dd 53 /// @parameter in: The pin the IR detector's signal line is connected to
humlet 0:a3a07eb0c1dd 54 /// @parameter tmOut: After this time [µs] of inactivity the data is reset. A value of zero deactivates the timeout.
humlet 0:a3a07eb0c1dd 55 FtControlSetReceiver(PinName in, uint32_t timeOut=120000);
humlet 0:a3a07eb0c1dd 56
humlet 0:a3a07eb0c1dd 57 /// get the last received signal
humlet 0:a3a07eb0c1dd 58 FtControlSetSignal getLastSignal()const{return m_lastSignal;};
humlet 0:a3a07eb0c1dd 59
humlet 0:a3a07eb0c1dd 60 /// hook a call back into the receiver ISR e.g. for sending a RTOS signal.
humlet 0:a3a07eb0c1dd 61 /// called on each update or receive error
humlet 0:a3a07eb0c1dd 62 void setCallBack(const FunctionPointer& callBack) {
humlet 0:a3a07eb0c1dd 63 m_callBack=callBack;
humlet 0:a3a07eb0c1dd 64 };
humlet 0:a3a07eb0c1dd 65 };
humlet 0:a3a07eb0c1dd 66
humlet 0:a3a07eb0c1dd 67 void FtControlSetReceiver::reset(){
humlet 0:a3a07eb0c1dd 68 m_nPulses=0;
humlet 0:a3a07eb0c1dd 69 m_rxBuffer=0;
humlet 0:a3a07eb0c1dd 70 m_nOnes=0;
humlet 0:a3a07eb0c1dd 71 }
humlet 0:a3a07eb0c1dd 72
humlet 0:a3a07eb0c1dd 73 #endif
humlet 0:a3a07eb0c1dd 74
humlet 0:a3a07eb0c1dd 75
humlet 0:a3a07eb0c1dd 76
humlet 0:a3a07eb0c1dd 77
humlet 0:a3a07eb0c1dd 78
humlet 0:a3a07eb0c1dd 79
humlet 0:a3a07eb0c1dd 80