USB interface application design based on NI-VISA and LabVIEW

Publisher:古通闲人Latest update time:2015-07-21 Source: dzscKeywords:NI-VISA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
introduction

USB (Universal Serial Bus) interface is a new interface technology used in the PC field in recent years. It is based on a single bus interface technology to meet the needs of various application fields; its plug-and-play, hot-swap support, easy expansion and other features greatly facilitate user use and have gradually become the development trend of modern data transmission.

The traditional steps to develop USB application systems are to first develop LJSB drivers using Windows DDK (Device Driver Development Kit) or third-party development tools (such as DriverSt LJdic), then write DLLs (Dynamic Link Libraries) using Visual C++, and finally call DLLs to develop applications. Obviously, this is difficult for people who are not familiar with Windows programming, not to mention that the development of USB drivers is very difficult. This article introduces a simple and fast method for developing USB interface application systems. It directly develops applications that can drive the user's USB system through NI-VISA in the LabVIEW environment, completely avoiding the complexity of developing USB drivers in the past and greatly shortening the development cycle.

1 Introduction to N1-VISA

NI-VISA (Virtual Instrument Software Architecture, hereinafter referred to as "VISA") is a high-level application programming interface developed by National Instruments NI (National Instrument) for communicating with various instrument buses. VISA bus 1/() software is a comprehensive software package that is not restricted by platform, bus and environment. It can be used to configure, program and debug USB, GPIB, serial port, VXI, PXI and Ethernet systems. VISA is the I/O interface software of the virtual instrument system. Based on the bottom-up structural model, VISA creates a unified form of I/O control function set. On the one hand, for beginners or designers of simple tasks, VISA provides a simple and easy-to-use control function set, which is quite simple in application form; on the other hand, for the builders of complex systems, VISA provides very powerful instrument control functions and resource management.

2 LabVIEW and its conditions for calling VISA

LabVIEW (Laboratory Virtual Instrument Engineering Workbench) is a programming language based on graphical programs developed by NI. Users write programs by creating and calling subroutines, making the created programs modular, and the programming is simple and intuitive. A LabVIEW program is divided into three parts: the front panel, the block diagram program, and the icon/wiring port. The front panel is used to simulate the front panel of a real instrument; the block diagram program uses graphical language to control the control objects on the front panel (divided into control quantities and indication quantities); the icon/wiring port is used to define the LabVlEW program as a subroutine, thereby realizing modular programming.

When performing USB communication, VISA provides two types of functions for LabVIEW to call: USB INSTR devices and USB RAW devices. USB INSTR devices are USB devices that comply with the USBTMC protocol and can be controlled by using USB INSTR class functions. There is no need to configure NI-VISA for communication. USB RAW devices refer to any USB devices other than instruments that clearly comply with the USBTMC specification. NI-VISA must be configured for communication.
(1) Steps to configure NI-VISA

①Use the Driver Development wizard to create an INF document;

②Install the INF file and install the USB device that uses the INF file

③ Use NI-VISA Interactive Control to test the device to confirm that the USB device has been installed correctly and obtain the property values ​​of the USB device.

For detailed procedures, please refer to the free document "Using NI-VISA to Control USB Devices" on the NI official website.

(2) VI subnodes in the LabVIEW template that work with NI-VISA

ViOpen, opens and specifies the connection of the device with VISA resource name.
ViProperty, the property subnode of the VISA device, can set the endpoint or transmission mode.
ViWrite, writes data to the device specified by VISA resource name.
ViRead, reads data from the device specified by VISA resource name.
ViClose, ends the device reading and writing and closes the connection with the specified device.

(3) USB RAW device read and write operation sequence

The read and write sequence of USB RAW devices is shown in Figure 1.

Taking a USB interface temperature acquisition system as an example, the following describes the design and implementation of a USB interface application system based on NI-VISA driver.

3 System Hardware Structure

The system is based on Philips' enhanced 80C51 microcontroller, as shown in Figure 2. This is a multi-point temperature acquisition system. The core device is the P89C52 with 8 KB non-volatile Flash program memory, which is fully compatible with the standard 80C51. The USB communication control chip uses Philips' PDIUSBD12 chip (abbreviated as "D12"). It is a relatively new dedicated USB communication control chip that complies with the USB1.1 version specification of the universal serial bus. It integrates a serial interface engine SIE, a 320-byte FIFO memory, a transceiver and a voltage regulator. The front-end temperature sensor uses the DS18B20 produced by Dallas. It is a one-line digital temperature sensor that directly outputs digital quantities to the microprocessor, which can save a lot of leads and signal conditioning circuits. There is a photolithographic ROM inside the DS18B20. This ROM stores a 64-bit serial number. It can be regarded as the address sequence code of the DS18B20, so multiple temperature sensors can be hung on one bus and occupy one I/O line of the microcontroller to realize the interface. On the premise of improving the I/O line driving capability of the microcontroller, the number of temperature points to be detected can be expanded arbitrarily in theory.

