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.
Previous article:Smart LED billboard production plan
Next article:Matrix keyboard principle and structure
Recommended ReadingLatest update time:2024-11-16 14:31
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Intelligent Control Technology of Permanent Magnet Synchronous Motor (Written by Wang Jun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Circuit-level electrostatic protection design techniques and ESD protection methods
- There are three questions about LC series-parallel circuit, transistor static operating point, and 4G 5G diffraction capability.
- EEWORLD University ---- Live Replay: Microchip Security Series 10 - Automotive Cybersecurity
- Appearance characteristics of chip resistors
- Has anyone used a 15v to 3.3v converter?
- When low EMI power supplies meet crowded circuit boards, what do you do?
- EEWORLD University ---- OpenCV 3 with Python 3 Tutorial
- Siemens 230RC opens for 3 seconds and closes for 3 seconds
- Stack Overflow Technology from Entry to Mastery
- Design of Automatic AC Voltage Stabilizer