Design of Electricity Meter Reading System Based on CAN Bus

Publisher:WhisperingWindsLatest update time:2012-07-19 Source: mcu99 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction to CAN Bus

CAN works in multi-master mode, and any node on the network can actively send information to other nodes on the network at any time; the node information on the CAN network is divided into different priorities to meet different real-time requirements; CAN uses non-destructive bus arbitration technology; CAN can transmit and receive data in several ways such as point-to-point, point-to-multipoint and global broadcast simply through message filtering; CAN's direct communication distance can reach up to 10km (rate below 5kbit/s), and the communication rate can reach up to 1Mbit/s (at this time the maximum communication distance is 40m); each frame of CAN information has CRC check and other error detection measures to ensure that the data error rate is extremely low; CAN's communication medium can be twisted pair, coaxial cable or optical cable, which is flexible to choose.

System design

The system consists of the following parts: pulse watt-hour meter, power collector, CAN converter, modem, and host computer. The system block diagram is shown in Figure 1.


Figure 1 Block diagram of the power meter reading system

As shown in Figure 1, the power collector collects the pulse signal output by the pulse meter of the residential building in real time, transmits it to the CAN bus through the CAN interface, and then converts it through the CAN converter and the Modem to realize the communication between the upper computer and the lower computer, thereby completing the data collection, storage, measurement, display and other functions, and realizing real-time monitoring of the situation of each user in the entire community.

How the system works

Electricity measurement collection
According to the structure of the rotary meter, its pulse is proportional to the number of turns of the rotary disk. The corresponding electricity measurement can be obtained by accumulating the number of pulses and multiplying them by a coefficient. In order to improve the accuracy of pulse measurement, the method of timed continuous sampling is adopted in software design. An effective electrical pulse width is more than 50ms, and the timing cycle used in the design is 16ms. For normal pulses, the number of times the pulse is high level continuously measured by timed sampling is ≥2, as shown in Figure 2. If the pulse width is too small and the number of times measured is less than 2, the pulse can be removed.

Click to browse products in a new window
Figure 2 Schematic diagram of pulse sampling inspection

Power collector
The main function of the power collector is to count pulse data and communicate with the host computer. Its core components are the AT89C52 microprocessor and the interrupt controller 8259A. In the system, the interrupt source exceeds 8 levels, so the 8259A adopts a cascade mode. There are 5 8259A cascades under each power collector to meet the input of 32 power signals. The principle block diagram of the power collector is shown in Figure 3.

Click to browse products in a new window
Figure 3 Schematic diagram of power collector

In the system, 8259A is used to cooperate with AT89C52 to control external interrupt sources. 8259A analyzes, judges, and determines the priority of interrupt request signals for AT89C52. Interrupt signals from multiple meters are sent to 8259A after being input into the processing circuit. When one of them is at a high level, the corresponding bit of IRR (interrupt request register) of 8259A is set; then, 8259A analyzes and processes the situation provided by its IRR and IMR (interrupt mask register). When a certain interrupt source is not masked by IMR, and the priority level of the interrupt source is higher than the level of the transaction being processed by the CPU, the 17 pin of 8259A generates a high level, and then changes to a low level through a special interrupt application and response circuit Click to browse products in a new window , and then an interrupt request is made to AT89C52, while the rest of the interrupt signals are queued and saved. In this way, the pulse signal will not be lost, ensuring the accuracy of the system acquisition signal. After that, the AT89C52 that receives the interrupt request will compare the priority of the currently running program with the interrupt request, and send an interrupt response signal back to the 8259A through the interrupt request and response circuit Click to browse products in a new window . At this time, the AT89C52 will turn to execute the interrupt service program. [page]

In order to protect the collected data, a memory is used in the design. The storage area can be divided into two areas: a working area that stores real-time power measurements and is refreshed once every certain period of time; and a backup area that backs up 6 months of power measurements to prevent the loss of useful information.

To facilitate user query, the system can design a display circuit LCM103 in the collector to realize on-site display. Its display function can be realized by connecting its pins CS, WR, DA2TA and the relevant interface of the single-chip microcomputer. The data of multiple interrupt sources are displayed in turn in LCM103. The 10 bits of LCM03 can be defined as user household, meter and display data respectively. The 10th bit is the household, the 8th bit is the meter, and the remaining bits represent the energy consumption of each meter. The 3rd bit is the decimal point. The 9th and 7th bits are spaces for clear reading.

When designing, add a 511kΩ resistor between the VDD and VLCD pins of LCM103 to ensure moderate display brightness.

CAN interface converter
The CAN converter consists of a CAN controller SJA1000 and a CAN driver PCA82C250. The CAN converter is responsible for receiving commands from the host computer and transmitting the power of the station to the upper computer. A maximum of 110 stations can be connected to a CAN bus. Its block diagram is shown in Figure 4.

Click to browse products in a new window
Figure 4 CAN controller interface functional block diagram

CAN converter
In order to realize the communication between the microcontroller and the host computer, an interface for converting between TTL level and RS-232 is designed, as shown in Figure 5. AT89C52 itself does not contain a controller, so the CAN controller SJA1000 and CAN driver PCA82C250 are used.

Click to browse products in a new window
Figure 5 Functional block diagram of RS232/CAN converter

CAN bus communication baud rate
The baud rate of the communication between the host computer in the community control room and the single-chip microcomputer in the power collector is calculated to be 40.5Kbit/s. Taking 50Kbit/s, the communication distance of the CAN bus is 1.5km. If the control room is built in the load center, this communication distance can meet the requirements. At this time, the bus timing registers BTR0 and BTR1 are BTR0=47H=01000111B and BTR1=2FH=0011111B respectively. In addition, in order to synchronize the operation of each station in the system, the host computer must issue a time calibration command to each station at the hour.

Software Design

The design of the main program of the collector is briefly described. It includes two parts: initialization and data acquisition processing. The initialization program includes the initialization of 8259A. In the data acquisition part, the main program of the collector adopts the method of cyclic data acquisition, and classifies the received commands, and then transfers to the corresponding command processing subroutine. The main program flow chart is shown in Figure 6.

System anti-interference measures

(1) In the system design, the X5045 chip was selected, which has a watchdog circuit. The watchdog circuit monitors the CPU in real time. If the CPU falls into an infinite loop, the watchdog circuit can detect it in time and reset the entire system. In software programming, the watchdog circuit is set to be accessed once every 1 second. If the program runs away or the watchdog chip is not accessed for a set time (set to 1.4 seconds in this system), the X5045 chip will automatically output a reset pulse until the program runs normally.

(2) The data acquisition device is equipped with a filtering circuit to filter the electrical pulse signals generated by various meters to prevent possible interference to the signals during transmission.

(3) Use the power monitoring function of the X5045 chip to set up a power monitoring circuit and a power-off protection circuit to prevent data loss after power failure.

Click to browse products in a new window

Conclusion

The electric meter reading system based on CAN bus adopts intelligent data acquisition and exchanges data through CAN bus. The system has fast response speed and strong anti-interference ability. The network has high reliability, high communication baud rate and large data transmission volume. The structure is simple and easy to install and maintain. The system can easily realize real-time monitoring, high-speed data acquisition, table lookup and printing, system monitoring and other functions, and has good application prospects.

Reference address:Design of Electricity Meter Reading System Based on CAN Bus

Previous article:Design and development of intelligent fuzzy water supply controller
Next article:The simplest temperature measurement system based on AT89C51 and DS18B20

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号