Battery charging and discharging monitoring system based on MATLAB

Publisher:MagicGardenLatest update time:2012-03-08 Source: 21IC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
As oil prices continue to rise, people are under increasing pressure from fuel costs. Most people are beginning to pay attention to transportation tools that use other energy sources, and more and more transportation tools use batteries as energy sources. The safety and life of batteries are also increasingly attracting people's attention. At present, there are three types of batteries that can be used in electric bicycles: lead-acid batteries, nickel-metal hydride batteries, and lithium-ion batteries. Because lead-acid batteries are low in cost and cost-effective, most electric vehicles now use lead-acid batteries. This article designs a charging characteristic monitoring system for single-cell lead-acid batteries.

1 System Overview

Parameters related to battery charging and discharging include: battery terminal voltage, charging current, battery temperature, etc. Therefore, the system needs to accurately collect these three parameters. The system block diagram is shown in Figure 1. The system consists of MCU, analog sampling circuit, temperature acquisition circuit and host computer. The MCU collects terminal voltage, current and temperature information during battery charging and discharging, and then sends the information to the host computer through the serial communication interface, and then receives and processes it by MATLAB, and draws a curve. The current and voltage are collected 10 times per second, and the temperature is collected once per second. The MCU transmits a set of data to the host computer every second, and MATLAB tracks and updates the data to achieve the effect of dynamically displaying voltage, current, and temperature.



2 Hardware Design

2.1 MCU Selection

The MCU of this monitoring system uses STC12C5A60S2. The chip resources include: 60K flash, 1280 bytes high-speed RAM, 8-channel 10-bit A/D, 2-channel UART, 2-channel 16-bit timer, and 1-channel internal watchdog timer. The crystal oscillator is 11.0592MHz.

2.2 Temperature acquisition chip selection

The temperature acquisition circuit chip uses DS18B20 produced by Dallas. It is a linear digital temperature sensor produced by Dallas. It uses a 3-pin T0-92 small package. The temperature measurement range is -55℃~+125℃, and it can be programmed to 9-bit to 12-bit A/D conversion accuracy. The temperature measurement resolution can reach 0.0625℃. The measured temperature is serially output in a 16-bit digital format with sign extension. It has the advantages of directly outputting digital signals, no interference in the signal transmission process, convenient expansion, and no need to design additional signal modulation circuits.

In order to make the temperature collection more accurate, this system uses two DS18B20s, and the A/D conversion accuracy is selected as 12 bits, which are attached to different positions of the battery wall.

2.3 Design of current and voltage detection circuits

The voltage check uses resistor voltage division, and is sent to the A/D conversion interface through the voltage follower circuit. The role of the operational amplifier is to increase the input impedance, reduce the impact of the detection circuit on the charging circuit, and improve the measurement accuracy.

There are two methods for current detection: high-end detection and low-end detection. Low-end detection is easier to implement, but the disadvantage of this solution is that the load will raise a DC voltage higher than the actual ground line, and the measurement is inaccurate; in addition, the power supply and load have different reference grounds, which is not conducive to EMI control. The difficulty of high-end detection is that there is a common-mode voltage at the input end, and the measurement circuit is complicated. This system uses Maxim's MAX4173 to measure the differential mode voltage, which includes a differential amplifier inside. Selecting two MAX4173s can realize bidirectional sampling of current. The current detection circuit is shown in Figure 2.



3 MCU software design

MCU completes functions including reading two-way A/D conversion (voltage, current); reading two-way DS18B20 conversion results; serial communication. Voltage and current change more drastically, the sampling period should be short, but a short period will result in a large amount of data, increasing the burden of transmission and data analysis. After weighing, the sampling period of voltage and current is taken as 0.1s. Temperature is a physical quantity with a long time parameter, so the sampling time can be relaxed. Here, the sampling period is taken as 1s.

3.1 MCU Program

In order to coordinate the implementation of various functions, this paper refers to the multi-task scheduling algorithm and the time slice rotation algorithm. The multi-task scheduling algorithm divides the functions to be implemented by the microcontroller into multiple task modules according to actual requirements, and specifies the priority level, and a task scheduling module uniformly controls the execution order. The control of the CPU is allocated to different task modules according to different priorities. Each module accesses the CPU within its own execution time, forming a multi-task effect of taking turns to execute at the micro level and running concurrently at the macro level, as shown in Figure 3.


Several tasks in this system are sensitive to time requirements, and simply using multi-task scheduling cannot meet the needs. Combined with the time slice rotation algorithm, time constraints are considered when allocating tasks, and tasks are prioritized. Tasks with high priorities are executed first. To ensure the stability of the sampling cycle, A/D conversion and temperature conversion have higher priorities. Sending the serial port several tens of milliseconds later will not cause adverse effects, so the priority is lower. The brief flow of the program is shown in Figure 4.


The task scheduling module contains the time information of each task, such as A/D conversion every 0.1s, temperature detection every 1s, temperature reading every 40ms, and serial port sending every 0.1s. If a task contains multiple sub-functions, the finite state machine (FSM) algorithm is used to execute one sub-function at a time until the task is completed.

