1. Introduction
For school teaching experiments and certain specific needs, the analog and digital oscilloscopes currently on the market may not be suitable. They are expensive, large in size, and many professional functions are not practical. Now that computers have become quite popular, using computers and additional data acquisition modules to realize a flexible and convenient virtual oscilloscope can meet most work, learning and development needs, and can achieve quite complex signal processing functions through low-cost hardware and software upgrades. It can realize a flexible configuration of intelligent instrument combinations at a low cost and small size; it can be combined with a portable computer to form a portable inspection and maintenance workstation. At present, there are data acquisition devices for computer parallel port communication, but the application of USB is becoming more and more extensive and in-depth. If the USB function is integrated into it, a higher data transmission rate and more convenient use can be achieved, which better reflects the performance of the virtual instrument.
2. Hardware Design
The data acquisition unit of this virtual oscilloscope consists of the following functional modules: front-end signal conversion module, high-speed analog-to-digital conversion module, high-speed data buffer module, single-chip control module, USB interface module and power module. There are mature solutions for front-end signal conversion and high-speed data acquisition, and they can be designed according to the required indicators, such as sampling rate, range control, sampling depth, etc. Here we mainly discuss the development of the USB interface part.
The development of USB interface has always been a headache. Although many designers yearn for the advantages of USB interface such as high-speed transmission, self-power supply and plug-and-play, it is difficult to overcome the obstacles of protocol firmware development and driver development. In this solution, the author selected a USB bus interface chip that does not require the development of protocol firmware and driver.
The CH371 launched by Nanjing Qinheng Company (www.winchiphead.com) is a universal interface chip for USB bus. It shields all protocols in USB communication by hardware logic and provides end-to-end connection between computer application layer and local controller. Based on CH371, designers do not need to understand any USB protocols, firmware programs and drivers, and can easily upgrade the original parallel and serial port products to USB interface, enjoying the advantages brought by USB interface with lower risk and cost.
When in use, on the local side, CH371 has an 8-bit data bus and read, write, chip select control lines and interrupt output, which can be easily connected to the system bus of controllers such as DSP and MCU just like operating general peripheral chips; on the computer side, the supporting software of CH371 includes universal drivers and application software packages, which provide a simple and easy-to-use operation interface. Communication with the local microcontroller is as simple as reading and writing files in the hard disk. Developers can use high-level languages such as VB, VC, C++Builder for development. In general, when designing USB products based on CH371, it is not necessary to consider USB communication protocols, firmware programs, drivers, configuration processes, and underlying data transmission processes. The work that designers have to do is the same as designing parallel and serial port products, including two things: one is to send data transmission requests from the application layer of the computer and receive responses; the other is to respond when the controller of the USB product is notified of a data transmission request.
At the same time, CH371 not only provides transparent USB protocol, but also provides direct management of I2C devices, direct reading and writing of 16 addresses, as well as reset, watchdog and other functions. The local end can even complete simple control functions without using a single-chip microcomputer. Therefore, it has strong functional adaptability, can meet the needs of different occasions, and effectively reduce system costs.
The SOP28 package product is used in this system, and its pin definition is as follows:
According to different working modes, the interface types of the chip can be the following: passive parallel interface, I2C master interface, master control mode interface. Among them, the passive parallel interface is the most commonly used mode, which provides the connection between the microcontroller and the computer, and CH371 is a passive peripheral of the microcontroller; the I2C master interface is that CH371 directly reads and writes an EEPROM device (such as 24C04, etc.) without passing through the microcontroller under the control of the computer program, and is often used for product information recording of USB peripherals; the master control mode interface does not use the microcontroller, and the computer program directly controls the 8-bit data reading and writing of 16 addresses provided by CH371 or more than a dozen IO lines. This method is mainly used to complete relatively simple external control tasks. These interface modes are not completely opposite and can be flexibly configured as needed. In this virtual oscilloscope, it is used as a peripheral device of the microcontroller, and A3~A0 is used in the master control mode to control four LEDs by the computer.
The microcontroller controls CH371 by operating the 16 internal registers. There are two ways to define the addresses of these 16 registers. One is that after power-on reset, the default is the direct address mode, and the four pins A3~A0 are the register addresses. This method is relatively simple, but it requires more IO port resources of the microcontroller; the other is that when CH371 detects the rising edge signal on the ALE pin, it switches to the multiplexed address mode. The register address is controlled by D3~D0 of the data bus, and the jump of ALE is used to determine whether it is a register operation or data reading and writing. In this design, since the large-capacity data buffer needs to use 74373 as an address latch, even if the direct address method is used, it does not need to occupy more microcontroller resources, but in order to save A3~A0 to drive the LED, the multiplexed address method is selected. [page]
According to the system requirements, we designed the hardware as follows.
The USB interface provides data exchange and power supply (after appropriate conversion, it can be used for high-speed AD). CH371 works at a frequency doubling under the 12M crystal oscillator, provides a watchdog reset output function while providing an interface with the microcontroller, and the I2C master control function is not used. A3~A0 can be controlled by the computer to drive 4 LEDs as working display signals. The P1 port group of the microcontroller 89C52 is used to control the data acquisition module, including range conversion control, AD trigger signal, and data acquisition overflow signal; the cache 62256 stores the results of high-speed AD acquisition through low-power CPLD control. The microcontroller reads out the data regularly and transmits it to the computer's data display and analysis software through CH371 to realize the virtual oscilloscope function. The schematic diagram of the microcontroller, CH371 and RAM is as follows:
Figure 3 Schematic diagram of MCU, CH371 and RAM
3. Software Design
MCU software:
The MCU software mainly completes the two functions of data acquisition control and data reporting. The data acquisition control controls the data acquisition module according to the gain, time base, trigger and other parameters set by the computer software. The computer needs to send a small amount of control information to the MCU. The data reporting function requires the MCU to transmit all the data of a collection cycle in the cache to the computer software, which is a large-scale data transmission. We focus on the communication between the MCU and the computer.
The communication between the microcontroller and the computer is achieved by operating the registers of CH371. For details on the definition of its registers, please refer to the data manual.
It should be noted in the application that the MCU receiving buffer provided by CH371 is 8 bytes, and the computer download data exceeding 8 bytes is segmented; and the MCU sending buffer is also 8 bytes, and the upload data exceeding 8 bytes needs to be uploaded multiple times. In addition, the interrupt of CH371 includes upload and reception success, and the specific situation after the interrupt occurs needs to be identified by the transmission status register; at the same time, the interrupt level is monostable, and the interrupt signal jumps after an event occurs, but it only maintains a short pulse before recovery, which is for the purpose of coordinating with processors of different speeds.
The main function subroutine examples of USB communication between the MCU and the computer are as follows: (Please add the address definition of the corresponding register of CH371 when using it)
file://********** CH371 initialization program******************************
void ch371_init()
{
CH371_INT_SET=0; file://CH371 interrupt data setting register address offset
CH371_LENGTH=0X0F; file://Set the upload data length register to 15, indicating that there is no data to upload temporarily
save_length=0; file://Save the download data length
IT0=1; file://External signal is falling edge trigger
IE0=0; file://Clear interrupt flag
PX0=1; file://Set high priority
EX0=1; file://Enable interrupt
}
file://***********Upload data subroutine********************************
void ch371_upload(unsigned char len) file://Parameter incoming data length
{
unsigned char i;
unsigned char *up_buf;
unsigned char *ch371_buf;
if(len!=0)
{
up_buf=&ret_buffer; file://point to the data address
ch371_buf=&CH371_BUFFER; file://point to the data buffer
for(i=0;i{
*ch371_buf=*up_buf; file://write to the upload data buffer
ch371_buf++; up_buf++;
}
}
CH371_LENGTH=len; file://write the length of this data
}
file://********Interrupt subroutine using interrupt 0 register group 2********
void ch371_inter() interrupt 0 using 2{
unsigned char *down_buf;
unsigned char *ch371_buf;
unsigned char i;
IE0=0; file://clear interrupt flag
if( (CH371_STATUS&0x01) ==0 ){
file://read the status information register and judge the data transmission status
save_length=CH371_LENGTH; file://keep the length of the downloaded data
down_buf=&save_buffer;
ch371_buf=&CH371_BUFFER;
for(i=0;ifile://judge the length of the downloaded data and process it
{
*down_buf=*ch371_buf; file://read one byte of downloaded data
down_buf++; ch371_buf++;
}
}
else CH371_LENGTH=0x0f; file://set the upload data length register to 15
}[page]
Computer software:
The main function of the computer software is to simulate the interface of an oscilloscope, realize data display and analysis functions that meet different needs, and complete the parameter setting of the data acquisition hardware. Basic functions have been realized in this design, and the interface of the virtual oscilloscope is as shown below. After further development, automatic range conversion, in-depth data analysis (such as waveform measurement, spectrum analysis, etc.) can be realized, and even the waveform generator, logic analyzer, sweep frequency analyzer, network analyzer and other functions can be realized in combination with hardware upgrades.
Figure 4 Virtual instrument computer software panel diagram
The development of USB communication on the computer side does not require the understanding of the USB underlying driver, and the chip manufacturer has encapsulated the API functions for functional applications in the form of dynamic link libraries, which developers can call in a variety of high-level languages. The API functions provided by the CH371 dynamic link library mainly include: device management API, data transmission API, interrupt query API, I2C operation API and direct control API.
Among them, the device management API is not needed for general product development; the data transmission API is the most important and commonly used set of functions, which provides a variety of data transmission modes; the interrupt query API is generally used in the case of USB devices using interrupt transmission, which we do not use here; the I2C operation API is used to read and write I2C devices controlled by CH371, which is generally used to store product information, which we do not use here; the direct control API is used for CH371 to directly input and output signals, including settings, input and output. We use this set of APIs to control the LED.
In actual applications, the author uses VB6 as the development platform for computer-side application software. First, the driver and dynamic link library provided by Qinheng Company must be copied to the computer, and then the access entry and function definition entry of the dynamic link library must be added to the VB6 project, that is, the module function module in the provided VB6 example program can be added to your own project. At this time, the communication programming of the USB device is almost the same as accessing files in the local hard disk. The specific difference can be solved by analyzing the syntax of the example program. The following are the relevant programs for the computer to receive and send data.
Option Explicit \' Variable Definition
Dim myReq As DEMO_REQ
Dim mOpen As Integer
Private Sub Form_Load() \' Window loading event
Dim mLength As Long
mIndex = 0
mOpen = CH371OpenDevice(mIndex) \' Open the device when the form is loaded
If mOpen = -1 Then
MsgBox "Unable to open CH371 device" \' Prompt for loading failure
End If
myReq.mCommand = &HFF \' User defined command
myReq.mBuffer(0) = &H11 \' User defined data
myReq.mBuffer(1) = &H22 \' User defined data
mLength = Len(myReq)
CH371WriteData(mIndex, myReq, mLength) \' Send command data via CH371
...
CH371ReadData(mIndex, myReq, mLength) \' Receive response data via CH371
...
End Sub
IV. Conclusion
The virtual oscilloscope with USB interface designed by CH371 has completed the verification of basic functions and is being improved in the later stage. It can also launch a series of products of different levels for various applications. Practice shows that it has good technical performance, powerful functions, small size, easy to use and low price, and is a powerful assistant for electronic enthusiasts and developers.
Previous article:Software Design of Four-channel Multi-parameter Test System Based on LabVIEW
Next article:Design of thermal expansion instrument test system based on virtual instrument
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- 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
- EEWORLD University Hall----[High Precision Laboratory] Interface: 9 USB
- Analyzing the basic steps of FPGA power supply design
- [RVB2601 Creative Application Development] Audio Playback
- MSP430F5529&LCD1602 Program
- Bluetooth Direction Finding Technology Overview
- How to automatically fan out BGA in Kicad
- Crazy Shell AI open source drone flight control firmware burning
- Problems affecting IC card reading distance
- How to design hollow fonts
- Three considerations for selecting Ethernet for harsh industrial environments