Design and implementation of infrared communication

Publisher:RadiantEnergyLatest update time:2014-03-08 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  1 Introduction

  In the field of electronic consumption, infrared products are widely used. They are mostly used for simple short-distance control, such as home appliances, toys, and various meter reading systems. This article uses Freescale's 8-bit high-performance, low-power microcontroller MC9S08GT60 as a carrier to introduce the hardware and software design process of infrared communication and the use of communication protocols.

  The HCS08 series MCU is the latest 8-bit microcontroller launched by Freescale Semiconductor. It has multiple low-power modes, higher operating frequency, integrated on-chip debugger, and rich resources. Therefore, the MC9S08GT60 of this series is used as the carrier to discuss in detail a simple and practical infrared communication development system.

  The infrared communication process mainly consists of two processes: infrared transmission and infrared reception. First, the digital signal is sent to the infrared transmitting circuit, which is modulated by the circuit and converted into an infrared light signal for transmission in the air. Then the infrared receiving circuit receives the infrared light signal, which is demodulated by the circuit and restored to a signal that can be processed by the microcontroller. The original data code is obtained by the microcontroller internal processing.

  2 Infrared Communication Protocol

  The purpose of the protocol is to give the sender and receiver an agreement so that they can synchronize and send and receive data correctly. This design uses a quasi-synchronous protocol. When the infrared receiver does not receive a signal, no timing operation is generated. Otherwise, the start bit '0' is received first, and an interrupt is triggered. The timer is started to receive data, and then it is determined whether it is a start bit. If it is, it continues to receive data. Otherwise, the timer is reset and the start bit is re-detected. When receiving the second stop bit, an interrupt is triggered to detect whether the stop bit received for the first time is correct. If it is not correct, the timer is reset and received again. Otherwise, the data segment has been received correctly.

  3 Analysis of the Principle of Infrared Communication

  Infrared communication transmits a carrier signal in the air. When a carrier passes through, the receiving end outputs a digital signal '0', otherwise, it outputs a digital signal '1'. Therefore, the function instruction code sent by the transmitting circuit generally uses a multi-bit binary serial code. In this article, the infrared communication data uses pulse coding, which means that each bit of data signal is represented by a pulse with a pulse width of 526 μs. Two such pulse cycles represent '1', and one such pulse cycle represents '0'. Such pulse signals are modulated on a carrier with a frequency of 38 kHz and then sent out. The signal transmitted in the air after modulation is a carrier signal with a certain time interval, and its duty cycle is determined by the data coding. At the infrared receiving end, the data processing process is just the opposite. After receiving the infrared light signal, it will undergo a series of processing such as shaping, amplification, filtering, modulation, and then output a series of data signals that can be processed by the microcontroller at its output end.

  4 Infrared Communication Hardware Design Principles

  4.1 Hardware Design of Transmitting Circuit

  There are two TPM modules inside the HCS08GT60 microcontroller, each module has two channels, and the PWM function of any channel can be used to output a 38 kHz carrier signal. According to the requirements of the experimental conditions, the programming design in this article uses the central pulse width output function of TPM1 channel 1 to generate a 38 kHz infrared carrier signal. The PTA7 port is used as a common input and output port to generate a square wave signal with a certain pulse width as the data encoding signal input. The hardware schematic diagram is shown in Figure 1.

 

  In the schematic diagram, the electrical node CODE is connected to the PTA7 port to generate data code; the electrical node CLK is connected to TPM1 channel 1 to generate a 38 kHz infrared carrier signal. The resistor and R5 connected in series to the base of the transistor play the role of current limiting protection. The transistor itself has the function of signal amplification. The other two transistors are cascaded to modulate the code on the 38 kHz carrier and transmit it through the infrared transmitter. When the code is '1', Q1 and Q2 are cut off, no current passes through the infrared transmitter, and a low-level signal is emitted. When the code is '0', Q1 and Q2 are turned on. At this time, the carrier signal is amplified by Q2 and reflects the 38 kHz carrier signal on the transmitter. Therefore, different data codes are input at the PTA7 port. Through this transmission circuit, a 38 kHz carrier signal with a certain interval will appear on the transmitter, and the transmitter will convert the carrier signal into an optical signal and transmit it. The timing diagram of the carrier pulse modulation signal is shown in Figure 2. [page]

 

  4.2 Hardware Design of Receiving Circuit

  The HS0038A receiver is used in the infrared receiving circuit. The internal logic block diagram of HS0038A is shown in Figure 3.

 

  It can be seen that the receiver implements infrared reception, amplification, filtering and demodulation functions. When receiving an infrared carrier light signal, the infrared receiver outputs a low level, otherwise it outputs a high level, thereby modulating the intermittent infrared light signal into a continuous square wave signal, which can be converted into the original data after internal processing by the microcontroller.

  The hardware schematic is shown in Figure 4.

 

  Since HS0038A has built-in filtering and is epoxy-sealed, it can be used as an infrared filter, so there is no need to add an additional filter in the circuit, and HS0038A has strong anti-interference ability.

  The infrared receiver output pin RevData is connected to TPM2 channel 0, using the TPM input capture function. Input capture occurs at the rising edge. By comparing the values ​​of the channel register TPM2C0V when the two captures occur, the width of a periodic pulse can be obtained. According to the timing diagram of the transmitted data, we can know what data corresponds to different pulse widths, and thus restore the original data.

  5 Software Design of Infrared Communication

  5.1 38 kHz infrared carrier design

  MC9S08GT60 uses an external 4 MHz crystal frequency. By configuring ICG1=0x78, ICG2=0x30, the bus frequency is controlled to 20 MHz. MC9S08GF60 has a timing/pulse output module inside. If the CPWMS bit of the TPM1 status control register is set to 1, TPM1 will work in the center pulse width output mode; set ELS0B:ELS0A of the TPM1 channel 0 status control register to 10 to control the pulse signal to be high or low when output comparison occurs. In order to make TPM1C1 output a carrier signal with a frequency of 38 kHz, the bus frequency of 20 MHz is divided by 526, that is, 526 square wave cycles of 20 MHz generate a square wave cycle of 38 kHz. Because it is the center pulse width output mode, the output pulse width is twice the value in the channel value register TPM1C1V, and the output pulse cycle is twice the value in the channel preset register TPM1M0D. Therefore, let TPM1C1V=131, TPM1M0D=263. After starting the timer, when the counter TPM1CNTL of timer 1 counts by 1, when the value matches the value in the channel value register TPM1C1V, the pulse output signal is pulled low. When the counter TPMlCNTL of timer 1 starts to decrement by 1, when it drops to the channel register TPMlClV, the pulse output signal is pulled high. The timing diagram of the center pulse width output is shown in Figure 5. The square wave frequency output from this channel is 37.9 kHz or 38 kHz when viewed on an oscilloscope.

 


  5.2 Data Coding Design

  The MC9S08GT60 microcontroller has 36 ports, most of which have dual functions. This article uses port PTA7 and configures the direction register PTADD_PTADD7 of the port to 1, that is, PTA7 is output. According to the rules of pulse encoding, different delay operations are performed to make the port output data pulses of a certain width. By viewing the port through an oscilloscope, a stable pulse sequence can be seen.

  5.3 Input capture design of receiving end signal

  If the bit CPWMS of the TPM2 status control register is set to 0, TPM2 can work in input capture mode, output comparison mode, and edge pulse output mode; to make TPM2 channel 0 work in input capture mode, it is necessary to further set the TPM2 channel 0 status control register, set the mode selection bits MS0B:MS0A of TPM2C0SC to 00, and select the input capture mode. In addition, to set the conditions under which the capture occurs, it is necessary to set the polarity selection bits ELS0B:ELS0A in TPM2COSC to 01, so that the capture occurs when the pin has a rising edge. When a capture occurs, the channel value register latches the value of the timing register. Therefore, when comparing the two input captures, the content of the channel value register can be known according to the encoding rules. The corresponding code of the value is '1' or '0'. In addition, the channel value register is 16 bits. If you want to view the comparison result through the serial port debugging window, because the serial port receive data buffer register is 8 bits, it can be decomposed into two 8-bit data and sent through the serial port.

  The following is the interrupt subroutine for input capture:

 

  Program function description: Send the captured data to the serial port for viewing. No matter what transmitter is used, the identification code can be obtained by observing the serial port data to complete different functions.

  6 Conclusion

  Infrared communication is generally used in low data rate and short distance occasions, so low power consumption is required. The operating voltage of Freescale's microcontroller can reach 1.8 V. In the idle mode of the microcontroller, different stop low power modes are designed by setting the two registers SOPT and SPMSC, or executing a WAIT instruction to put the microcontroller into a waiting low power mode. The implementation process will not be described in detail here. The difference between the MC9S08GT60 microcontroller and other low-voltage and low-power microcontrollers is that it does not sacrifice performance in exchange for a low voltage of 1.8 V. Therefore, this article uses this microcontroller to discuss the design process of sending and receiving infrared circuits and the application of communication protocols. The design of this system is feasible and has certain help for infrared control developers. 

