Single chip microcomputer and USB interface to realize the control system of power compensation device

Publisher:导航灯Latest update time:2011-09-20 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In some special industrial occasions, it is sometimes necessary to continuously collect and store sensor signals in real time, and then play the data back to the PC for analysis and processing after a certain period of time. In the case of harsh working environment, the solution of using high-performance microcontrollers and industrial-grade large-capacity FLASH memory is probably the most appropriate choice. CYGNAL's C8051F320 SOC is a high-performance microcontroller with an 8051 core, and its operating speed is 12 times that of ordinary 8051.

This article presents a data acquisition and storage circuit for monitoring the operation status of a large photovoltaic system . Since it is made using surface mount technology, the width of the entire circuit board is only 18 mm, which is as convenient as using a USB flash drive.

Acquisition circuit hardware part

Circuit hardware structure

This system uses CYGNAL's C8051F320 chip and ATMEL's AT45DB321C memory chip as the main control and storage chips. Figure 1 is the acquisition and storage system block diagram of the signal acquisition system.

Block diagram of USB-based data acquisition and storage system

Figure 1 Block diagram of USB-based data acquisition and storage system

As can be seen from Figure 1, during the acquisition process, the sensor's input analog signal is amplified by a variable gain amplifier and sent to the C8051F320, where it is converted into a digital signal by the ADC. There are eight 45DB321C chips outside the microcontroller to form a 32MB Data flash memory. The collected data is continuously transmitted to the 45DB321C chip through the SPI interface for storage.

Compared with other chip models, C8051F320 has a USB interface. The USB function control module in the chip complies with the USB2.0 specification, can run at full speed or low speed, and has a 1KB USB cache, integrated transceiver, and no external resistors are required. It can be plug-and-play with a PC. When data is needed, the acquisition storage circuit can be retrieved from the site and played back to the PC through the USB interface, and waveform display and data analysis and processing can be performed on the LabVEIW platform.

Hardware interface between 8051F320 and 45DB321C

In the system, C8051F320 and 45DB321CI use SPI single master and multiple slaves to communicate. Pin NSS is used as the slave select line to select the memory chip, and low level is effective; SCK is used as the synchronous clock signal for the serial peripheral interface to send and receive data; RDY/BUZ is used as the signal line to determine whether the device is not busy or ready to receive new instructions; SO and SI are used as data transmission lines.

This system design considers using 8 45DB321C chips, with a maximum capacity of 32MB, and connects to the CS end of each 45DB321C through chip selects CS1~CS8. The clock SCK is only valid for the selected 45DB321. In addition to providing sufficient storage space, the design of this system using multiple Flash chips also solves a key problem, that is, drawing on the idea of ​​RAID technology in the hard disk field, a basic parallel acceleration is achieved by sequentially operating a group of 4 Flash chips, solving the problem of slow Flash write speed and greatly improving storage performance.

The specific circuit is shown in Figure 2, where the SPI of the eight memories is cascaded and only one is drawn, and their respective CS chip select signals are decoded by 74HC138.

Interface circuit between single chip microcomputer and FLASH memory

Figure 2 Interface circuit between MCU and FLASH memory

Acquisition circuit program software

The program of the acquisition circuit refers to the program solidified in C8051F320, which is written in C language and consists of four parts: main program module, ADC data acquisition, Flash data storage and USB communication.

Main program and ADC data acquisition

The main program mainly completes system initialization status indication operation control and parameter setting, starts A/D conversion, etc.

The ADC data acquisition program converts the analog signal from the sensor into a digital signal. In this system, the ADC conversion is triggered by the automatic overflow of Timer2, and the acquisition rate can be set in advance by the host computer. [page]

Flash Data Storage Program

The communication between the C8051F320 chip and the Flash memory uses the SPI interface, and the data transmission rate is 12MHz (bit/second). In this design, the C8051F320 works in the SPI master mode, and the data transmission of the SPI bus will be initiated by the C8051F320. First, configure the SPI-related SFR SPI0CFG register and SPI0CN register to make it work in the 3-wire master mode 12MHz. When communicating, first use the GPIO pin to select the corresponding Flash slave device, and then read the SPIDAT to perform read and write operations. When using the Flash chip for read and write operations, you must first determine the status of the Flash memory. You can write the D7H command and read the status register to determine whether the device is Ready or in Bus

After the status is determined, the relevant read, write and erase operations can be performed according to the command format in the data sheet.

USB Communication Program

Firmware programming is the main work in the USB device development process. The main task of the firmware is to initialize the microcontroller and peripherals, send USB requests, and respond to the host's standard device requests. Complete various data exchange requests according to the functional classification of the device. Initialization programming mainly completes the initialization of the USB controller, endpoint initialization, cross switch and I/O port initialization, system clock setting, and controller enablement. After initialization, the USB device can be inserted into the host at any time, and the host will follow the USB protocol to identify and initialize the device. After the host recognizes the device, it configures the device, calls the corresponding driver, and performs related communication operations with the host computer software.

Silicon lab provides a USBXpress development kit. By using the USBXpress library, the development of USB firmware programs and PC-side drivers is greatly simplified. USBXpress implements the application program interface (API) on the microcontroller side through a series of functions. These functions encapsulate the details of the USB protocol, so that program developers do not need to understand too many details of USB to use USB for data communication (see Figure 3).

USB communication between microcontroller and PC

Figure 3 USB communication between MCU and PC

This system mainly uses the four functions of initialization, reading, writing and interruption:

Initialization function USB_Init(0,0xEA61,NULL,NULL,Serial,250,0x80,0x100); block write function Block_Write(); block read function Block_Read(); USB interrupt enable function.

