I am currently involved with a small project which should detect (but not necessarily decode) different, not known IR signals.
Therefore I wrote a small sketch to print out the received data in form of a list of pulses including their time period.
My sketch uses timer 2 for measuring timer counts between two consecutive interrupts generated by the input GPIO signal.
The timer runs with a 1us clock (after the prescaler), so that the counts directly reflect the time in microseconds.
The data processing takes place only after a complete pulse train has been received, detected by a timeout of 15ms (adjustable, set a bit larger than the longest possible period) after the last detected signal transition. In this way the processor is not loaded with any unnecessary tasks in the ISRs.
It uses dual buffer to store the received timer counts in an alternate way, so theoretically one could easily change the sketch to detect repeated commands (signals with same timeline geometry and similar timings).
A typical output looks like this:
Code: Select all
Total pulses: 15 0 1 0 2 2 2 0 0 2 2 0 0 0 0 2 0=510 1=2580 2=1023
The detected levels are not recorded, but they are obviously alternating from high to low and from low to high in a sequential order.
The values shown in the last row are averaged values (if more than one similar value available).
The error margin to identify a pulse which period has been already received is set to +-15%, can be changed if needed.