With the rapid development of microelectronics and computer information technology, wireless data communication systems composed of single-chip microcomputers and wireless transmission modules have been increasingly widely used in wireless control, data acquisition, fault alarm and many other fields in the petroleum, electric power, hydrology, metallurgy, security and other industries. The coding and decoding of data has a significant impact on the reliability of wireless transmission. At present, there are two main coding and decoding methods: hardware coding and decoding and software coding and decoding. Based on the research on existing hardware and software coding and decoding technologies, this paper designs and implements a method of encoding and decoding transmission data in software through the STC89C516RD+ single-chip microcomputer.
1 Existing coding and decoding technology
1.1 Hardware coding and decoding technology
There are currently many dedicated chips for encoding and decoding, and PT2262/PT2272 is a more commonly used one. In normal use, 8-bit address code and 4-bit data code are generally used. At this time, the 1st to 8th pins of the encoding chip PT2262 and the decoding chip PT2272 are address setting pins. There are three states to choose from: floating, connected to the positive power supply and grounded. 38 is 6 561, so the address code is not repeated in 6 561 groups. Only when the address codes of the transmitter PT2262 and the receiver PT2272 are exactly the same can they be used in pairs. When the encoding start terminal TE is connected to a low level, PT2262 will encode the data input from the data input terminals D0~D3 and output it serially from the DOUT pin [1]. The high 8 bits of the data frame are the address, and the low 4 bits are the data. When sending, they are sent in the order of high bits first and low bits later. Each frame is sent 4 times, and each frame of data is separated by a synchronization code. Only when PT2272 detects the same address code and data code twice in a row will it drive the corresponding data output terminal to a high level and drive the VT pin to a high level synchronously [2]. After the VT pin is reversed, it is connected to the external interrupt input pin of the microcontroller to notify the microcontroller that the data has been received by triggering an interrupt.
The PT2262/PT2272 chip has low power consumption, few external components, and a wide operating voltage range. However, these two chips must be uniformly encoded in the application and used in pairs, and the chip address can only be reset by changing the hardware circuit; the frame format of the encoding chip is fixed and cannot be changed at will, and the encoded pulse width needs to be adjusted to change the size of the external oscillator resistor. All of these have brought great inconvenience to users.
1.2 Software encoding and decoding technology
In the process of using a single-chip microcomputer and a wireless transmission module for wireless data transmission, the timing sampling method is usually used when using software encoding and decoding. The overall design idea is as follows: the transmitter generates pulses or pulse combinations of different widths through a timer delay to achieve the encoding of data "0" and "1". The receiver samples the received pulse signal at a fixed time, and then identifies the corresponding data signal through calculation. When decoding through the timing sampling method, there are relatively strict requirements on the sampling frequency. According to the Nyquist theory, the digital signal can only be accurately restored when the sampling frequency is higher than twice the highest frequency of the transmitted signal [3]. However, the response and return of the interrupt and the judgment of the data will cause time delay. Therefore, the frequency of the transmitted signal cannot be too high, otherwise it will easily lead to data loss. At the same time, the timing sampling requires multiple calls to the interrupt service program, which adds extra time overhead. These will reduce the rate of wireless data transmission.
2 Improved encoding and decoding technology
2.1 Software encoding principle and program flow
Coding is to use different forms of code types to represent binary "1" and "0". The encoding method adopted in this paper is pulse-gap encoding, that is, the pause duration t before the next pulse represents the binary symbol "1", and the pause duration 2t before the next pulse represents the binary symbol "0" [4]. The pulse-gap encoding is shown in Figure 1. The signal at the transmitting end is divided into synchronization signal, data signal and checksum signal. The wireless transmission circuit is shown in Figure 2. The encoded signal is output from the P1.7 pin of the microcontroller to the wireless transmission module, and then the wireless transmission module modulates the baseband signal through the high-frequency carrier circuit and radiates it into space through the antenna.
When encoding data at the transmitting end, the delay time caused by the judgment of the transmitted data bit and the number of bits and the generation of the checksum does not exceed 70T, where T is the machine cycle. Therefore, a high-level pulse of 100T is defined to represent "1", and a high-level pulse of 200T represents "0". When decoding at the receiving end, the falling edge on the INT1 pin triggers an interrupt and stops the timer count, thereby identifying the data signal. The delay time of the interrupt service program in this process does not exceed 50T. Therefore, the low-level pulse width between data bits is set to 70T. In order not to be confused with the data signal, the synchronization bit is defined as a high-level pulse of 300T. The quartz crystal used in this experiment has a crystal oscillator frequency of 12 MHz, so a machine cycle is 1 μs, so the transmission rate of one byte is 5 882 b/s at the fastest and 3 703 b/s at the slowest.
The software coding program flow chart is shown in Figure 3. Timer 0 is used to work in mode 1, that is, the 16-bit timer working mode. Different initial values are loaded into the counting registers TH0 and TL0 according to different output pulse width requirements. The flag flags_0 is used to distinguish high-level pulses from low-level pulses. When the flag flags_0 is 0, a low-level pulse between two data bits is output, and a high-level pulse is output when it is not 0. The flag flags_1 is used to distinguish data bits from synchronization bits. When flags_1 is 0, a data bit high-level pulse is output, and when it is 1, a synchronization bit high-level pulse is output. During the transmission process, each byte is sent, and the byte is accumulated into the checksum. When all the data is sent, the checksum is sent.
[page]
2.2 Software Decoding Principle and Program Flow
Decoding is a process of using a specific method to restore digital data to the content it represents, or to convert electrical pulse signals into the information, data, etc. it represents. This paper uses a method combining a timer and an external interrupt to decode the received pulse signal, and uses the received checksum for verification.
Set the gate bit GATE of the mode control register TMOD of the microcontroller to 1. When TR1 = 1, the external interrupt INT1 directly controls the start and stop of timer 1, that is, when INT1 changes from 0 to 1 level, the counting starts; when INT1 changes from 1 to 0 level, the counting stops. This situation is often used to measure the width of the positive pulse appearing on the INT1 pin [5]. The wireless receiving circuit is shown in Figure 4. The wireless receiving module demodulates, amplifies and shapes the received signal, restores the baseband signal, and outputs it to the INT1 pin of the microcontroller from pin 2. Set external interrupt 1 to the falling edge trigger mode, and timer/counter 1 to the 16-bit timer working mode. When a negative transition from high to low occurs on the INT1 pin, an interrupt is triggered, timer 1 stops counting [6], and the values in the counting registers TL1 and TH1 are read to determine the pulse width, thereby decoding the received data signal.
Since it takes time to reload the initial count value, receive data, and respond to interrupts during the transmission process, the actual pulse width received is greater than the pulse width sent. Therefore, if the received high-level pulse width is greater than 300T, it means that the synchronization bit is received; if it is greater than 200T, it means that the data bit "0" is received; otherwise, it means that the data bit "1" is received. The software decoding flow chart is shown in Figure 5. After receiving the synchronization bit, data reception begins, and reception is suspended until the synchronization bit is received again. The received data and checksum are used for verification. If the received data is correct, the reception is stopped; if it is incorrect, all the previously received data is discarded and the reception is restarted.
Experiments have shown that when software encoding and decoding are performed by this method, the address can be set by software programming according to different needs. The receiving end and the sending end can perform many-to-many wireless data communication without the need for pairing; the pulse width of the encoding can be changed by changing the initial value of the timer count register, thereby changing the transmission rate; the decoding is accurate and fast, occupies relatively less CPU resources, and is easy to operate; the verification method is optional, and the data frame format is flexible and changeable.
In this experiment, a quartz crystal with a crystal oscillator frequency of 12 MHz and an 8-bit microcontroller with a CISC structure are used. One machine cycle of it takes 12 oscillation cycles, and it takes at least one machine cycle to execute an instruction. The processing speed is slow, which affects the wireless transmission rate to a certain extent. The wireless data transmission rate can be increased by increasing the crystal oscillator frequency or selecting a faster microcontroller as the control chip. For example, a C8051F series microcontroller with a pipeline structure or an AVR series microcontroller with a prefetch instruction function can be selected, which can complete an instruction within one clock cycle. You can also use a single-chip microcomputer with a DW8051_core core, which uses a mode of 4 clock cycles as 1 instruction cycle. Under the same clock cycle, the processing capacity is 3 times that of the standard 8051. Using these high-speed single-chip microcomputers can reduce the delay time caused by program execution, thereby shortening the data bit encoding pulse width and increasing the wireless data transmission rate.
References
[1] Li Guofeng, Feng Yongzhen, Lu Guangwen. Implementation of short-range wireless encrypted transmission of Wiegand signals [J]. Wireless Communication Technology, 2009(1): 31-36.
[2] Zhao Qiu. Wireless transceiver circuit using codec chip [J]. Information Research, 2009, 35(9): 35-38.
[3] Shao Pingfan, Chen Huabin. Implementation method and performance analysis of software codec for wireless signals based on Atmega8 [J]. Fujian Computer, 2009(8): 115-116.
[4] Kang Dong, Shi Xiqin, Li Yongpeng, et al. Radio Frequency Identification (RFID) core technology and typical application development cases [M]. Beijing: People's Posts and Telecommunications Press, 2008.
[5] Mei Lifeng, Wang Yanqiu, Wang Yuduo, et al. Principles of single-chip microcomputers and interface technology [M]. Beijing: Tsinghua University Press, 2004.
[6] Ma Zhongmei, Ji Shunxin, Zhang Kai, et al. C language application design for single-chip microcomputer (4th edition) [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2007.
Previous article:Introduction to Misunderstandings in Software Anti-interference Technology of MCS51 Series Microcontrollers
Next article:Design of Remote Temperature Detection System Based on 8051 Single Chip Microcomputer
- Popular Resources
- Popular amplifiers
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- I work 996 in Beijing, and you have retired in your hometown, so what? (Source: LinkedIn)
- How to assign initial values to a continuous RAM range in C2000 chip
- [AT-START-F425 Review] Real-time Clock (ERTC)
- [Sipeed LicheeRV 86 Panel Review] 2-Use the shell to control the LED flashing
- Millimeter wave sensors
- Is pulse power supply DC or AC?
- Jiefa AC7801X data summary
- C language function interrupt function
- [Project Source Code] The device library has been installed but it is reported that it is not installed - Solution
- The auxiliary power transformer of new energy vehicles has a power of 2.4-6.6kw. How small can its volume be?