Reference address:Design and implementation of infrared communication

Previous article:Smart LED billboard production plan
Next article:Matrix keyboard principle and structure

Recommended ReadingLatest update time:2024-11-16 14:31

stm32 simulates output of multiple PWM channels through IO port
This is mainly used to control the servo. TIM1 is used to simulate 5-channel 50Hz PWM signal, and only the duty cycle is adjusted to control the servo angle. There is no specific test on the maximum number of channels that can be simulated. Disadvantages: Because it is a timer interrupt simulation (interruptions are m
[Microcontroller]
A Simple Method of Simulating Single-phase PWM Rectifier Using Matlab
A Simplified Method for Simulating Single Phase PWM Rectifier by Using Matlab YE Qi-feng, JIN Xin-min Abstract:A simulation model for a single phase PWM rectifier using Matlab is introduced, which has the advantage of distinct principle, short simulation time and consuming relative little resource. Ke
[Power Management]
A Simple Method of Simulating Single-phase PWM Rectifier Using Matlab
PWM programming of LPC2103
 PWM programming of LPC2103   1. Set the pin function that needs to output PWM wave in PINSEL0/1 register; 2. Set the CTCR register to timer mode (default reset value); 3. Enable the corresponding MAT bit in PWMCON to output PWM function; 4. Set PWM timing time and duty cycle and other parameters: 1) Set the PR r