There are two ways to interface D12 with the microcontroller: multiple address/data bus mode and single address/data bus mode. The single address/data bus mode is selected here, so the ALE of D12 is connected to a low level, and the A0 pin is connected to the port P3.3 of P89C52X2. This port controls the command and data status of D12: A0=1, indicating that there is a command on the data bus; A0=0, indicating that there is data on the data bus. The data bus of D12 is directly connected to the P0 port, and the interrupt pin INT_N of D12 is connected to: INTO of P89C52X2. When one of the external interrupts of D12 is 1, INT_N outputs a low level, triggering the external interrupt of P89C52X2. Because the system does not use DMA, the DMACK_N pin of D12 is connected to a high level, and the EOT_N pin is connected to the +5V of USB through a resistor to correctly detect the USB connection; a pull-up resistor is added to the INT_N pin. Because D12 has an on-chip power-on reset circuit, the RESET_N pin is directly connected to the power pin VCC. The temperature sensor DS18B20 works in external power mode, and the DQ pin is directly connected to P1.O of P89C52X2.

[page]


3.1 System Working Principle
According to the USB protocol, any transmission is initiated by the host, and the foreground work of the MCU is to wait. The host PC must first send a token packet to the USB. When D12 receives the token packet, it sends an interrupt to the MCU, and the MCU enters the interrupt service program. First, read the interrupt register of D12, determine the type of the LJSB token packet, and then perform the corresponding operation. Therefore, the USB MCU program is mainly the writing of the interrupt service program. In the USB MCU program, the response to various token packets must be completed, mainly programming the port.

3.2 Software Design

The system firmware program is divided into two parts from the functional point of view, and the entire programming is completed in the Keil C environment.

(1) Temperature sensor DS18B20 reading program

The single-line communication function of DSL8B20 is realized by time-sharing. It has very strict timing requirements, and its operation must be carried out according to the protocol, that is, initialization → sending ROM operation command → sending memory operation command → data processing.

(2) Communication program between MCU and USB interface

This program uses endpoint 1 and endpoint 2 of D12 to transmit commands and data between the host computer and MCU P89C52. Endpoint 1 and endpoint 2 are set to mode 0 (asynchronous mode). Endpoint 1 transmits data in interrupt mode and response mode, while endpoint 2 transmits data in batch mode. Endpoint 1 receives the read command sent by the host computer, and endpoint 2 returns the read success data. 

The firmware program of the system is written in a hierarchical structure. It is a building block structure, as shown in Figure 3.

①Hardware abstraction layer: operates the I/O port, data bus and other hardware interfaces of the microcontroller.

②PDIUSBDl2 command interface: module subroutine set for operating D12 devices

 

③Interrupt service program: When D12 sends an interrupt request to the microcontroller, read the data transmitted by the D12 interrupt, set the event flag "EPPFIAGS" and the Setup package data buffer "CONROL_XFER" and transmit them to the main loop program.

④Standard device request handler: processes USB standard device requests.

⑤Manufacturer request handler: processes manufacturer requests added by users.

⑥ Main program: issue USB data transfer requests, handle bus events and call user-defined function subroutines

Design of host LabVIEW application driven by NI-VISA, NI-VISA uses version 3.2 and LabVIEW uses version 7.1.

The main framework of the entire application uses a WHILE loop to perform continuous queries. In the process of programming, an event-driven mechanism similar to that in Windows programs is adopted. LabVIEW provides such a structure - event structure. The generation of each message utilizes various interface controls and is given by the Case selection structure. The program structure diagram is shown in Figure 4.

In order to explain the USB operation sequence, the event structure in Figure 4 is used as a shortcut to develop the USB driver application.
In Figure 5, the USB RAW device communication uses endpoint 1 to receive the host computer operation command in interrupt transmission mode, and the protocol can be agreed upon by itself. Endpoint 2 sends temperature data back to the host computer in batch transmission mode. The endpoint number "130" is the decimal number corresponding to the hexadecimal number "0082", which indicates the batch input of endpoint 2; and the endpoint number "1" is the decimal number corresponding to the hexadecimal number "0001", which indicates the interrupt output of endpoint 1.

