TSOP IR Detector
From Embedded Systems Learning Academy
The first step of decoding is already done by the TSOP which converts IR signals to digital signals. The next step is for you to convert it signal to meaningful signal codes.
References
LPC2148 Hints
You can either setup an interrupt on falling edge and capture the times or you can also setup auto-capture using CAPTURE input of your controller.
Setup
- Hook up TSOP signal to an External Interrupt Pin (EINT). Configure for falling edge for Active-Low signal.
- Create a Helper task, such as "DecoderTask"
- Create a FreeRTOS Queue to send time-stamps from ISR to DecoderTask
- Queue item size is sizeof(int) and depth as 20+ should work
- Have the ISR Task time-stamp the falling edges, and let the decoder task decode the signals
- Note: You do not want to spend the entire signal length (many tens of milliseconds) in ISR
- Start Timer1 (FreeRTOS project already does this) @ resolution of 1 tick per microsecond.
ISR Task
Psuedocode:
// Enter ISR unsigned int timer1Value = T1TC; // Timer 1 Counter Value xQueueSendFromIsr(&timer1Value, &taskWoken); // Exit ISR
Decoder Task
Psuedocode:
while(1)
{
unsigned int startTime = 0;
// Wait forever for the 1st signal time
if(xQueueReceive(qId, &startTime, portMAX_DELAY))
{
// Got 1st signal, so get all signals within 10ms timeout
unsigned int signalTimes[128];
int sigNum = 0;
while(sigNum < 128 && xQueueReceive(qId, &signalTimes[sigNum], 10))
{
signalTimes[sigNum] -= startTime;
sigNum++;
}
// Calculate differences of falling edges
for(int i = 0; i < sigNum-1; i++) {
signalTimes[i] = signalTimes[i+1] - signalTimes[i];
}
for(int i = 0; i < sigNum; i++) {
rprintf("Timestamp #u : %X\n", (i+1), signalTimes[i]);
}
// Now your array may look like: 10,10,20,10,10,20 etc,
// so turn these numbers to binary bits of an integer and you're done!
}
}