“More and more measuring instruments provide GPIB (General Purpose Intefface Bus) bus interface, through which the instruments and computers with GPIB interface can be easily and quickly connected to form a GPlB network. When connecting a GPIB device to a computer, a GPIB interface card is required, but these GPIB interface cards are expensive, which brings inconvenience to the connection between the instrument and the computer. In most cases, only one GPIB interface instrument is connected to the computer, and these complicated and expensive GPIB boards are not needed.
More and more measuring instruments provide GPIB (General Purpose Intefface Bus) bus interface, through which the instruments and computers with GPIB interface can be easily and quickly connected to form a GPlB network. When connecting a GPIB device to a computer, a GPIB interface card is required, but these GPIB interface cards are expensive, which brings inconvenience to the connection between the instrument and the computer. In most cases, only one GPIB interface instrument is connected to the computer, and these complicated and expensive GPIB boards are not needed. Facing the functional requirements of connecting a single instrument with a computer, this paper designs a RS232-GPIB controller with outstanding cost performance. The controller uses the most commonly used RS232 interface of the computer to control the instrument with GPIB interface. establish a data transmission channel between them. At the same time, it supports the SCPI (Standard Commands for Prognmnnable Instrumentation) instruction set, and you can easily set the parameters of the instrument and read the test results simply by entering the SCPI command in the hyperterminal of the tool software that comes with the Windows operating system.
The RS232-GPIB controller is designed to connect a computer and a measuring instrument with a GPIB interface, and use the computer’s keyboard and Display to control the instrument for program-controlled measurement. In this design, the computer interface is RS232 interface, using this serial port as a communication tool, the programming is convenient, the connection is simple and reliable, and the software adopts the super terminal that comes with the Windows operating system. Therefore, it is very convenient to complete the receiving and sending of computer serial port data, without self-development of computer-side software, which saves the development time of the controller. The core of the designed controller is the single-chip microcomputer, which is connected to the RS232 serial port of the computer at one end and the GPIB interface of the instrument at the other end. After the instrument executes the instruction, it sends the execution result to the controller, and the controller transmits the received data to the computer through the RS232 serial port. displayed in HyperTerminal.
1 hardware design
The single-chip microcomputer is the core of the RS232-GPIB controller. This design selects the AT89C51 single-chip microcomputer of ATEML Company. Because the 89C51 has a wide range of applications, it has abundant on-chip resources and bus-type I/O ports, supports high-level language programming, and integrates an asynchronous serial control unit that conforms to RS232 data specifications. Therefore, using the Tx and Rx serial interface lines to transmit data with external serial, only need to use the MAX232 chip for level conversion outside the single-chip microcomputer, and then the serial port (COM) of the computer can be directly connected. The hardware structure of the controller is shown in Figure 1. Among them, the GPIB interface control circuit is the focus of the controller hardware design.
It should be pointed out that the use of intelligent GPIB interface chips can greatly simplify the design of GPIB interface circuits. There are two most commonly used chips at present, one is represented by the TNT4882 chip produced by National Instruments, which integrates all interface functions on the chip, completely completes the interface functions by hardware, does not require other auxiliary chips, and is directly connected to the GPIB bus The other is represented by the TMS9914 chip produced by Texas Instruments, which relies on software programming to complete the GPIB interface function. The interface chips SN75160 and SN75161 perform level conversion and connect to the GPIB bus. The comparison of these two chips is shown in Table 1. Taking into account the cost and other factors, this design selects the NAT9914 chip that is fully compatible with the TMS9914 chip as the GPIB bus interface chip. NAT9914 is a standard GPIB control chip, which can perform all GPIB interface functions, has direct memory access (DMA) function, programmable clock and baud rate, adopts CMOS driver, and is compatible with TTL level, so it is extremely convenient to use. At the same time, SN75160 is selected as the data converter, and SN75162 is used as the handshake line and control line converter, and is used together with NAT9914 to connect to the GPlB interface.
In Figure 1, the PO port of 89C51 is used to connect the data interface of NAT9914, as a data bus and GPIB for bidirectional data exchange; the I/O port of Pl is used as an address bus to address the internal registers of NAT9914. The interrupt output of NAT9914 is connected to the external interrupt interface of 89C51, and the GPIB interface communication is managed by means of interrupt triggering; the clock signal of NAT9914 generally adopts an independent clock source. In this design, considering that the function of the controller only completes the communication with a single GPIB interface instrument, the impact of the clock frequency on the data transmission speed of the GPIB interface can be ignored. Therefore, the ALE signal of the 89C51 is directly used as the NAT9914 clock signal. In this way, the on-chip resources of the 89C51 can be fully utilized, the circuit can be simplified, and the hardware cost can be reduced.
2 Software Design
The computer-side software adopts the hyperterminal, and the user enters the command statement in the hyperterminal to control the instrument with the GPIB interface. Because the SCPI command set provides a seamless control interface, it does not need to reset the control program when replacing similar GPIB devices from different companies, and can easily program with similar GPIB devices from different manufacturers. Therefore, this design selects the SCPI command set commonly used in the industry as the control command, so that the RS232-GPIB controller can be used in conjunction with most GPIB interface instruments.
In this design, the controller software is written in C51 language, compiled and programmed to run in the 89C51 single-chip microcomputer. The software framework adopts the main program plus interrupt calling method. to improve the cohesion of functional modules. The software function is divided into two parts: RS232 serial communication program and GPIB interface communication program, which are related to two interruptions: (1) Serial communication interruption. This interrupt is responsible for RS232 serial port data transmission. (2) Receive external interrupt of NAT9914 interrupt signal. This interrupt handles various events for data communication from the GPIB interface. The main program enters an infinite loop state after completing all initialization, waiting for the occurrence of these two interrupts. Among them, the RS232 serial port data transmission is executed in the main program, and the serial port data reception is completed by the serial port interrupt handler. The serial communication program is relatively simple, and the GPIB communication program structure is mainly given here.
The NAT9914 chip needs to be initialized before it starts to work. This part of the code runs as part of the initialization program in the main program, including setting the ICR register, selecting the clock signal frequency, setting the GPIB delay time and asking T1, defining the communication end character EOS, and setting the GPIB device Address (The specified address must be between 0 and 30, if a larger address is written. The device is still regarded as 30). After the initialization is completed, connect the NAT9914 to the GPIB bus. The initialization process is shown in Figure 2.
The code of the GPIB control part runs in the interrupt mode. When the NAT9914 triggers the external interrupt of the 89C51 chip, the microcontroller stops normal work, pushes the field data into the stack protection, and calls the external interrupt processing function to respond to the interrupt application of the NAT9914 chip, and its interrupt processing The program flow is shown in Figure 3. There are four main events that cause NAT9914 to send out interrupt signal to the microcontroller: send data event, receive data event, receive GET command event and receive DCAS command event. Frequent interruptions will affect the running efficiency of the main program, but considering that the designed converter has a single function, the main program is basically in an idling state, and the processing of the four events is completed in the interrupt program, so it has little impact on the main program. Figure 4 and Figure 5 show the process of GPIB receiving data and sending data.
Each time the GPIB interface data is received, after the NAT9914 receives the first byte of data, the BI bit in the register ISR0 is set. Trigger the external interrupt of the single-chip microcomputer. After the single-chip microcomputer enters the external interrupt handler, it reads the ISR0 register and determines that the reason for the NAT9914 triggering the interrupt is that after receiving the data event, it calls the execution of the receiving data subroutine and starts to receive the data from the GPIB instrument.
In the main program, after NAT9914 sends the first byte of data. That is, the BO bit in the register ISR0 is set to trigger the external interrupt of the microcontroller. After the microcontroller enters the external interrupt processing program, it judges that the event type is a sending data event according to the BO bit, then calls the GPIB data sending program, and sends the remaining data in the buffer to the GPIB bus in turn.
3 Operation and results
The RS232-GPIB controller designed in this paper has been successfully used in the GPIB bus connection between the computer and the Tektronix TDS210 oscilloscope. Figure 6 is a partial screenshot of the Display interface of the computer super terminal, in which COMMAND: “is the SCPI command input prompt on the computer keyboard, and GPIB: ” is the feedback information output prompt of the GPIB connected device, indicating that the following information comes from the GPIB device (that is, the Tektronix TDS210 type oscilloscope).
The first input is the query command. Such commands start with ‘? ‘ at the end, when the oscilloscope receives the query command, it will immediately feedback the relevant query information. ID? command to query the brand and model information of the oscilloscope, and the oscilloscope will reply relevant information and display it on the HyperTerminal; CH1? command to query the setting information of channel 1 of the oscilloscope; DATA? command to query the current channel information and sampling points of the oscilloscope.
Then input the control command. After the oscilloscope receives the command, it performs the corresponding operation, but does not feed back the execution result. Such as: LANG ENGL command, it means to change the oscilloscope language interface to English interface; LANGJAPA command, means to modify the interface to Japanese interface.