0 Introduction
Multi-rate watt-hour meters are indispensable watt-hour metering products under the current electricity conservation and planned electricity consumption policies in my country. The communication interface of multi-rate watt-hour meters generally has both infrared interface and RS485 interface. Infrared communication has the advantages of being intuitive, easy to operate, and highly reliable. It is the most commonly used communication method in watt-hour meters and an effective means for realizing meter reading, programming, time calibration, data management, and other functions between watt-hour meters and handheld devices. The use of Xinmao single-chip microcomputer SSU7301 (51 series), infrared transmitting tube SE303 and infrared receiving tube PIC12043 of Japan Optoelectronics Corporation, as well as the serial port of the single-chip microcomputer and two timers/counters can effectively realize the infrared communication function.
1 Principle of infrared communication
Infrared communication is a communication transmission method that uses infrared waves with a wavelength of 900nm to 1000nm as the carrier of information. The transmitting device sends out binary signals after high-frequency modulation, and the receiving device demodulates the received infrared high-frequency signals into the original information. There are two modulation methods: pulse width modulation (by changing the pulse width modulation signal PWM) and pulse time modulation (by changing the time interval between pulse trains to modulate the signal PPM). This article uses PPM pulse time modulation.
2 Serial port infrared communication hardware design
The infrared transmitting and receiving circuits of the multi-rate electric energy meter mainly include the Xinmao single-chip microcomputer SSU7301, the infrared transmitting tube SE303 and the infrared receiving tube PIC12043 of Japan Optoelectronics Corporation, as well as the driving transistor 8550, resistors and capacitors. The infrared communication hardware schematic diagram is shown in Figure 1.
2.1 Infrared Transmitter Hardware Design
Infrared emission uses the serial data transmission port TXD (P3.1) of the single-chip microcomputer SSU7301 to control the driving transistor BG1 to transmit binary data "0" and "1" (data is sent from the serial transmission buffer SBUF), and uses the P3.4 port to control the driving transistor BG2 to perform high-frequency 38.4kHz modulation (the high-frequency driving signal is generated by the automatic reload mode of mode 2 of the timer/counter T0), thereby reliably realizing the infrared emission tube D1 to perform high-frequency infrared emission when transmitting data "0" and be cut off when data "1". The state relationship is shown in Table 1 and the waveform is shown in Figure 2.
2.2 Infrared receiving hardware design
Infrared reception uses the infrared receiving tube PIC12034 to receive a high-frequency signal and output a low level to determine the data "0", and if it does not receive a high-frequency signal, it outputs a high level to determine the data "1". After demodulation, the data is received serially through the serial data receiving port RXD (P3.0) of the single-chip microcomputer SSU7301 (the received data is stored in the serial port buffer SBUF). [page]
3 Infrared communication software design
DL/T645-1997 "Multifunctional Electric Energy Meter Communication" stipulates that the infrared carrier frequency of the electric energy meter is 38kHz±1kHz; the initial rate is 1200 bps; the byte format of the communication is 8-bit binary code D0~D7, and a start bit (0), an even parity bit P and a stop bit (1) are added during transmission, a total of 11 bits, and the low bit is transmitted first, followed by the high bit. The transmission sequence is shown in Figure 3. According to the above requirements, the infrared carrier frequency in this design is 38.4kHz, the baud rate is 1200bps, and the serial port uses mode 3 for 9-bit asynchronous communication, plus 1 start bit and 1 end bit, and the transmission of one byte of data is 11 bits.
3.1 Infrared carrier and timer/counter T0 settings
The infrared carrier frequency f2 is 38.4kHz. When C/T=0 and M1M0=10 in the timer/counter T0 mode controller TMOD, the timer/counter T0 of SSU7301 is set to mode 2. At this time, TL0 and TH0 are preset to an 8-bit timer/counter that can be automatically reloaded. After TL0 and TH0 are preset to the same initial value by software, when the TL0 count value increases by 1 and overflows, on the one hand, TF0 is set to 1 and an interrupt is requested; on the other hand, the overflow pulse generated automatically enters the data value of TH0 into TL0, and there is no need to re-initialize TL0 by software. The system's crystal oscillator f1 is 11.0592MHz, so the initial values of TL0 and TH0 are calculated as follows:
f2=38.4kHz, so T=1/f2=1/38.4k≈26×10-6=26 μs
, so the period of high-frequency modulation reversal TC=T/2=26/2=13μs
That is, the initial value of timer/counter T0 is TL0=TH0=28-(TC×f1)/12=256-(13×10-6×11.0592×106)/12=256-11.9808≈244=0F4H.
In the interrupt service program of timer/counter T0, only two instructions are needed to realize high-frequency modulation, namely CPL P3.4 and RETI.
3.2 Serial Port and Timer/Counter T1 Baud Rate Generator Settings
The serial port uses mode 3 as a 9-bit asynchronous communication mode with a baud rate of 1200bps. The operation mode selection bits SM0 and SM1 of the serial port control register SCON are set to mode 3. When C/T=0 and M1M0=10 in the timer/counter T1 mode controller TMOD, the timer/counter T1 of SSU7301 is set to mode 2 as a baud rate generator, and its baud rate is expressed as:
Baud rate = (overflow rate of T1) / nWhen
SMOD = 0, n = 32; when SMOD = 1, n = 16, (SMOD = 0 in this design) then
Baud rate = (overflow rate of T1) × 2SMOD / 32
Overflow rate of T1 = (f1/12) / (28-initial value of T1)
So: Baud rate = (overflow rate of T1) × 2SMOD / 32
= [(f1/12) / (28-initial value of T1)] × 2SMOD / 32
So: Timer/counter T1 initial value
TL1 = TH1 = 28-(f1×2SMOD)/(12×32×baud rate)
= 256-(11.0592×106)/(12×32×1200)
= 256-24=232=0E8H
3.3 Programming
According to the setting of the above two parameters, the assembly language program design of 51 series single chip microcomputer SSU7301 is as follows:
The following is the parameter setting program
MOV TMOD, #22H ;Timer/counter T0 mode 2 automatic reload mode is used for PWM38.4KHZ modulation
, timer/counter T1 mode 2 automatic reload mode is used for serial port communication baud rate generator
MOV TH1,#0E8H ;When the baud rate is 1200, the timer/counter T1 automatically reloads the initial value
MOV TL1,#0E8H
MOV TH0,#0F4H ;When 38.4KHz high frequency modulation, the timer/counter T0 automatically reloads the initial value
MOV TL0,#0F4H
SETB ET0 ; Timer/counter T0 overflow interrupt enable bit
SETB TR1 ; Timer/counter T1 start timing control bit
SETB TR0 ; Timer/counter T0 start timing control bit
MOV PCON,#00H ;SMOD is 0, non-multiplication mode
MOV SCON,#0D0H ;Serial port is set to mode 3, allowing reception
SETB ES ;Serial port allows interrupt
SETB EA ;Open the general interrupt enable bit
; The following is the timer/counter T0 interrupt overflow service program
ORG 000BH; Timer/counter T0 interrupt entry address
T0SERVE:CPL P3.4 ; Timer/counter T0 timing inversion P3.4 port for high frequency modulation
RETI ; Interrupt return
; The following is the serial port interrupt service program, taking the reception of a byte of data as an example, and multiple bytes are analogous
ORG 0023H; Serial port interrupt entry address
SENDSERVE:NOP
NOP
MOV A,SBUF ; Send the data in the receive buffer to register A
... ; Perform data processing and other functional operations
RETI ; Interrupt return
; The following is the serial port sending program, taking the sending of a byte of data as an example, and multiple bytes are analogous
COMSEND: MOV A,#DATAH ; Send data to register A
MOV C,P ;Send the even parity bit generated by the data in A to the carry flag
MOV TB8,C ;Send the even parity bit to the 9th data to be sent
MOV SBUF,A ;Send data to the send buffer
JNB TI,$ ;Wait for the end of sending in query mode
CLR TI ;Clear the send interrupt flag
... ;Continue sending or other function operations
RET Subroutine returns
4 Conclusion
The biggest feature of this design is that the pulse oscillator is omitted, and only the serial port and two timers/counters of the single-chip microcomputer on the multi-rate electric energy meter are used, which not only makes the multi-rate electric energy meter simpler in hardware design and lower in cost, but also makes the software more convenient and reliable. At the same time, this infrared communication method can also be applied to the application field of single-chip microcomputers with serial ports and timers/counters.
Previous article:Design of intelligent infusion control system based on single chip microcomputer
Next article:Inkjet Printer Control Technology Based on 51 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!
- 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
- RS485 chip SN75LBC184 burned out
- Simple smart home system design based on Arduino and OneNET cloud platform
- Programmable Power Supply Technology and Application Guide (6) - Reducing Noise from Power Supply to DUT
- 【GD32L233C-START Review】- Summary of the initial review
- Design of heterogeneous pads in AD9
- Zigbee based on CC2430 enables terminal devices to access the network based on a specific PAN ID
- Some posts related to Qinheng EE are sorted out, and there are also school videos in the download center
- How can we check whether the heat dissipation area of the control board is sufficient?
- Correcting ICOM IC-725 frequency deviation without frequency meter
- Freshman asks for a simple wind tunnel control program