Welcome: Hunan Intelligent Applications Tecgnology CO.,ltd.-HNIAT.com
Language: Chinese ∷  English

Smart test

Research and Development of Virtual Experimental Instrument Based on Computer Sound Card

Virtual instrument (Virtual Intrument) technology is an important direction of measurement in the field of measurement and control. It is a brand-new concept instrument produced by the in-depth combination of computer technology and instrument technology. It is a major breakthrough in the concept of traditional instruments. In order to meet the needs of universities and scientific research institutions for some experimental equipment, it has become a trend to develop some virtual instruments under low-cost conditions. Set up a virtual oscilloscope as an example to introduce how to develop a virtual experimental instrument.
    1 Look at the sound card from the point of view of data collection
    From the point of view of data acquisition, the sound card is a data acquisition card in the audio range, and an important way for the computer to connect with the external analog environment. 
    1.1 The working principle of the sound card
    The working principle of the sound card is actually very simple, its working flow chart is shown as in Fig. 1. We know that both microphones and speakers use analog signals, and all the computer can handle are digital signals. The function of the sound card is to realize the conversion between the two. From the structural point of view, the sound card can be divided into two parts: the analog-to-digital conversion circuit and the digital-to-analog conversion circuit. The analog-to-digital conversion circuit is responsible for converting the analog sound signals collected by the microphone and other sound input devices into digital signals that can be processed by the computer; The conversion circuit is responsible for converting the digital sound signal used by the computer into an analog signal that can be used by devices such as speakers. 
    2 The main technical parameters of the sound card
    (1) The number of bits sampled.
    The number of sampling bits can be understood as the resolution of the sound card processing sound. The larger the value, the higher the resolution, and the more realistic the sound recorded and played back. The bit of the sound card refers to the binary digits of the digital sound signal used by the sound card when collecting and playing sound files. It objectively reflects the accuracy of the digital sound signal's description of the input sound signal. For example, 8 bits means 28=256; 16 bits means 216=64000. Comparing a piece of the same music information, a 16-bit sound card can divide it into 64,000 precision units for processing, while an 8-bit sound card can only process 256 precision units, so the final sampling effect is naturally incomparable.
    (2) Sampling frequency.
    Currently, the sampling frequency of the sound card is 44.1kHz. A few reach 48kHz. For civilian sound cards, the sampling frequency is generally set to 4 levels, which are 44.1kHz, 22.05kHz, 11.025kHz and 8kHz. 22.05kHz can only reach the sound quality of FM broadcast; 44.1kHz is the theoretical limit of CD sound quality, and 48kHz is better. For audio signals in the 20kHz range, the sampling frequency is only 48kHz. Although there is no problem in theory, it seems that there is not much margin. The major limitation of using a sound card is that it does not allow users to set the sampling frequency at will under the sampling frequency, but can only be divided into 4 settings. Although this can reduce manufacturing costs, it is inconvenient to use. It is basically impossible for users to control full-period sampling, and can only compensate for the problems caused by non-full-period sampling through signal processing.
    (3) Buffer.
    Unlike general data acquisition cards, the D/A and A/D tasks faced by sound cards are usually continuous. In order to better accomplish a certain task under a concise structure, the design of the sound card buffer has its own unique features. In order to save CPU resources, the computer's CPU does not respond to interrupts every time the sound card A/D or D/A ends, but uses a buffer mode of work. In this working mode, both A/D and D/A of the sound card operate on a certain buffer. Take the A/D conversion of input sound as an example. After each conversion, the sound card control chip stores the data in the buffer. When the buffer is full, it sends an interrupt to the CPU. After the CPU responds to the interrupt, the data in the buffer is restored. Read all away. The data transmission rate of the computer bus is very high, and the time used to read the buffer data is extremely short, which will not affect the continuity of the A/D conversion. The working mode of the buffer greatly reduces the frequency of the CPU responding to interrupts and saves system resources. The A/D conversion when the sound card outputs sound is similar.
    The default value of the buffer length used by general sound cards is 8KB (8192 bytes). This is because for the X86 series processors, in the protected mode (under the working mode of the CPU used by Windows and other systems), the memory is divided into many pages in units of 8KB, and any access to the memory is carried out on a page-by-page basis. It is guaranteed that the speed of reading and writing 8KB memory buffers is fast enough, and generally will not be interrupted by other external events. Setting a buffer with a size of 8192 bytes or an integer multiple (for example, 32768 bytes) can better ensure the coordination between the sound card and the CPU.
    (4) No reference voltage.
    The sound card does not provide a reference voltage, so whether it is A/D or D/A in use, users need to refer to the reference voltage for calibration.
    (5) Sound card frequency range and frequency response.
    The frequency response of a certain sound card is shown in Figure 2. It can be seen that the curve between 200Hz and 5kHz is relatively flat, and the rest of the signal has more attenuation. In the appropriate frequency range, you can use a sound card to replace the expensive data acquisition card to work. 
    2 Using G language LabVIEW to build a virtual experimental instrument
    The virtual instrument is developed on the basis of the slogan "Software is the instrument" put forward by National Instruments Corp. (National Instruments Corp. for short) in 1986. With the support of the acquisition hardware, the functions of traditional instruments can be realized and expanded through software design according to the needs of the test task. The traditional desktop instrument is a closed structure designed and defined by the manufacturer, with a fixed input/output interface and an instrument operation panel. Each instrument can only implement a specific type of test function and provide it to the user in a definite way. The emergence of virtual instruments breaks the traditional instrument model defined by manufacturers and cannot be changed by users. It allows users to design their own instrument system according to their own requirements, and can change or increase or decrease the functions of the instrument by modifying the software, which truly reflects The new concept of "software is instrument".
    (1) G language LabVIEW introduces the module of sound card.
    LabVIEW provides a series of sound card-related functions written using Windows low-level functions. These functions are concentrated under Sound VI. Because it uses Windows low-level functions to directly deal with the sound card driver, the package level is low, the speed is fast, and it can be accessed. It has great flexibility to collect data at any position in the buffer and can meet the needs of real-time uninterrupted collection.
    The Sound Input sub-template (Functions Palette→Graphics&Sound→Sound→Sound Input) in the LabVIEW function library provides sound card functions, which can collect external analog signals through the sound card.
    (2) The establishment of virtual oscilloscope based on sound card.
    Using LabVIEW to build a sound card-based virtual oscilloscope, the overall idea is to add each input node in a While loop to display the collected sound waveform, and add a number of attribute nodes inside to add various additional The function is realized. The flowchart is shown in Figure 3.
    The design of the virtual oscilloscope software is to divide the entire software into several modules, and then group them into a whole. Respectively data collection, storage, display, processing, etc.
    The data acquisition module is the hardware driver part of the virtual oscilloscope software. Here, the sound card function in LabVIEW is mainly used to complete the hardware parameter setting of the sound card, start the sound card to collect data, wait for the message that the sampling data buffer is full, and notify the sound card to stop collecting and other tasks.
    The waveform display module uses waveform operation functions, mainly the Build Waveform function. Build Waveform function. Create or modify existing waveforms. By default, the function has only waveform and t0 input terminals. Drag the lower edge of the function downwards to add dt, Y and attributes input terminals. Use the operating tool to click on the terminal to pop up a shortcut menu for element selection. If the waveform terminal is not connected, Build Waveform creates new waveform data according to the input parameters and returns it in the output terminal. In this design, only three input terminals t0, dt, and Y are used. Among them, t0 is the starting time of the waveform, dt is the time interval or duration between the waveform data points, and Y is the data value that contains the waveform. Here, the start time is set to 0, but because the data format does not match, a data format conversion function to time stamp is added to convert a numerical value into a time value. The dt value is taken from the reciprocal of the sampling in the SI Config format, and the method of obtaining the reciprocal uses the reciprocal function. The Y value comes from the stereo 16-bit output terminal of SI Read.
    Due to limited space, each module cannot be introduced in detail. The following is a built oscilloscope. 
    3 Comparison of virtual oscilloscope and traditional oscilloscope
    The advantage of a virtual oscilloscope is that users can define their own dedicated instrument system, with flexible functions and easy construction, so the application is extremely wide. Especially in the fields of scientific research, development, measurement, inspection, metrology, etc., it is a rare good tool. The virtual oscilloscope technology is advanced, which is in line with the internationally popular "hardware software" development trend. It is powerful and can realize all the functions of a traditional oscilloscope, but also has functions that traditional oscilloscopes do not have, such as real-time waveform storage, data storage, and remote data acquisition. It is flexible in operation, fully graphical interface, simple in style, and conforms to the usage habits of traditional equipment. Users can quickly master the operating procedures without training; it is easy to integrate and can work with high-speed data acquisition equipment. 
    4 Conclusion
    The computer sound card is used to replace the special data acquisition card for data sampling and output in the audio range. The virtual instrument constructed on this basis has the advantages of low cost, good compatibility, versatility and flexibility. Students can install the user program on their own computer and have their own oscilloscope and other instruments without increasing hardware investment. Using the same principle, users can develop various experimental instruments such as spectrum analyzers and signal generators.

CONTACT US

Contact: Manager Xu

Phone: 13907330718

Tel: 0731-22222718

Email: hniatcom@163.com

Add: Room 603, 6th Floor, Shifting Room, No. 2, Orbit Zhigu, No. 79 Liancheng Road, Shifeng District, Zhuzhou City, Hunan Province

Scan the qr codeClose
the qr code