[Microcontroller]
Research on the Implementation of Carrier Phase-Shifted Multi-Level PWM Based on DSP and CPLD
1 Introduction With the rapid development of power electronics technology and power semiconductor technology, medium-voltage high-power transmission equipment has been widely used in petrochemical, mining, steel rolling and metallurgy, transportation and other fields, which not only improves the utilization r
[Power Management]
Research on the Implementation of Carrier Phase-Shifted Multi-Level PWM Based on DSP and CPLD
STM8 study notes---using PWM function to output SPWM wave
To generate SPWM waves, the key is to generate a set of numbers that change sinusoidally, then correspond the numbers to the duty cycle of the PWM output, and output the duty cycle in sequence. The method of generating sine waves is detailed in the blog on using C language to generate sine wave data, so I won't go int
[Microcontroller]
STM8 study notes---using PWM function to output SPWM wave
Two methods of 51 single chip microcomputer output PWM
The 51 series microcontroller has no PWM output function, but can use the timer and software to output. It is very practical for occasions where the accuracy requirement is not high. The circuit diagram is shown in Figure 1, which uses a high-speed optical isolation (6N137) output and inverts the PWM signal.
[Microcontroller]
Two methods of 51 single chip microcomputer output PWM
STM8 study notes ---- PWM single pulse mode output
First, let’s take a look at the official information on single pulse mode. Let's look at the implementation of C code void PWM_GPIO_Init( void ) {     PC_DDR_DDR6 = 1; // output pin PC6 TIM1_CH1     PC_CR1_C16 = 1; //Push-pull output     PC_CR2_C26 = 1; //Output maximum 10MHZ       PC_DDR_DDR7 = 0; //Input pin
[Microcontroller]
STM8 study notes ---- PWM single pulse mode output
A CPLD-based PWM control circuit design
Abstract: This paper introduces a CPLD-based PWM control circuit designed using the hardware description language VHDL. This PWM control circuit has the characteristics of adjustable PWM switching frequency, 2-way signal interlocking on the same side, adjustable delay time, and simple interface. Can be applied to moder
[Power Management]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号