<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://socialledge.com/sjsu/index.php?action=history&amp;feed=atom&amp;title=TSOP_IR_Detector</id>
		<title>TSOP IR Detector - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://socialledge.com/sjsu/index.php?action=history&amp;feed=atom&amp;title=TSOP_IR_Detector"/>
		<link rel="alternate" type="text/html" href="http://socialledge.com/sjsu/index.php?title=TSOP_IR_Detector&amp;action=history"/>
		<updated>2026-05-11T14:32:05Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.27.1</generator>

	<entry>
		<id>http://socialledge.com/sjsu/index.php?title=TSOP_IR_Detector&amp;diff=1148&amp;oldid=prev</id>
		<title>Preet: /* Decoder Task */</title>
		<link rel="alternate" type="text/html" href="http://socialledge.com/sjsu/index.php?title=TSOP_IR_Detector&amp;diff=1148&amp;oldid=prev"/>
				<updated>2012-05-31T01:43:54Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Decoder Task&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*  [http://www.vishay.com/docs/82013/tsop12xx.pdf TSOP1236 Datasheet]&lt;br /&gt;
*  [http://www.ladyada.net/learn/sensors/ir.html Very Useful Tututorial @ Ladyada.net]&lt;br /&gt;
&lt;br /&gt;
==LPC2148 Hints==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
* Hook up TSOP signal to an External Interrupt Pin (EINT).  Configure for falling edge for Active-Low signal.&lt;br /&gt;
* Create a Helper task, such as &amp;quot;DecoderTask&amp;quot;&lt;br /&gt;
** Create a FreeRTOS Queue to send time-stamps from ISR to DecoderTask&lt;br /&gt;
** Queue item size is sizeof(int) and depth as 20+ should work&lt;br /&gt;
* Have the ISR Task time-stamp the falling edges, and let the decoder task decode the signals&lt;br /&gt;
** Note: You do not want to spend the entire signal length (many tens of milliseconds) in ISR&lt;br /&gt;
* Start Timer1 (FreeRTOS project already does this) @ resolution of 1 tick per microsecond.&lt;br /&gt;
&lt;br /&gt;
=== ISR Task ===&lt;br /&gt;
Psuedocode:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    // Enter ISR&lt;br /&gt;
        unsigned int timer1Value = T1TC; // Timer 1 Counter Value&lt;br /&gt;
        xQueueSendFromIsr(&amp;amp;timer1Value, &amp;amp;taskWoken);&lt;br /&gt;
    // Exit ISR&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Decoder Task ===&lt;br /&gt;
Psuedocode:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
    while(1)&lt;br /&gt;
    {&lt;br /&gt;
        unsigned int startTime = 0;&lt;br /&gt;
        // Wait forever for the 1st signal time&lt;br /&gt;
        if(xQueueReceive(qId, &amp;amp;startTime, portMAX_DELAY))&lt;br /&gt;
        {&lt;br /&gt;
            // Got 1st signal, so get all signals within 10ms timeout&lt;br /&gt;
            unsigned int signalTimes[128];&lt;br /&gt;
            int sigNum = 0;&lt;br /&gt;
            while(sigNum &amp;lt; 128 &amp;amp;&amp;amp; xQueueReceive(qId, &amp;amp;signalTimes[sigNum], 10))&lt;br /&gt;
            {&lt;br /&gt;
                signalTimes[sigNum] -= startTime;&lt;br /&gt;
                sigNum++;&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            // Calculate differences of falling edges&lt;br /&gt;
            for(int i = 0; i &amp;lt; sigNum-1; i++) {&lt;br /&gt;
                signalTimes[i] = signalTimes[i+1] - signalTimes[i];&lt;br /&gt;
            }&lt;br /&gt;
            for(int i = 0; i &amp;lt; sigNum; i++) {&lt;br /&gt;
                rprintf(&amp;quot;Timestamp #u : %X\n&amp;quot;, (i+1), signalTimes[i]);&lt;br /&gt;
            }&lt;br /&gt;
            // Now your array may look like: 10,10,20,10,10,20 etc, &lt;br /&gt;
            // so turn these numbers to binary bits of an integer and you're done!&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Preet</name></author>	</entry>

	</feed>