Analysis of infrared remote control and decoding remote control program based on STM32

Publisher:sjp5035022Latest update time:2016-09-02 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The text mainly contains two contents: 1. Explanation of infrared remote control protocol; 2. Analysis of decoding program (refer to the code of punctual atom)

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:

11

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:

12

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();

13

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();

14

15

 

16

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.

17

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.

Keywords:STM32 Reference address:Analysis of infrared remote control and decoding remote control program based on STM32

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

STM32 keil5 compilation optimization
I was originally writing an IAP program, and only 4K bytes were planned in the Flash, but after the code was written, there were 6K, so I looked for an optimization solution, and after optimization, it was around 1.7K. STM32 keil5 compilation optimization, you can check the following items: 1、Options for Taeget-- Targ
[Microcontroller]
STM32--Application of basic timer
Experimental purpose: Use the basic timer TIM6 to control the on and off of the LED. void GPIO_Config(void) {     GPIO_InitTypeDef GPIO_InitStructure;     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;     GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;     GPIO_Init
[Microcontroller]
What do the several interrupt flags defined in the STM32 serial port firmware library mean?
#define USART_IT_PE                       ((uint16_t)0x0028) #define USART_IT_TXE                      ((uint16_t)0x0727) #define USART_IT_TC                       ((uint16_t)0x0626) #define USART_IT_RXNE                     ((uint16_t)0x0525) #define USART_IT_IDLE                     ((uint16_t)0x0424) #define USART_
[Microcontroller]
Parsing and generating timestamps for STM32
What is a timestamp? Timestamp refers to the total number of seconds from 00:00:00 Greenwich time on January 1, 1970 (08:00:00 Beijing time on January 1, 1970) to the present. In layman's terms, a timestamp is a complete and verifiable piece of data that can indicate that a piece of data existed at a specific point in
[Microcontroller]
Stm32 key input control LED light
Note: GPIOA, GPIO_Pin_0 corresponds to key1; GPIOA, GPIO_Pin_1 corresponds to key2; GPIOA, GPIO_Pin_2 corresponds to LED1; GPIOA, GPIO_Pin_3 corresponds to LED2 #include "stm32f10x.h"   #include "stm32f10x_rcc.h"   #include "stm32f10x_gpio.h"   #include "system_stm32f10x.h"      /* Control the small light: 0 of
[Microcontroller]
STM32 Learning: Timer Interrupt
Timer Interrupt   The timer function of STM32 is very powerful. There are advanced timers such as TIME1 and TIME8, general timers such as TIME2~TIME5, and basic timers such as TIME6 and TIME7. In this chapter, we will use the timer interrupt of TIM3 to control the flip of DS1, and use the flip of DS0 in the main func
[Microcontroller]
How to write interrupt program in STM32+IAR+uC/OS environment
First, let's talk about a few key functions: bsp_int.c provides several key interrupt operation functions: void    BSP_IntDis                (CPU_DATA    int_id)                  //Disable the specified interrupt void    BSP_IntDisAll        (void)                                                             
[Microcontroller]
Design of remote temperature control system using STM32
Temperature control is one of the main objects of industrial control. The commonly used mathematical model for temperature control is first-order inertia plus a pure lag link, but it varies greatly with different heating objects and environmental conditions. Because the temperature control object has a relativ
[Microcontroller]
Design of remote temperature control system using STM32
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号