Application solution of using SD card mobile memory to realize power consumption recorder

Publisher:pi26Latest update time:2023-04-07 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

As a new type of mobile storage device, SD cards are popular for their small size, fast speed, shock resistance and strong versatility. Using SD cards as storage media to save the company's power consumption parameters can effectively improve the reliability of data storage. The multi-parameter power consumption recorder is designed using an SD card combined with the ARM processor LPC2l48 to store various types of power consumption data collected on site into the SD card in the form of files, and can easily exchange data with PCs and other host computers. This meets the requirements for on-site data collection and indoor data analysis, and is especially suitable for long-term, large-capacity data collection occasions.


1. System hardware design

The hardware circuit of the power consumption recorder is shown in Figure 1. The ARM core processor LPC2l48 is the core of the entire system. Its operating frequency is as high as 60 MHz. It has built-in 5l2 KB flash memory and 16 KB SRAM, and has an SPI bus and two channels. A/D converter, real-time clock and other on-chip functional components. The voltage and current signals in the power grid are converted into AC signals of about 1V through high-precision transformers. At the same time, the recorder is isolated from strong electricity. The isolated AC signals are shaped and filtered and then sent to the two internal A/C signals of LPC2148. D converter, completes the measurement of voltage, current, power factor and other parameters. The LPC2148 measures the power consumption according to the peak and trough periods according to the time provided by the internal real-time clock, and calculates the instantaneous power, hourly power, and total power. demand and other parameters. The recorder uses a dot matrix graphic LCD as the local display interface, which can display the collected data in text mode or graphically display the collected data curve. The external matrix keyboard is used to set the data collection interval, collection time, etc. The system starts data collection according to user settings and automatically stores the collected data into the SD card memory.

Application solution of using SD card mobile memory to realize power consumption recorder

The SD card can work in two modes: SD and SPI. In the sPI mode, only 4 signal lines are needed to complete data communication. The operation is simple and convenient, and it is easy to interface with the SPI bus of LPC2148. The interface pin description is shown in Table 1. listed. As an SPI device, the SPI channel of the SD card consists of the following 4 signals: CS (chip select), SCK (clock), Dateln (data signal from host to card) and DateOut (data signal from card to host). CS is the chip select signal line of the SD card and must remain active low during the entire SPI operation; the SCK clock is used for synchronization; Dateln not only transmits data but also sends commands; DateOut not only transmits data, but also sends a response signal.

2. SD card reading and writing implementation in SPI mode

SPI is a universal synchronous serial interface bus with a word length of 8 bits. The SPI protocol works in a master-slave manner, usually with one master device and one (or more) slave devices. During operation, the master device controls data transmission by providing synchronous clock and slave device enable signals. Each time the host device starts transmitting data, it must first set the chip select signal low to activate the SD card and bring it into working condition. When the SD card works in SPI mode, the selected card always responds to commands from the main device. When the card encounters an error, an error response will be returned instead of the expected data.


2.1 SD card initialization

The SD card must be initialized before reading and writing operations. This is a prerequisite to ensure that the SD card can perform normal data transmission in sPI mode. Due to the emergence of large-capacity SD cards, the SDI.x standard has been upgraded to SD2.0. However, many electronic devices are unable to drive large-capacity SD cards. How to identify SDI. x and SD2.0 are particularly important. After the SD card is powered on, it enters the SD working mode by default. You should wait for at least 74 clock cycles, set the chip select signal low, send the reset command CMD0, and then send the CMD8 command to the SD card after the SD card reset is completed. If the received response signal is 01H, it means SD2.0 card, otherwise it is SDI. x card SDI. The biggest difference between x and SD2 0 is the representation of the command address, SDI. The address unit of Figure 2 shows the initialization process of the SD card in sPI mode.

2.2 FAT32 file system

Before the SD card can save data, it must be formatted according to the regulations of a certain file system. The FAT32 file system is widely used in mobile storage devices because of its high compatibility. The FAT32 file system structure is divided into five parts: MBR area, DBR area, FAT area, EDT area, and DATA area.


The MBR area is also called the master boot record, followed by the 64 B disk partition table DPT.

The DBR area is the operating system boot record area, occupying sector 0 of the partition, totaling 512 B, and consists of jump instructions, end flags and other parts.

The FAT area stores the file allocation table, which corresponds to the cluster number of the data area, reflecting the usage of all clusters. The size of each entry unit determines the type of FAT. For example, the entry unit of FAT32 is 32 bits. FAT tables generally have one copy.

The EDT area stores the file directory table, located after each FAT table. EDT consists of 32-bit linear directory entries, recording the starting unit, attributes, etc. of each file (subdirectory) in the root directory.

The DATA area is the real data storage area, located after the EDT and occupies most of the space on the SD card.

When the SD card is formatted as a FAT32 partition, the file system plans the partition as a whole allocatable area to facilitate data storage. The SD card space is usually divided into units of a certain number of sectors. Such units are called clusters. The size of the cluster is 2n sectors (which is an integer). Each sector is 512 B. The maximum storage capacity of each cluster is The space is 32 KB.


3. System software design

System software includes SD card driver, LCD driver, A/D conversion driver, keyboard driver and various data processing programs. Due to space limitations, only the file system operations of the SD card are introduced here. The entire file system adopts a modular hierarchical structure, including file management and directory management modules, file allocation table management modules, SD cache modules, etc. These modules are built on the underlying driver, and the underlying driver mainly completes the transfer of certain files to the SD card. Reading and writing of sectors. The function of the file system is to perform correct file data operations in the SD card, which mainly includes: applying for new directory entries in the EDT and creating files; when writing new files, searching for unused clusters in the FAT table and storing the clusters The number is written into the starting cluster number position in the corresponding directory data structure of the file. When the file length is greater than one cluster, the next available cluster number needs to be filled in at the corresponding starting cluster number position in the FAT table until the last cluster number in the file. Cluster; when deleting a file, in addition to setting the corresponding flag of the corresponding directory entry in the EDT, F also modifies the FAT table and clears the cluster number position used by the file to 0, indicating that the cluster is currently not used, etc. The smallest unit when storing files in the FAT32 file system is a cluster. Even a small file will occupy a cluster. In order to save storage space, if a file with the same name exists when creating a file, you only need to append data to the original file with the same name. The file system is designed to provide users with various API functions, such as the create file function Lre-at_Fie O, open the file function Open_FIle O, write the file function Write File (), delete the file function Delete File (), etc., call these API functions can complete the functions required by users. Figure 3 shows the flow chart of creating a file in the SD card and writing file data to it.

Design and implementation of power consumption recorder based on SD card

Using SD card as a mobile memory for multi-parameter power consumption records, on-site power consumption data can be collected in real time and saved at high speed. Taking advantage of the good mobility of the SD card, data exchange with the computer can be easily realized to achieve the purpose of on-site data collection and indoor data analysis. You can also read the data in the SD card at any time through the recorder keyboard commands, and display it in real time in the form of text or curves on the LCD screen. As the performance of SD mobile storage continues to improve, its capacity becomes larger and larger, and its price becomes cheaper, multi-parameter power consumption recorders based on SD card mobile storage will be widely used.


Reference address:Application solution of using SD card mobile memory to realize power consumption recorder

Previous article:Design of robot human-machine interface based on PC104 embedded microcomputer and TMS320F2812
Next article:Design of intelligent fire and anti-theft alarm system

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号