Infrared Decoding Based on ARM7 timer capture in UC/OS-II

Source: Internet
Author: User


This afternoon, with debugging efforts, the infrared decoding was finally achieved. In fact, infrared has been used in the previous game, but 51 single-chip microcomputer was used for decoding with external interruptions and delay detection pulse width, because the 51 clock is relatively simple, decoding is easy and correct. But now I have switched to the ARM7 platform, because I am not very familiar with it, it is difficult for me to use common statements to implement precise latency. Finally, two solutions are used for infrared decoding. Solution 1 is to use the external interrupt and the timer delay detection pulse width for decoding, but the result is not as good as I thought. After debugging for half a day, it has not been correctly decoded, I personally think it is the impact of the task beat, but I do not know how to modify it. I finally gave up solution 1, switched to solution 2, and used the timer to capture and implement infrared decoding.

The lpc2103 chip is equipped with a timer for capturing and can be set to a falling edge, a rising edge, or a bilateral edge for capturing interruption. Because it is combined with this infrared encoding method, the descent edge is used for capture. Timer 0 is used as a system timer, so I chose timer 1 for capture.

The timer 1 is initialized as follows.

 
Void settimer (void) {t1ctl = 0x02; // turn off the reset timer 1t1pr = 10; // 11 frequency division, about 1 US timing once (peripheral clock 11.0592 MHz) t1cr = 0x06; // descent edge capture and interrupt t1ir = 0x10; // clear timer 1 capture 0 interrupt t1ctl = 0x01; // enable the timer 1vicvectaddr1 = (uint32) timer1_handler; // The vicvectcntl1 = (0x20 | 0x05); vicintenable | = (1 <5 );}

Then, in the interrupt service function of timer 1, the difference between two adjacent descent edges is calculated. Then, send the message to the pulse width detection task through the message mailbox for processing.

 
Void timer1_exception () {static uint32 told; // Save the capture value of the old descent edge uint32 tnew; // Save the new descent edge capture value static I; OS _enter_critical (); t1ir = 0x10; // clear timer 1 capture 0 interrupt tnew = t1cr0; tvalue = tnew-told; // get the difference between two descent edges told = tnew; // enable osmboxpost (MSG, (void *) tvalue) for processing the next interruption; // send the message to the mailbox and synchronize the behavior OS _exit_critical (); vicvectaddr = 0x00 ;}


In the pulse width detection task, I only need to compare and judge the measured pulse width with the original pulse width of the original code, and then perform operations on the relevant shift data,Obtain the data code value.

Because my remote control is a little different, the address code and the address code are not reversed, so the address judgment is not allowed, so the guide code and the address code are filtered out, and the data code is processed directly.

As long as the data code is the same as the data reverse code, the debug led flashes.

Of course, I do not know the specific code system corresponding to the remote control button, and I have not detected the connection code. I will wait for the next time to send the code system to the host computer through the serial port for display.


 
 

 

This is the core of the test pulse width task Code :

 while (1) {osmboxpend (MSG, 0, & ERR ); // wait for the pulse width detection message if (tvalue> 2145 & tvalue <2345) // perform the pulse width detection {uctemp = 1; // logic 1} else if (tvalue> 1025 & tvalue <1225) {uctemp = 0; // logic 0} else if (tvalue> 13400 & tvalue <13600) {uccounter = 0; // Boot Code usdata0 = 0; usdata1 = 0; flag = 1;} else {continue;} If (FLAG) // data processing process {Uccounter ++; If (uccounter <16) {usdata0 | = (uint16) uctemp; usdata0 <= 1;} else if (uccounter = 16) {usdata0 | = (uint16) uctemp;} else if (uccounter <32) {usdata1 | = (uint16) uctemp; usdata1 <= 1 ;} else if (uccounter = 32) {usdata1 | = (uint16) uctemp; flag = 0; ossempost (SEM); // sends semaphores to perform Code Conversion tasks, my task is simply implemented to determine whether the decoding is successful .}}} 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.