|GPIB till USB omvandlare
A PIC based GPIB to USB adapter
This is a design for a simple GPIB (IEEE-488) to USB adapter as featured in Elektor. It allows you to hook up a number of GPIB- capable instruments to your computer, through an USB port. You can then send commands and read the output through a virtual COM-port on the PC.The new and improved version of the firmware (autumn 2013) now supports most of the Prologix (r) command set. This allows you to use off-the-shelf programs like the KE5FX toolkit or EZGPIB (see note).
NEW: We will soon have have bare boards for sale. See below for details.
Revision 2 board with SMD-parts.
No dedicated GPIB-chips are used, instead we use the standard PIC ports with pullups. This works well, unless you intend to run a lot of instruments on the GPIB Bus or intend to run at very high speeds. U2, RP3 and the LEDs can be omitted if you do not require visual feedback on bus activity.
Prototype PCB, partially populated and mounted in an aluminium box that once housed a TP to FX converter. Connectors (GPIB and USB) are on the back and leds protrude through slot in front.
Trace of the GPIB three-way handshake (0=DAV, 1=NRFD, 2=NDAC, 3.. = Data). We see NRFD going high when all listeners are ready to accept data. At that point the talker puts data on the bus and pulls DAV low. When the last listener has read the data NDAC goes high and milliseconds later DAV, then the cycle repeats.
Data is sent to the converter as strings, terminated by CR/LF. Strings are passed on to the instrument, but CR, LF, ESC and + need to be escaped. So to send a '+', you send two characters ESC and '+'. The sequence '++' is taken to be the start of a command. Valid commands are:
|++addr||Sets or queries the GPIB address used. Send ++addr 24 to make the instrument with an GPIB address of 24 the target of commands to follow. ++addr returns the current address.|
|++auto||Can be 0 or 1, if 1 the controller will automatically put the instrument in talk mode after sending a command.|
|++clr||Send a delected device clear. Usually resets the addressed instrument|
|++eoi||Can be 0 or 1, if 1 the controller will automatically assert EOI on the last character sent.|
|++eos||Can be 0..3, how strings sent to the instrument are terminated: 0=CR+LF, 1=CR, 2=LF, 3=nothing.|
|++eot||Can be 0 or 1, if 1 the controller will automatically add the char specified as eot_char on an EOI.|
|++eot_char||Can be any ascii character, if eot is 1 the controller will automatically add the char on an EOI.|
|++ifc||Send an Interface Clear|
|++loc||Deassert REN (Put instrument in local mode)|
|++mode||Determine if unit is controller or device. The setting is read and stored, but unit is always controller|
|++read char/eoi||Read until char or EOI.|
|++read_tmo_ms||Sets read timeout in ms|
|++rst||Resets internal data pointers and clears buffers|
|++spoll||Executes a serial poll. Read the status byte from the unit|
|++srq||Returns the status of the SRQ line|
|++trg||Group execute trigger - send an Group Execute trigger to the currently addressed instrument or to the one address given. Note that multiple addresses are not currently supported.|
|++ver||Returns the unit's version string|
|++debug||Sets or reads debug level for debug builds. See debugging|
Incoming data is accepted (up to a maxmimum of 128 characters) and passed back to the PC when the line is terminated by an LF or an EOI
Note that when sending data to the instrument, the buffer is 64 bytes. If the data contains chars that need to be escaped, a safe assumption is to send a maximum of 32-1 non-escaped (or 64-1 escaped) characters, followed by a LF. Next version of Firmware, currently in testing will remove this limitation and allow you to send binary data of unlimited length.Source
Latest (2018-05-01) debug and release firmwares as a zip-file. Rightclick and "save as"
2016-09-27 release firmware as HEX-file. Rightclick and "save as"
2016-09-27 debug firmware as HEX-file. Rightclick and "save as" (Outputs debug info on serial port at 57600baud)
2015-09-03 release firmware as HEX-file. Rightclick and "save as"
2015-09-03 debug firmware as HEX-file. Rightclick and "save as" (Outputs debug info on serial port at 57600baud)
Utility to save and restore settings and save screendumps from HP163XX and similar. Rightclick and "save as"
2013-09-05 Now handles received binary data correctly. Reworked the receive code so that it is much faster (accepts a byte in 25us)
2013-09-29 Prologix (r) emulation
2014-02-09 Tweaked GPIB some more, now manages one byte in 20.15us, ie approx 50kb/s. (Measured pushing binary data from a HP 3852A)
2014-12-02 Corrected a problem handling EOI. We now untalk immediately after EOI which seems to make the HP 603x range of PSUs happier
2015-09-03 Untalk even for instruments that do not issue EOI, fixes the dreaded "NO MESSAGE" hang. Fixed several issues when running as DEVICE. Now works correctly with the KE5FX 7470.exe plotter emulator
2016-09-27 Code ported to MPLABx/XC8. Slightly faster, plus corrected a few minor issues 2018-05-01 Changed the version string as some version of Prologix.exe objected.
We will soon have boards for sale. The boards are 70mmx80mm and uses all-SMD parts, except for a LED-bar for status. They also have a jumper to accomodate the boot-loader I intend to incorporate. The boards are of professional quality, plated,soldermasked and silk-screened. The cost per bare board will be 20€ plus postage. Postage and packing to Europe is 4€ with priority mail. Please send an email to email@example.com if you are interested.
Bom for the v2 PCB in Excel format
Useful GPIB Information
RudisWiki GPIB page
A Tutorial Description of the HPIB Bus
GPIB / IEEE 488 Basics Tutorial
The GPIB FAQ
Make sure that the unit is assembled properly and that there are no bad solderjoints, shorts etc. Check with an oscilloscope that the clock is running
Check that the unit is recognised as a virtual com port when connected to a PC
With the unit plugged in to an USB port and no GPIB units connected, only the NDAC (leftmost) led will be lit. Start Hyperterminal and send it a string. You should see activity on the leds. Type something with nothing connected to the GPIB bus, NRFD should lit, hit Ctrl-Enter and you should see a brief flash on the rest of the leds, then NRFD should go off. f you see this, then the unit is working. Then connect your GPIB-cable and try sending sommands to the unit. If you program with the debug hex file, the unit will output diagnostic info on the serial port at 57600 baud.
I cannot test every instrument and every software package out there. There are subtle quirks in some instruments and some utilities make assumptions they should not. If your instrument fails to work with this adapter please let me know and I will try to see if we can fix the problem. In this case I wamt to see a debug log from the adapter.
To grab a debug log you need a TTL to RS232 adapter (can be built with a MAX232 or bought on eBay for a few dollars) connected to the port of the adapter and to a serial port on your computer. Adapter needs to be programmed with the debug HEX file, you also need to select what to output. The debugging output alters bus timing and hence you can select what to output, ie:
|1||Data from USB|
|2||Data from GPIB|
The debug level is a bitmap with each bit controlling debug output for a certain section. Hence ++debug 24 will output all transmission and reception. Send me the log with an explanation of what instrument and possibly FW version, software and version and what you were trying to do.
EZGPIB expects to see RTS asserted, but because I use the standard Windows USBSER.SYS driver, this does not happen. Thus EZGPIB will never find the GPIB adapter. To get around this you need to hack EZGPIB.EXE and change one byte in the RTS Check routine. Open up a copy of the exe-file in a hex editor. Assuming the 20121217 version, look for the HEX sequence F6 02 24 10. That is the check for RTS. After that you find 74 06, change to 75 06 and save the file. Then look for 24 04 10 0F 95. Change 95 to 94.EZGPIB should now find your adapter. See here and here.
Prologix is a registered trademark of Prologix, LLC, 16541 Redmond Way #421-C, Redmond, WA 98052 USA
This information and the circuits are provided as is without any express or implied warranties. While every effort has been taken to ensure the accuracy of the information contained in this text, the authors/maintainers/contributors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. I disclaim everything. The contents of the articles below might be totally inaccurate, inappropriate, or misguided. There is no guarantee as to the suitability of said circuits and information for any purpose whatsoever other than as a self-training aid. I.E. If it blows your equipments, trashes your hard disc, wipes your backup, burns your building down or just plain don't work, IT ISN'T MY FAULT. In the event of judicial ruling to the contrary, any liability shall be limited to the sum charged on you by us for the aforementioned document or nothing, whichever is the lower. I will not be held responsible for any damages or costs which might occur as a result of my advice or designs. Nor are you allowed to use any of my designs for commercial purposes without my written authorisation.