I won’t tell you about the introduction, advantages and disadvantages of infrared, as they are all available online and in books. Let’s get to the point.
1. Explanation of infrared remote control protocol
The most commonly used infrared remote control codes are: PWM (Pulse Width Modulation) of NEC Protocol and PPM (Pulse Position Modulation) of Philips RC-5 Protocol.
This article will implement infrared remote control using the NEC protocol.
Features of NEC protocol:
1. 8-bit address and 8-bit instruction length;
2. Address and command are transmitted twice (to ensure reliability);
3. PWM pulse width modulation, using the duty cycle of the transmitted infrared carrier to represent "0" and "1";
4. The carrier frequency is 38KHz;
5. The bit time is 1.125ms and 2.25ms;
The definition of NEC code: one pulse corresponds to a continuous carrier of 560us, a logic 1 transmission takes 2.25ms (560us pulse + 1680us low level), and a logic 0 transmission takes 1.125ms (560us pulse + 560us low level). The remote control receiver is at a low level when it receives a pulse, and at a high level when it does not receive a pulse. Therefore, the signal we receive at the receiving head is: logic 1 should be 560us low + 1680us high, and logic 0 should be 560us low + 560us high. As shown below:
The data format of NEC remote control command is: synchronization terminal (guide code) + address code + address inverse code + control code + control inverse code. The synchronization code is composed of a 9ms low level and a 4.5ms high level. The address code, address inverse code, control code, and control inverse code are all 8-bit data formats. They are sent in the order of high bit first and low bit last. The inverse code is used to increase the reliability of transmission (can be used for verification). The figure below is the waveform measured from the infrared receiving head end when we press button 2:
As can be seen in the figure, after 100ms, we still received several pulses. This is the continuous code specified by the NEC code (consisting of 9ms low level + 2.5ms high level + 0.56ms low level and 97.94ms high level). If the key is still not released after a frame of data is sent, a repeated code (continuous code) will be sent. The length/number of times the key is pressed can be marked by counting the number of continuous codes.
2. Decoding program analysis (refer to the code of the punctual atom)
In the code of the punctual atom, the input capture function of the timer is used to realize remote control decoding. The following is an analysis of the key code:
In the remote.h file of this experiment, three functions are defined: Remote_Init();, TIM4_IRQHandler();, and Remote_Scan();.
1. Remote_Init();
Here we need to pay attention to the interrupt priority. The priority of the two interrupts of timer 4, overflow (update) interrupt and capture event interrupt, is the same. That is, neither of them can interrupt the other. For example, when A is executing, B will not generate an interrupt. This is very important, very important, very important!
2. TIM4_IRQHandler();
Note the status mark in the red box in the figure above. Let's analyze this interrupt service function (there are two interrupts in this terminal service function, overflow interrupt and capture interrupt):
1. First look at the capture interrupt. Rmtsta is 0 at the beginning. When a rising edge capture occurs (the pin corresponding to RDATA gets a high level), the capture event is first configured as a falling edge capture, and then Rmtsta=0x10, marking that the rising edge has been captured;
2. When a falling edge arrives, assign the value of the CCR1 register to the Dval variable, and then configure the capture event as a rising edge capture; Supplement: The rising edge capture and the falling edge capture are used alternately like this in order to capture the duration of the high level.
3. Note: Decoding is performed only after the receiving head receives the boot code. Therefore, first determine whether the value of Dval is between 4200us and 4700us. If so, set Rmtsta|=1<<7 and set the highest position of Rmtsta to 1, marking the successful reception of the boot code.
4. When the highest bit of Rmtsta is set to 1, that is, if(Rmtsta&0x80) is satisfied, it can be determined that the value of Dval is within the following 3-minute range: 300~800 (560us), 1400~1800 (1680us), 2200~2600 (2500us). Thus, 0 or 1 or RmtCnt++ is obtained. Decoding is realized.
4. In the above three items, the duration of high level is within 10ms, which means that the capture interrupt (rising edge and falling edge) is generated before 10ms. Because of the same priority, overflow interrupt cannot be generated at this time. Only when you reach 10ms and no rising edge capture or falling edge capture is generated, an overflow interrupt will be generated.
5. Under what circumstances is there no capture in 10ms? It is the burst code mentioned above. The high level of 97.94ms is much greater than 10ms, so an overflow interrupt will be generated. In the overflow interrupt, it will be marked that a complete key value information collection has been completed (RmtSta|=1<<6). The burst code time set by the punctual atom in the overflow interrupt is 130ms. If it exceeds 130ms, it is considered that the key is released (because there will be no pulse when the key is released, that is, high level, see above).
In addition, the program for processing infrared keyboard is very simple. First, determine whether all the information of a key is obtained (according to the previous item, determine whether if(RmtSta&(1<<6)) is true), then read the data stored in the capture interrupt before by shifting, and then compare the original code and the inverse code. I won't say more here.
Note: The codes sent by the remote control are all encoded. If you want to crack the remote control code, you can use an oscilloscope to measure the code at the receiving end.
The whole program idea is not difficult, which is to decode the code sent by the remote control. The main thing here is to understand the two interrupts.
Previous article:CoAP Server solution based on STM32 platform
Next article:Using STM32 to complete the design of intelligent motor protector
Recommended ReadingLatest update time:2024-11-22 12:22
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Vicor high-performance power modules enable the development of low-altitude avionics and EVTOL
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- Chuangshi Technology's first appearance at electronica 2024: accelerating the overseas expansion of domestic distributors
- "Cross-chip" quantum entanglement helps build more powerful quantum computing capabilities
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Ultrasound patch can continuously and noninvasively monitor blood pressure
- Europe's three largest chip giants re-examine their supply chains
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- "Practice together in 2021" + continue to persevere
- [TI recommended course] #[High Precision Laboratory] Magnetic Sensor Technology#
- Prawn Idioms
- What are the consequences of a battery short circuit?
- CNC Technology in Information Manufacturing
- In the information age, how to protect information security?
- Latest release: How to use PCB to SCH
- [GD32L233C-START Review] RTX operating system
- Bluetooth controlled stepper motor driver and firmware - Seeking paid technical assistance
- Commonly used resistor nominal values