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.
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.
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.
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
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
- [April 23 | Suzhou] High-speed digital and optical communication test seminar invites you to meet
- Selection of power supply decoupling capacitors
- 【Anxinke NB-IoT Development Board EC-01F-Kit】3. Serial port networking test
- STM32 DCMI driver OV2640 project source code
- Embedded USB driver-free device communication method based on WinUSB
- Generate random 0,1 signal
- Problems using Saber to simulate SPWM driving H-bridge via 2110
- Espressif ESP32-Korvo Audio Development Board Review Summary
- STM32mini MCU external clock method high-precision frequency capture
- TI DSP Bit Field and Register-File Struc...