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:
Sun Mar 17 22:15:41 2013 +0000
Revision:
1:3904ef8c606e
Parent:
0:a3a07eb0c1dd
Child:
2:1ae8bb468515
working with debug hacks;

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 1:3904ef8c606e 4 #include "FtControlSetMessage.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 1:3904ef8c606e 16 /// Each message delivers the complete remote control status encoded into 30 bits.
humlet 1:3904ef8c606e 17 /// The structure of the message is can be seen in FtControlSetMessage.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 1:3904ef8c606e 20 ///
humlet 1:3904ef8c606e 21 /// I assume that the ft control set works fine with standard 38kHz IR detectors. I have used a CHQ0038 from a broken DVD Player.
humlet 1:3904ef8c606e 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 1:3904ef8c606e 26
humlet 0:a3a07eb0c1dd 27 uint32_t m_rxBuffer;
humlet 0:a3a07eb0c1dd 28 uint32_t m_nPulses;
humlet 0:a3a07eb0c1dd 29 uint32_t m_timeOfLastEdge;
humlet 1:3904ef8c606e 30 uint8_t m_nOnes;
humlet 1:3904ef8c606e 31 uint32_t m_errorCount;
humlet 1:3904ef8c606e 32
humlet 1:3904ef8c606e 33 FtControlSetMessage m_lastMessage;
humlet 1:3904ef8c606e 34
humlet 1:3904ef8c606e 35 FunctionPointer m_callBack;
humlet 1:3904ef8c606e 36
humlet 1:3904ef8c606e 37 Timeout m_messageTimeout;
humlet 1:3904ef8c606e 38 Timeout m_receiveTimeout;
humlet 0:a3a07eb0c1dd 39
humlet 1:3904ef8c606e 40 static const uint32_t c_pulseLengthLimits[5];
humlet 1:3904ef8c606e 41 static const uint32_t c_pulseLengthDelta = 99;//101;
humlet 1:3904ef8c606e 42 static const uint32_t c_pulseLengthOffset = 797;//793;
humlet 1:3904ef8c606e 43 static const uint32_t c_maxPulseTime = c_pulseLengthOffset+7*c_pulseLengthDelta/2;
humlet 1:3904ef8c606e 44 static const uint32_t c_messageTimeout[2];
humlet 1:3904ef8c606e 45
humlet 0:a3a07eb0c1dd 46 void pulseISR();
humlet 1:3904ef8c606e 47 void messageTimeoutISR();
humlet 1:3904ef8c606e 48 void recoverISR();
humlet 1:3904ef8c606e 49
humlet 1:3904ef8c606e 50 void messageReceived();
humlet 1:3904ef8c606e 51 void handleReceiveError();
humlet 0:a3a07eb0c1dd 52
humlet 1:3904ef8c606e 53 void DBGrising();
humlet 1:3904ef8c606e 54
humlet 0:a3a07eb0c1dd 55 public:
humlet 1:3904ef8c606e 56
humlet 0:a3a07eb0c1dd 57 uint32_t dbg1;
humlet 0:a3a07eb0c1dd 58 uint32_t dbg2;
humlet 0:a3a07eb0c1dd 59 uint32_t dbg3;
humlet 0:a3a07eb0c1dd 60 uint32_t dbg4;
humlet 1:3904ef8c606e 61 uint16_t DBGhist[800];
humlet 1:3904ef8c606e 62 uint16_t DBGhist2[800];
humlet 1:3904ef8c606e 63 uint32_t DBGtime;
humlet 1:3904ef8c606e 64
humlet 0:a3a07eb0c1dd 65 /// Create a receiver
humlet 1:3904ef8c606e 66 /// @parameter in: The pin the IR detector's message line is connected to
humlet 1:3904ef8c606e 67 FtControlSetReceiver(PinName in);
humlet 0:a3a07eb0c1dd 68
humlet 1:3904ef8c606e 69 /// get the last received message
humlet 1:3904ef8c606e 70 FtControlSetMessage getLastMessage()const {
humlet 1:3904ef8c606e 71 return m_lastMessage;
humlet 1:3904ef8c606e 72 };
humlet 1:3904ef8c606e 73
humlet 1:3904ef8c606e 74 /// get number of receive errors
humlet 1:3904ef8c606e 75 uint32_t getErrorCount()const {
humlet 1:3904ef8c606e 76 return m_errorCount;
humlet 1:3904ef8c606e 77 }
humlet 1:3904ef8c606e 78
humlet 1:3904ef8c606e 79 /// hook a call back into the receiver ISR e.g. for sending a RTOS message.
humlet 0:a3a07eb0c1dd 80 /// called on each update or receive error
humlet 0:a3a07eb0c1dd 81 void setCallBack(const FunctionPointer& callBack) {
humlet 0:a3a07eb0c1dd 82 m_callBack=callBack;
humlet 0:a3a07eb0c1dd 83 };
humlet 0:a3a07eb0c1dd 84 };
humlet 0:a3a07eb0c1dd 85
humlet 0:a3a07eb0c1dd 86
humlet 0:a3a07eb0c1dd 87 #endif
humlet 0:a3a07eb0c1dd 88
humlet 0:a3a07eb0c1dd 89
humlet 0:a3a07eb0c1dd 90
humlet 0:a3a07eb0c1dd 91
humlet 0:a3a07eb0c1dd 92
humlet 0:a3a07eb0c1dd 93
humlet 0:a3a07eb0c1dd 94