introduction
At present, measuring instruments are developing towards networking, and each individual embedded instrument will become a node on the Internet. This system realizes the networking of electronic energy meters in the form of ARM+RTOS. The hardware platform is based on the ARM core microcontroller LPC2104, and the software system is developed under the uC/OS-II operating system.
System hardware design
LPC2104 is a 32-bit microcontroller based on ARM7TDMI-S launched by Philips. LPC2104 integrates many functions, including 128k bytes of high-speed Flash memory, dual UARTs, multiple 32-bit timers, SPI, I2C serial interfaces and RTC, etc. Among them, UART1 has a complete modem interface and can be used in network products.
CS5460 is a single-phase power/electric energy metering chip from Cirrus Logic with a serial interface. CS5460 is highly integrated and contains two ADCs, high/low pass digital filters, energy calculation units, serial interfaces, and digital-to-frequency converters. CS5460 stores its measured and calculated results in its various registers, and the energy value is output to the CPU through pulses, and can also drive the meter.
The working principle of the networked meter is: first, the sampling circuit converts the input large current/voltage into a small voltage signal that can be received by CS5460. CS5460 calculates the electric energy based on the sampled current/voltage, and then transmits the current, voltage, electric energy and power to the CPU through a three-wire bidirectional serial interface (the energy value is output through pulses). The CPU displays the results on the LCD according to the input instructions of the keyboard or transmits the results to the Internet through the serial port. LPC2104 itself serves as both the controller of CS5460 and the embedded gateway, realizing the remote communication function of the electric energy meter. For the hardware structure diagram of this system, please refer to "Electronic Design Applications" 2004.8.
CS5460 can only receive small voltage signals less than 150mV. In the sampling circuit part, an appropriate current/voltage transformer should be selected to convert the input current/voltage to the voltage range that CS5460 can receive.
In the voltage sampling circuit, the input voltage is stepped down and isolated by the voltage transformer, and then low-pass filtered. The capacitor C1 at the end shows a large impedance and is used to sample the voltage. The current sampling circuit has an additional sampling resistor R5 compared to the voltage sampling circuit. R5 is used to convert the current from the current transformer into voltage. For the sampling circuit diagram, see "Electronic Design Applications" 2004.8.
CS5460 and LPC2104 use standard SPI interface, which is very easy. Since CS5460 outputs energy value in fixed-width variable pulse, its energy output pin is connected to an external interrupt pin of LPC2194 to collect energy value.
Since the accumulated value of electric energy and calibration constants need to be saved in EEPROM, a 24C16 is added to save these values. LPC2104 itself has an I2C interface, so it is very easy to expand EEPROM.
The 4UART1 port of LPC210 has a complete modem interface. Since the amount of data required to transmit when the energy meter is connected to the Internet is not large, a low-speed modem chip can be selected. Here, the MSM7512B of OKI Company is selected. MSM7512B is a 1200bps half-duplex FSK modem. It uses a single 3-5V power supply and has low power consumption.
It should also be noted that the CS5460 input/output signals are both 5V, while the LPC2104 signals are 3.3V, so a level conversion circuit is required between the two. [page]
System software design
ARM application system can be based on embedded operating system platform, or can be started directly through startup code without using operating system. In order to realize networking function conveniently, this system chooses the method based on embedded operating system platform. After cutting down, embedded real-time operating system uC/OS-II has only 128K Flash memory, so uC/OS-II can be transplanted into it.
First, you need to port the uC/OS-II operating system to the LPC2104 microprocessor. To facilitate porting, most of the uC/OS-II source code is written in C language. During the porting process, only a few files directly related to the processor need to be rewritten. There are successful examples of porting uC/OS-II to LPC2104, which can be found on the Internet.
uC/OS-II itself does not support network functions. In order to realize the networking of the energy meter, the TCP/IP protocol needs to be transplanted. Since the functions of this embedded system itself are relatively simple, a simple embedded protocol stack can be selected to remove unnecessary protocols. Since the amount of data that the energy meter needs to transmit is not large, but the reliability requirement is high, the reliable data transmission control protocol TCP should be selected at the transport layer, and the basic data transmission protocol IP should be selected at the network layer.
The software part mainly realizes the following functions:
1. Data acquisition and calculation. The calculation part is mainly completed by CS5460. After the command to start the conversion is issued, the required measurement value can be read from the corresponding register after a proper delay. The electric energy value is transmitted to the CPU in the form of pulses. The measurement of effective power is achieved by counting pulses of 1 second. For example, the CS5460 can be programmed to generate a pulse every time 10 joules of energy are converted, and then the effective power is calculated by multiplying the pulse count by 10. Every few minutes, the current accumulated energy will be written to the 24C16 serial EEPROM. In this way, all the energy over the elapsed time can be saved. The calibration constants are also stored in the 24C16. However, when the system is powered on again, these calibration constants will be read from the 24C16 and written back to the CS5460.
2. Button management and LCD display. Since the bus of LPC2104 is not developed, it brings some inconvenience to driving the LCD display, but it can be operated by simulating the bus timing of the ordinary I/O port.
3. System calibration. Before calibration, the CS5460 should be in a valid operating state, and receive valid commands through SPI, clear the data ready bit (DRDY) in the status register; then, apply the corresponding calibration signals to the voltage and current input channels; then, send an 8-bit calibration command word to the CS5460 through the SPI interface; finally, save the calibration results in the corresponding calibration register, and set the DRDY bit to notify the CS5460 that the calibration is complete. The calibration module mainly provides a management interface, through which the user can calibrate the voltage, current, power and other parameters of the ammeter, and save the calibrated data.
4. Network communication. It is necessary to send AT commands to control the modem and generate data streams that comply with the communication protocol. When sending data, the data sent by the application is encapsulated by the TCP/IP protocol, and then encapsulated into PPP frames using the lower-layer PPP protocol, and then the PPP frames are sent out through the asynchronous serial port driver. When receiving data, the asynchronous serial port driver is responsible for receiving the data. Then the TCP module and the IP protocol module process the data and hand over the user data to the application.
uC/OS-II is a preemptive real-time kernel that always ensures the highest priority ready task to run. uC/OS-II can complete the scheduling and synchronization between tasks and coordinate hardware resources. Tasks share data and communicate with each other through communication mechanisms such as semaphores, mailboxes, and message queues. The key to programming based on the uC/OS-II embedded operating system platform lies in the division of tasks and the determination of priorities. The task division diagram of this task can be found in "Electronic Design Applications" 2004.8.
The priority of each task is: over-current and over-voltage protection > data processing > real-time clock > data storage > remote communication.
Conclusion
The networked electric energy meter software system introduced in this article is developed under the embedded operating system platform, which is convenient for debugging a single task, and the error of a single task will not cause the collapse of the entire system. Traditional embedded network products require a special gateway to realize network transmission of data. This system realizes the integration of embedded gateway and measurement control part, which is the trend of realizing the Internet access of embedded products in the future.
Previous article:Design of embedded power parameter detection system based on ARM920T
Next article:Two CAN bus expansion methods based on ARM920T
- 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
- Vote for reliable national chips - MCU: Test, test, test, which reliable national chips have the first-line forum friends detected?
- C6000 embedded assembly C and assembly comparison and function description
- [Atria AT32WB415 Series Bluetooth BLE 5.0 MCU] Infrared Detection
- After reading these two books, you will never be embarrassed to talk about the Internet of Things again!
- Verilog007
- Zhongke Bluesun (AB32VG1) development board (based on RT-Thread system) --- Music player -- Sharing
- What exactly is a sine filter?
- Pingtouge RVB2601 board-GPIO
- [TI recommended course] #DC/DC switching regulator packaging innovation#
- ST60 short-distance, contactless connector evaluation 1: application environment and principle