My friend and I want to design a universal learning remote controller, like this one, for learning purposes. What we want to do basically is store and replay infrared pulses.
We want to detect 36kHz, 38kHz and 40kHz signals. A 40kHz signal will have a period of 25\$\mu\$s.
We want to use an 8-bit PIC microcontroller, for now we have selected PIC16F616, that will run at 20MHz high speed crystal oscillator. We have two options available:
- Use the
Interrupt On Change
module. - Use the capture mode of the CCP module.
First option will be as follows:
Assume a register is set as: unsigned char _10_us = 0;
. This register will hold the time. TMR2 module with period register is set to create an interrupt every 10\$\mu\$sec. When an interrupt occurs, it will increment the _10_us
register and exit. This will give a maximum time of 2.55msec. If more time measurement is needed, additional registers such as _1_ms
can be defined and incremented as needed.
Now, every time an interrupt is generated by any kind of change ( high-to-low or low-to-high), the program will note the current time, that is the value of _10_us
register. After a while, when the next interrupt is generated, the program will subtract the saved value from the _10_us
register, and thus will now the time that is taken in the meantime, with a unit of 10 \$\mu\$seconds.
This option make me scratch my head; TMR2 interrupt will occur about every 50 instructions. Interrupt handling will take about 20 instructions. I am left with 30 instructions to calculate and save the period to an array. Will this method work?
Second option will be as follows:
Set up the capture mode of the CCP module so that it will generate an interrupt when an event(high-to-low) occurs on CCP1 pin. In the interrupt routine, it will set a flag so that a task in the program can calculate(if needed) and save the value of CCPR1H (probably will not be needed) and CCPR1L. Then we will change the configuration of the capture mode so that it will trigger the interrupt when a low-to-high edge occurs. And then it will wait for the next event. I cannot estimate the performance of this method since I've never used it.
Another option?
We can use an infrared demodulator IC such as TSOP17xx series. That would solve our problem completely. However some questions come to mind.
Our reading distance requirement is not much; 1 metre (~3 feet). If we select a TSOP1738 that is meant to be working in 38kHz, how well will this work with 36kHz and 40kHz signals?
Page 4 of the datasheet of TSOP17xx series shows "Frequency Dependence of Responsivity" graph. As far as we understood;
- 40kHz, which is ~1.053 of 38kHz, will give a relative responsitivity of ~0.6.
- 36kHz, which is ~0.95 of 38kHz, will give a relative responsitivity of ~0.65.
What do these values mean? Can we use a TSOP1738 and be fine?