The A/D conversion is relatively simple and will not be described in detail. The main point to note is that after starting the A/D conversion, you must wait for the conversion to complete before reading the result, otherwise the result read out will be the last conversion result .


3.2 DS18B20 Program

The operation of DS18B20 is divided into three steps: initialization, ROM command and DS18B20 function command. The operation timing of DS18B20 is shown in Figure 5. It can be seen from the timing diagram that DS18B20 has strict requirements on the operation timing, otherwise it will cause operation failure.


According to the timing diagram, each read bit of data requires a 60us delay. In order to ensure accurate delay, the method used is to look at the assembly language and calculate the number of null instructions (NOP) that need to be added.

After writing the code according to the timing requirements, the following statistics are obtained: the start-up temperature conversion time is about 2.5ms, and the temperature reading time is about 10.25ms. These time quantities are much smaller than the length of a time slice (20ms), which meets the requirements. In order to achieve 12-bit accuracy, the device manual requires that the interval between two start-up temperature conversion times must not be less than 750ms. Temperature acquisition can be achieved once every 1s. The task flow chart for reading temperature is shown in Figure 6.


In Figure 6, SenseNo refers to the serial number of the DS18B20, and SenseCNT is the total number of devices. The way to read different DS18B20s is to use the device's own ID, which can be read out through the program, but it is more cumbersome. In order to reduce the burden of the program, we read out the ID of each device in advance through other methods and use it directly when reading the temperature, which simplifies the task.

3.3 Communication Protocol

The system transmits the sampled data to the host computer every 1s. In order to ensure reliable transmission, the following communication protocol is formulated:


There are 4 groups of data, voltage (24Byte), current (24Byte), temperature 1 (6Byte), temperature 2 (6Byte). When the baud rate is 19200bps, the longest group of transmission time is about 12ms, which is less than the length of a time slice and meets the requirements. In the task, a group of data is sent each time, and the algorithm is similar to the temperature reading task.

4 MATLAB Program Design

In order to facilitate drawing and data analysis, we use MATLAB as the host computer development tool. The main tasks include serial communication with MCU; data scale conversion; and drawing 4 curves on the same interface.

4.1 Serial communication and data processing

Starting from Matlab 6.0, Mathworks has added the instrument control toolbox to the software, providing formal support for serial communication of RS-232/RS-485 communication standards. Using the Serial class and instrcallback callback function of the toolbox, real-time serial communication can be reliably performed.

The order of serial port operation is (1) create a serial port and set its properties; (2) open the serial port; (3) read and write serial port operations; (4) close and clear the serial port device object.

After reading the data, extract the voltage, current and two-channel temperature data according to the protocol. Since these data are raw A/D conversion data and have no actual physical meaning, they need to be scaled. That is, the physical meaning represented by the data is expressed. For example, for voltage detection, the A/D reference voltage is 5V, so for a 10-bit ADC, the voltage value represented by the conversion result N is: N*5/1024. After the scale conversion is completed, it is stored in the buffer.

4.2 Handle drawing

The system needs to display three physical quantities, voltage, current and temperature. Due to different physical units and sampling periods, three coordinate systems need to be drawn and displayed separately. MATLAB does not provide such a drawing function, so the handle drawing function of MATLAB is used here.

When creating each graphic object, MATLAB assigns a unique value to the object, which is called the graphic object handle (Handie). A handle is a unique identifier of a graphic object. The handles of different objects cannot be repeated or confused. Graphic objects include root screens, windows, coordinate axes, lines, etc. The so-called handle drawing is to use the underlying drawing function to achieve drawing by setting and operating the object properties (Handle Graphics).

5 Running Example Analysis

The system is used to monitor the charging of a lead-acid battery (12V). The computer effect is shown in Figure 7:


In Figure 7, the horizontal axis is the time axis, which is updated once per second; there are three vertical axes, namely the current and voltage on the left, and the temperature on the right; the current curve is red, the voltage is black, the temperature 1 is a blue solid line, and the temperature 2 is a blue dotted line. The four curves correspond to their respective coordinates.

In general, due to the influence of factors such as the internal resistance of the battery and the speed of electrochemical reaction, the terminal voltage during charging is higher than that during static state, and the terminal voltage during discharge is lower than that during static state. The longer the battery is used, the higher the internal resistance, and the more sensitive it is to the charge and discharge current. As shown in the figure, a slight change in the charging current (about 0.1A) causes a sharp fluctuation in the terminal voltage (about 9V). The battery terminal voltage is very sensitive to the charging current, indicating that the battery internal resistance is large. In addition, for a lead-acid battery with good performance, the voltage is between 11V and 13V when it is static, while the static terminal voltage of the battery is less than 6V. It can be inferred that the battery has been seriously damaged.

6 Conclusion

Through this system, we can very intuitively monitor the relationship between the battery terminal voltage and the charge and discharge current, as well as the temperature changes, which is helpful for studying the battery charge and discharge characteristics, managing the battery more scientifically and efficiently, and providing a basis for electric vehicle power management.

Reference address:Battery charging and discharging monitoring system based on MATLAB

Previous article:Design of a Single-stage Long Delay Circuit
Next article:Waveform Conversion and Circuit Implementation of Narrowband Remote Control Signal

Latest Power Management Articles
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号