GPIB to USB Interface, Arduino Nano 3
Rainer Schuster was so friendly, and has programmed in a good style a GPIB to USB converter with Win32 demo program to read a Tektronix TDS210 oscilloscope presented in the magazine Elektor 04-2011. The whole thing is much cheaper than commercial circuits, for hobby purpose. Please see for details at GPIBtoUSB2.
Unfortunately, by not using a GPIB bus driver, it is only possible to connect not more than one GPIB device. The R8C CPU can deliver up to 60 mA at the I/O ports in total. Per output pin it should not be more than 2 mA in order not to exceed the voltage of 0.8V for the LOW level. With IEEE-488 GPIB standard, each device on the bus has a termination 3 KOhm resistor to +5V and 10 KOhm to 0V.
Now I have ported the software to the Arduino Nano 3, please see at GPIBtoUSB_Nano3#Links.
The ATMega CPU can deliver up to 200 mA at the I/O ports in total. Per output pin it should not be more than 20 mA in order not to exceed the voltage of 0.8V for the LOW level. So, I think that a minimum of 3 instruments should be possible to connect on the GPIB bus.
2016-01-16 Software Update to version 1.3. In header file GPIB_nano.h I had forgotten to set the ATN_D1 out direction in macro SET_TALK. The effect was, that the program works only after the first error.
2016-08-21 Software update to version 1.4. The GPIB T1 data settle time was reduced from 10 us to 2 us. The USB serial baudrate was increased from 38400 to 115200 baud. The Python program hp1630_p23.py was extended to work under Python 2 and 3, and function was tested under Linux Ubuntu 16.04-32, Mac OS X 10.11.6 and Windows 7-64.
Development Software
The development software is the standard IDE from Arduino, please see at GPIBtoUSB_Nano3#Links.
Simplified Hardware
Because the Nano 3 is a complete micro computer board, which has its power supply from the USB port, just some resistors and a GPIB connector (Centronics, 24 pin socket) are needed, please see the picture on the right.||
I have drawn a diagram with Eagle5 and attached:GPIB_USB_Nano.sch
In order to see an overview of the diagram here as a PNG file (click to enlarge).
Plus a PDF file for a better printout GPIB_USB_Nano_sch.pdf.
Test of the circuit
In order to test the basic function of the program and the interface, you need a terminal program. May I suggest PUTTY for Win32 and CoolTerm for Mac OS X.
PUTTY Parameters, Session: Connection Type: serial Serial line: COMx (x = USB Serial Emulation Nummer, e.g. 6) Speed: 115200 Keyboard input (blind, no Echo): "I", strg"J" (upper case I, Control+J = LineFeed) Answer: GPIB/USB converter V1.4 or Set local echo ON Text from the clipboard is inserted into the terminal window via the middle mouse key.
Firmware Comands
The commands can be sent manually in a terminal to the GPIB-USB converter. All commands must be terminated with Linefeed (Ctrl + J).
C - Reset and Init GPIB Bus
Gx - Send Command byte, x = Zahl 0..255
I - Show the GPIB-USB info : GPIB/USB converter V1.1
Ra,s - Send a string and read answer, a = GPIB Adresse, s = String, end of read at LineFeed
S - Check GPIB SRQ signal
Tn - Set GPIB Timeout in n = ms
Wa,s = a = GPIB Address, s = String, Write a string
To be able to operate my HP Logic Analyzer HP1631D in a useful manner with this interface a few commands were added:
B addr, byte LF - send a command Byte to the selected device, for example "B4,1\n" for the command Go To Local, in order to switch from Remote Mode back to Local Mode, in order to operate from the front panel again.
D LF byte - send a Data byte, if the device was addressed before with the L-command. Which is used to upload a file to the GPIB device. The data byte is echoed in order to control the data rate.
E addr, command LF - This works like the R-command, but the end of the answer is not signalled by a LineFeed, instead with GPIB signal line EOI. Otherwise reading in of multi-line data, or binary data, for example a screen hardcopy, will be more complicated.
L addr,LF - switching of the selected device to Listener, and uploading a file to the device.
U LF - switching off the Listener mode, with the sequence: LF+EOI, UNL, UNT. That could also be done with a sequence of other commands, but his is easier in the GPIB programming.
Extensions to GPIB_USB.c
The extended files are here for download: GPIB_USB_nano.ino , GPIB_functions.ino and header file GPIB_nano.h. If you click on the file link, the program will be shown with pritty printing (colored).
All files must be within one folder to allow the Arduino IDE to reference the symbols across the files.
Debug
- Error numbers:
- DEVICE_NOT_PRESENT_ERROR 1
- GPIB_TIMEOUT_ERROR_TX 2
- GPIB_TIMEOUT_ERROR_RX1 3
- GPIB_TIMEOUT_ERROR_RX2 4
For easier trouble shooting, please see the pin out of the GPIB DB24 plug, on the right.
Application Program hp1630_p23.py for Logic Analyzer
You need the modul pyserial in order to use this program. That can be installed with the following command line:
# Linux and Mac OS X $ sudo pip3 install pyserial # Windows 7 > py -3 -m pip install pyserial
For comfortable using the HP Logic Analyzer HP1631D, I have written a Python command line program hp1630_p23.py. The function was tested under Linux Ubuntu 16.04-32, Mac OS X 10.11.6 and Windows 7-64. If you run the programm without parameter you get get a help message. The GPIB Address of the device is coded to 4.
It is an example program, which can be easily adopted to other instruments. Most of the needed functions are already coded.
The following commands are build in, as Command Line Parameter:
-a --printall - print the Text Screen, also the non visible part. Filename default: printall.txt
-b --beep - the Logic Analyzer will generate a Beep.
-d --date - sets the actual date and time in the Logic Analyzer. The time is incremented (RTC) until switching off the LA. There is no battery back up (27 years old).
-f --file - specify a Filename for download or upload.
-i --id - read out the identity info of the device (hp1631D).
-l --local - switch back the device from Remote mode to Local mode, for using again the front panel buttons. This is also possible by a switch on the front panel, but it could be more convenient.
-p --print - read out a Waveform screen shot and store in format PBM (Portable Bit Map). OpenOffice can import that file.
-r --restore - upload the Inverse Assembler for the HP 10269B Preprozessor (GPIB, RS232, RS449). This will show GPIB mnemonics on the screen, up to 1000 cycles.
-t --timeout - set GPIB timeout in seconds.
-u --usb read out the Info string "GPIB/USB converter V1.1" from the GPIB-USB converter.
-v --verbose enable temporarily status messages for debugging.
If you want to run a different GPIB device so you have to adjust the program accordingly. Since Python is a multi-platform interpreter programming language, an adoption should not be so difficult.
Screen Shots
For screen shots please have a look at GPIBtoUSB2#Screen_Shots.
On the right is a Screenshot of the Arduino IDE (Integrated Development Environment), click to enlarge.
GPIB handshake
DAV: Used by the Talker to indicate that a byte can be read by the Listeners.
NRFD: Indicates whether the Listener is ready to receive the byte.
NDAC: Indicates whether the Listener has accepted the byte.
The GPIB handshaking process follows these steps:
Initially, the Talker holds the DAV line high indicating no data is available, while the Listeners holds the NRFD line high and the NDAC line low indicating it is ready for data and no data is accepted, respectively.
When the Talker puts data on the bus, it sets the DAV line low, which indicates that the data is valid.
The Listeners set the NRFD line low, which indicates that they are not ready to accept new data.
The Listeners set the NDAC line high, which indicates that the data is accepted
When all Listeners indicate that they have accepted the data, the Talker asserts the DAV line indicating that the data is no longer valid. The next byte of data can now be transmitted.
The Listeners hold the NRFD line high indicating they are ready to receive data again, and the NDAC line is held low indicating no data is accepted.
Please see the timing chart on the right.
If the ATN line is high during the handshaking process, the information is a command to an instrument.
If the ATN line is low, the information is a GPIB message from an instrument.
GPIB command bytes |
||
byte value, HEX |
name |
decription |
0x01 |
GTL |
Go To Local |
0x04 |
SDC |
Select Device Clear |
0x05 |
PPC |
Parallel Poll Configure |
0x08 |
GET |
Group Execute Trigger |
0x09 |
TCT |
Take Control |
0x11 |
LLO |
Local Lockout |
0x14 |
DCL |
Device Clear |
0x15 |
PPU |
Parallel Poll Unconfigure |
0x18 |
SPE |
Serial Poll Enable |
0x19 |
SPD |
Serial Poll Disable |
0x20 - 0x3E |
MTA0-30 |
My Listen Addr. 0 - 30 |
0x3F |
UNL |
Unlisten |
0x40 - 0x5E |
MTA0-30 |
My Talk Address 0 - 30 |
0x5F |
UNT |
Untalk |
GPIB command bytes
The table on the right shows most of the GPIB Commands.
This can be useful if debugging with a Logic Analyzer.
Only the Primary Addresses are show. The command codes 0x60 - 0x7E are used for Secondary Addresses and Parallel Poll use. This is not covered here, please see here for details.
Debugging the GPIB
I will try to give a help for trouble shooting the GPIB. The shown example is the Identification command, which does most instruments have.
In this case the instrument is an old Logic Analyser HP1631D with GPIB address 4.
The command for identification is the ASCII text ID followed by the byte newline (LineFeed). This can be entered manually from the Arduino Monitor, it does not need a comuter program for that.
The baudrate of the Arduino Monitor must match the baudrate of the USB-GPIB interface, in my case 115200 baud.
The answer text from the instrument must be HP1631D.
State Analysis
In order to better understand the sequence of the commands, I made a State Analysis with an HP1652B Logic Analyser, with Inverse Assembler for the GPIB mnemonics.
1 MACHINE 1 - STATE LISTING 2016-08-10
2 Label > ADDR ATN Mnemonic HEX EOI SRQ REN IFC STAT
3 Base > Hex Instructions Hex
4
5 +0000 ATN *UNL* 3F REN 1A
6 +0001 ATN *UNT* 5F REN 1A
7 +0002 ATN LAG_04 24 REN 1A
8 +0003 I 49 REN 1B
9 +0004 D 44 REN 1B
10 +0005 <LF > 0A EOI REN 19
11 +0006 ATN *UNL* 3F REN 1A
12 +0007 ATN *UNT* 5F REN 1A
13 +0008 ATN TAG_04 44 REN 1A
14 +0009 H 48 REN 9B
15 +0010 P 50 REN 9B
16 +0011 1 31 REN 9B
17 +0012 6 36 REN 9B
18 +0013 3 33 REN 9B
19 +0014 1 31 REN 9B
20 +0015 D 44 EOI REN 99
21 +0016 ATN *UNL* 3F REN 1A
22 +0017 ATN *UNT* 5F REN 1A
23 File: hp1652-state_hp1630-ID.txt
- A short explanation of some commands and signals:
ATN = Attention, active LOW means a command byte follows, not a data byte.
LAG_04 = Address Listener number 04 on the GPIB, the controller will send a text.
TAG_04 = Address Talker number 04 on the GPIB, the controller will wait for a text.
EOI = End Or Identify, this signals usually the end of a text.
Timing Analysis
While the data flow in the State Analysis looks consecutive, it is not in the Timing Analysis.
Please see the first Timing Diagram on the right. It shows the Talker Handshake Timing, and is about 100 us long.
0 us: It starts with the first 4 bytes, shown in the State Analysis: Unlisten, Untalk, Address Listener number 4, first letter I of the command.
8 ms: Letter D was send.
12.8 ms: 4 bytes are send: LF (newline) with EOI, Unlisten, Untalk and Address Talker number 4.
31.25 ms: Letter H was send.
31.9 ms: in a sequence of length 950 us the letters P1631 are send.
33.27 ms: Letter D with EOI was send, then Unlisten and Untalk.
33.35 ms: End of the sequemce.
The second Timing Diagram on the right shows the End of the command sequence.
At the letter D you will see the Listener Handshake Timing.
Each byte of the command sequence has a duration of about 25 us. So, a telegram of 18 bytes length could have a theroretical duration of 450 us, in reality it needs 33500 us, wich is a factor of 75. Let's write it in a formula for an easier understanding:
- 18 x 25 us = 450 us
- 450 us * 75 = 33750 us
That was the difficulty with the Timing Analysis, on one hand you need a resolution of 10 us per division, in order to see the handshake timing, but if you want to show the total sequence length, you will get a screen resolution of 5000 us per division, which can not show any handshake detail.
The third Timing Diagram on the right will show that.
You see at the previous mentioned times, some data transfer will go on, but no details are marked in the timing diagram.
For a better understanding of the GPIB bus, please read the reference manuals referenced in Links #7 and #8.
Links
Linux GPIB instrument support utilities, 2014-08 version 1.5
Tutorial Description of the Hwlett-Packard Interface Bus 1987
List of pages in this category:
-- RudolfReuter 2013-11-05 12:28:29
Go back to CategoryLogicAnalyzer or StartSeite ; KontaktEmail