Top Banner
INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/ 09 Instrumentação Suportada em Computadores Pessoais GPIB under MATLAB A. Lopes Ribeiro [email protected]
14

Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008

Dec 17, 2018

Download

Documents

lytu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Instrumentação Suportada em Computadores Pessoais

GPIB under MATLAB

A. Lopes [email protected]

Page 2: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Using the GPIB Interface under MATLAB Control

IEEE 488

Page 3: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Equipment

• GPIB adaptor board or GPIB-USB adaptor• GPIB cables• Instruments with the GPIB interface• MATLAB with the “Instrument Control Toolbox”

installed

Page 4: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

MATLAB information about drivers

To get information about the available drivers to the GPIB interface use the MATLAB function

instrhwinfo(‘gpib’)

>> instrhwinfo('gpib')ans =

InstalledAdaptors: {'advantech' 'ni'}JarFileVersion: 'Version 2.3'

>>

There are drivers for GPIB from the manufacturers Advantech and National Instruments

Page 5: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

MATLAB information about the adaptor board

To get information about the GPIB board installed use the MATLAB function

instrhwinfo(‘gpib’, ‘manufacturer’ )

>> instrhwinfo('gpib','ni')ans =

AdaptorDllName: [1x87 char]AdaptorDllVersion: 'Version 2.3'

AdaptorName: 'ni'InstalledBoardIds: [??????????]

ObjectConstructorName: 'gpib('ni',<BID>,<PR>) '

VendorDllName: 'gpib-32.dll'VendorDriverDescription: 'NI-488'

>>

Page 6: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Communicate with One InstrumentTo communicate with one instrument, we need to create one

variable of the type object in MATLAB. At this time MATLAB already told us how to construct it:

ObjectConstructorName: 'gpib('ni',<BID>,<PR>) '

Example: We want to communicate with one oscilloscope. The board adaptor number is <BID>=0 and the Oscilloscope Primary Address is <PR>=18. The virtual object to create will have the name oscil :

We must use the MATLAB command

>> oscil=gpib('ni',0,18)

MATLAB will respond as follows

Page 7: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Communicate with One Instrument>> oscil=gpib('ni',0,18)

GPIB Object Using NI Adaptor : GPIB0-18

Communication Address BoardIndex: 0PrimaryAddress: 18SecondaryAddress: 0

Communication State Status: closedRecordStatus: off

Read/Write State TransferStatus: idleBytesAvailable: 0ValuesReceived: 0ValuesSent: 0

>>

Page 8: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Obtain Information on The Object Created

Double click

Page 9: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Obtain Information on The Object Created

Page 10: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Obtain Information on The Object Created

Some information about the object oscil just created is also available with the function

instrhwinfo(object_name)

>> instrhwinfo(oscil)ans =

AdaptorDllName: [1x87 char]AdaptorDllVersion: 'Version 2.3'

AdaptorName: 'NI'VendorDllName: 'gpib-32.dll'

VendorDriverDescription: 'NI-488'>>

Page 11: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Connecting and Disconnecting Instruments• To connect to the oscilloscope we must open the object using

the function fopen(object_name).• To disconnect it we use the function fclose(object_name).

>> fopen(oscil)>> oscil.Statusans =Open>> ………………………>> ………………………>> fclose(oscil)>> oscil.Statusans =closed>>

We can check the Status property of the object oscil with the command above

Page 12: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Sending and Receiving Data

• We send data to the instrument with the function fprintf(instrument_name,’data_string’), but to read answers we use the function fscanf(.) with the instrument logic name as argument.

• Example:

>>fprintf(oscil,’*IDN?’)>>Osc_name=fscanf(oscil)Osc_name=TEKTRONIX TDS 2014,0,CF:91…….>>

Page 13: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Sending and Receiving Data• In the next example we wish to read data from the

channel 1 of the oscilloscope. We send one command to set CH1 as the data source and next we confirm the command execution by sending a query and reading the answer, that is put in a variable:

>>fprintf(oscil,’MEASUREMENT:IMMED:SOURCE CH1’)>>fprintf(oscil,’MEASUREMENT:IMMED:SOURCE?’)>>Source_channel=fscanf(oscil)Source_channel=CH1>>

Page 14: Instrumentação Suportada em Computadores Pessoais · INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Sending and Receiving Data• If we wish to read a peak to peak voltage from the

current source channel:

>>fprintf(oscil,’MEASUREMENT:MEAS1:TYPE PK2PK’)>>fprintf(oscil,’MEASUREMENT:MEAS1:VALUE?’)>>Vx_p2p=fscanf(oscil)Vx_p2p=3.0017668678E0>>If we want to disconnect the instrument definitely we must

close the object, delete it and clear the MATLAB workspace:

>>fclose(oscil)>>delete(oscil)>>clear(oscil)