Because NI-VISA 3.2 does not support the USB attribute "interrupt out", in order to implement the interrupt output of USB endpoint 1, the USB attribute "bulk out pipe" and the "VI Write" node are combined here to implement the interrupt output of endpoint 1. From NI-VISA 3.3 onwards, the "interrupt out" attribute can be used directly to achieve this.

Conclusion

Practice has proved that the design of USB interface application system based on NI-VISA driver is very easy, with low development difficulty and low requirements for developers; the developed system is stable and reliable, and even people who are not familiar with Windows programming can develop USB application system. It provides another shortcut to develop USB driver application.

References:

[1]. 80C51 datasheet http://www.dzsc.com/datasheet/80C51_103447.html.
[2]. ROM datasheet http://www.dzsc.com/datasheet/ROM_1188413.html.
[3]. DS18B20 datasheet http://www.dzsc.com/datasheet/DS18B20_819975.html.
[4]. P89C52X2 datasheet http://www.dzsc.com/datasheet/P89C52X2_538908.html.

Keywords:NI-VISA Reference address:USB interface application design based on NI-VISA and LabVIEW

Previous article:Sound energy design based on LabVIEW development platform
Next article:Multi-channel instrument temperature measurement and control system based on LabVIEW

Recommended ReadingLatest update time:2024-11-16 13:38

Communication protocol test between battery management system and charger based on LabVIEW
With the rapid development of the electric vehicle industry in recent years, various standards related to electric vehicle technology have been introduced, including the "Communication Protocol between Off-board Conductive Chargers and Battery Management Systems for Electric Vehicles" (GB/T 27930-2011). This protocol
[Power Management]
Communication protocol test between battery management system and charger based on LabVIEW
Design and implement an electronic steering system for the aircraft's front landing gear using LabVIEW and PXI
  challenge:   Design and implementation of a test rig for the prototype of the electronic steering system for the nose landing gear of the Airbus A320 passenger aircraft .   solution:   We created a system based on NI LabVIEW software and PXI hardware, using a real-time operating system to quickly develop the
[Test Measurement]
Design and implement an electronic steering system for the aircraft's front landing gear using LabVIEW and PXI
Design of Calibration Software for Ground-Based Gamma Spectrometer Based on LabVIEW
  1 Introduction   Ground gamma spectroscopy is a nuclear geophysical method that uses a portable gamma spectrometer to directly determine the potassium, uranium, and thorium content in soil and rocks on site. It plays an important role in solving problems in the fields of earth science and environmental science . The
[Test Measurement]
Design of Calibration Software for Ground-Based Gamma Spectrometer Based on LabVIEW
Design of ECG signal acquisition and analysis based on LabVIEW
Biomedical electrical signals, such as ECG signals, blood pressure signals, and EEG signals, all represent certain pathological characteristics. Taking ECG as an example, ECG is usually used to record the bioelectric current generated by the heart. Clinicians can use ECG to evaluate the patient's heart condition and
[Industrial Control]
Design of ECG signal acquisition and analysis based on LabVIEW
In-depth exploration of LabVIEW------Is the sequence structure a "structure"?
The concept of "structure" in LabVIEW is very different from that in C language. The structure in C language refers to a composite data type. The so-called structure in LabVIEW is equivalent to the program running structure in C language, including loops, sequence structures, conditional structures, event structures, e
[Test Measurement]
In-depth exploration of LabVIEW------Is the sequence structure a
LabVIEW Series - Filter Effects
 
[Test Measurement]
Research on Intelligent Monitoring System of Student Dormitory Based on LabVIEW
0 Introduction     The "Ma Jiajue Incident" that shocked the whole country in the dormitory of Yunnan University in 2004 made countless student management workers shudder; and on December 11, 2010, the "Yunnan Student Dormitory Tragedy" that occurred in the student dormitory of Zixi Middle School in Chuxiong, Yunnan,
[Test Measurement]
Research on Intelligent Monitoring System of Student Dormitory Based on LabVIEW
LabVIEW and C interface design method
   Labview provides a driver library that supports VXI bus, GPIB bus, and RS-232 serial bus interface hardware, but its operation on physical memory is limited, and the real-time performance of hardware operation is not good. However, it provides CIN (CODeInterfaceNode) nodes. Users can determine the number and type o
[Test Measurement]
LabVIEW and C interface design method
Latest Test Measurement Articles
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号