All USB processing procedures are completed through the USB interrupt service program. After entering the USB interrupt, the program calls the Get_Interrupt_Source() function to obtain the entry reason of the USB interrupt. Then, according to different entry conditions, corresponding processing is performed. For example, after receiving data, the corresponding buffer content is read into the memory; when receiving the initialization command, the various state parameters in the microcontroller are reset. The USB communication flow chart is shown in Figure 4.

USB communication flow chart

Figure 4 USB communication flow chart

PC software program

The computer-side software program consists of two parts: USB driver and user application.

USB Drivers

A USB driver is a software component that encapsulates the functions of an application program to access a hardware device. Some devices have the same properties, and by grouping them into a set of standard categories, a device class specification can be defined as the host driver framework for this type of device. Device class drivers use similar functions to handle communications between different devices, so that the development of device class drivers can be independent of device manufacturers.

The USB driver model is generally divided into five layers (see Figure 5).

USB Driver Model

Figure 5 USB driver model

If the client wants to read data from the device, it will call an application program interface API, such as OpenFile, which is implemented by SiUSBXp.dll. The bus driver controls access to all devices on the bus.

In this system, the tool used to develop the USB device driver is USBXpress Development Kit. The main functions are as follows:

S

I_Open() function; SI_Close() function; SI_Read function; SI_Write() function; SI_GetNumDevices() function; SI_CheckRXQueue() function. [page]

User Application

In this system, the application is written in NI's LabVIEW software, and the graphical C language is used for software development to achieve data display, analysis functions that meet different needs, and parameter settings for data acquisition hardware (see Figure 6).

Playback data waveform display interface

Figure 6 Playback data waveform display interface

Conclusion

The acquisition and storage circuit based on the C8051F320 USB interface closely combines computer technology with traditional signal acquisition technology, giving full play to the advantages of PC and single-chip microcomputer to realize the acquisition, storage, display and processing of sensor signals. With the communication function of the USB interface, the complexity of the data transmission system is reduced.

Keywords:MCU Reference address:Single chip microcomputer and USB interface to realize the control system of power compensation device

Previous article:Design of Oscilloscope Monitoring Program Based on C8051F020
Next article:Design of portable multifunctional medical examination meter based on MXT8051

Recommended ReadingLatest update time:2024-11-16 16:00

Serial communication example of 51 single chip microcomputer
Among them, fOSC is the clock frequency of the microcontroller; the baud rate refers to the number of bits sent (or received) per second by the serial port. SM2: Multi-machine communication control bit. This is only used for multi-machine communication in mode 2 and mode 3. The transmitter SM2 = 1 (program control s
[Microcontroller]
Serial communication example of 51 single chip microcomputer
Parallel operation of 1602 LCD panel based on 51 single chip microcomputer
The TX-1C board operates the 1602 LCD in parallel mode. Pins 1 and 2 of the LCD are gnd and vcc. Pin 3 is the contrast adjustment. Pin 4 is the data/command selection terminal RS. Pin 5 is the read/write selection terminal R/W. We only write and do not read this time, so it is directly grounded. Pin 6 is the read/writ
[Microcontroller]
Parallel operation of 1602 LCD panel based on 51 single chip microcomputer
SWIM mode pin multiplexing of stm8 microcontroller
SWIM mode After a power-on reset, SWIM resets and enters OFF mode. 1. OFF: The default state of power-on reset. At this time, the SWIM pin cannot be used as an I/O port. 2. I/O: The SWIM pin can be set as a normal I/O port by setting the SWD bit in the global configuration register (CFG_GCR). Once the system is reset,
[Microcontroller]
SWIM mode pin multiplexing of stm8 microcontroller
ATMEGA16 microcontroller keyboard and display circuit
The input and display circuit uses 4 buttons and function switching to complete the setting of output voltage and display switching. The display part uses a common anode digital tube for dynamic display, as shown in the figure. The single-chip microcomputer ATMEGA16 uses an internal 8 MHz crystal oscillator. Figure
[Microcontroller]
ATMEGA16 microcontroller keyboard and display circuit
51 MCU Series Knowledge 16--HD7279 (2)
Control instruction The control instructions of HD7279 are divided into two categories: pure instructions and instructions with data. Pure instructions 1. Reset (clear) instruction When HD7279 receives this command, it clears all displays, and all the set character blanking, blinking and other properties are a
[Microcontroller]
51 MCU Series Knowledge 16--HD7279 (2)
MCU SPI communication interface
UART, I2C and SPI are the three most commonly used communication protocols in microcontroller systems. We have already learned the UART and I2C communication protocols before. In this lesson, we will learn the remaining SPI communication protocol. SPI is the abbreviation of Serial Peripheral Interface. As the name imp
[Microcontroller]
MCU SPI communication interface
Implementation of Simple Timer with 51 Single Chip Microcomputer
Preface I was bored and didn't want to review even though the final exam was approaching. Suddenly a friend asked me this Use a single-chip microcomputer to control two LED digits, using static link, requiring the two digital tubes to display 00~99 counts, with an interval of 1s (interrupt mode). Design the circuit
[Microcontroller]
Implementation of Simple Timer with 51 Single Chip Microcomputer
Knowledge is required for microcontroller learning
In fact, electronic engineers put a bunch of devices together, inject ideas (programs), complete the functions that these devices cannot complete when separated, and make a finished product. The higher the skills required, the more complex the functions, the lower the cost, and the greater the demand for the correspon
[Microcontroller]
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
Guess you like
    502 Bad Gateway

    502 Bad Gateway


    openresty

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号