MATLAB控制儀器自動(dòng)測(cè)試就是這么簡(jiǎn)單
【免責(zé)聲明】
-
本公眾號(hào)的主體為個(gè)人,作者在本公眾號(hào)發(fā)表的所有文章均是出于無私分享、交流學(xué)習(xí)的目的。
-
作者在該公眾號(hào)發(fā)表文章純屬個(gè)人行為,文章的觀點(diǎn)也純屬個(gè)人觀點(diǎn),與作者曾經(jīng)任職或者正在任職的公司、其他個(gè)人或組織均沒有任何關(guān)系。
-
作者已經(jīng)發(fā)表或者即將發(fā)表的MMIC設(shè)計(jì)系列文章將會(huì)嚴(yán)重倚賴于各類EDA軟件,尤其是ADS和Cadence;作者個(gè)人的確沒有實(shí)力購買這些軟件的使用授權(quán),但作者保證僅用于業(yè)余研究和交流學(xué)習(xí)的目的,絕對(duì)不會(huì)用于商業(yè)盈利;若軟件商有異議,作者全力配合刪除相關(guān)軟件和文章。
-
文章中可能有些素材取材于網(wǎng)絡(luò),若有侵權(quán)請(qǐng)讀者提醒,作者會(huì)在第一時(shí)間進(jìn)行更正。
-
對(duì)于聲明原創(chuàng)的文章,歡迎任何人轉(zhuǎn)載分享,但須注明出處。
非常難得因?yàn)橐咔殪o態(tài)管理,免費(fèi)獲得一天周五不需要上班的時(shí)間!高興??!前段時(shí)間翻到以前用MATLAB做的功放自動(dòng)測(cè)試程序,覺得以前的自己是真的很NB??!那今天就隨手?jǐn)]一篇。
搞電路設(shè)計(jì)必然繞不過的測(cè)試,使用儀器完成測(cè)試任務(wù)是必備技能。一些常規(guī)的,非重復(fù)性的測(cè)試任務(wù)可以手動(dòng)完成,但如果需要完成大量的重復(fù)性測(cè)試,使用自動(dòng)化測(cè)試手段就非常有必要了。絕大部分儀器都是支持編程控制的,幾個(gè)跟可編程儀器相關(guān)的概念包括:
VISA or "Virtual Instrument Software Architecture" is a standard library used to communicate to instruments. It's incorporated into Keysight Technologies "IO Suite" and also in National Instruments "Max". The library can be used by graphical and textual languages.The VISA standard includes specifications for communication with instruments over Test and Measurement-specific I/O interfaces such as GPIB, VXI, PXI, AXIe .... There are also specifications for T&M-specific protocols (computing) over PC-standard I/O, such as VXI-11 (over TCPIP) and USBTMC (over USB).The current standard, "VISA Specification 5.8", is maintained by the IVI Foundation. The complexity (communication protocol) of the different interfaces like: USB, LAN, PXI ... is solved in this library. So you can concentrate on the actual measurement task.
VISA即虛擬儀器軟件架構(gòu),將各類儀器、各種儀器的硬件接口(例如GPIB、VXI、PXI、PCI、USB、Serial、LAN(TCP/UDP)等全部抽象后統(tǒng)一起來,提供一套標(biāo)準(zhǔn)的軟件接口
SCPI or "Standard Commands for Programmable Instruments" is mainly used by "Keysight Technologies" instruments. The idea behind this standard is to create common commands for common tasks. SCPI promotes consistency, from the remote programming standpoint, between instruments of the same class and between instruments with the same functional capability. For a given measurement function such as frequency or voltage, SCPI defines the specific command set that is available for that function. Thus, two oscilloscopes made by different manufacturers could be used to make frequency measurements in the same way. It is also possible for a SCPI counter to make a frequency measurement using the same commands as an oscilloscope. SCPI commands are easy to learn, self-explanatory and account for both novice and expert programmer’s usage. Once familiar with the organization and structure of SCPI, considerable efficiency gains can be achieved during control program development, independent of the control program language selected.
SCPI即可編程儀器的標(biāo)準(zhǔn)指令集,這是一個(gè)有二十多年歷史的老標(biāo)準(zhǔn)了,最初是為遠(yuǎn)程傳感器控制設(shè)計(jì)的,使用ASCII碼字符串來定義指令(有點(diǎn)類似電信中的AT&T信令),后來被其他儀器采用逐漸得以發(fā)展。任何符合SCPI規(guī)范的可編程儀器至少包含以下通用指令集:
*IDN? 查詢?cè)O(shè)備ID*ESE *OPC*SRE?*RST 儀器復(fù)位*ESE?*OPC?*STB*CLS*ESR*SRE*TST?*WAI
除此之外,不同儀器根據(jù)需要再定義一些可選指令集。具體定義和語法參考https://www.ivifoundation.org/docs/scpi-99.pdf
給儀器編程時(shí),應(yīng)該查看其對(duì)應(yīng)的編程手冊(cè),手冊(cè)里會(huì)給出詳細(xì)的指令格式和功能說明。
SICL or "Standard Instrument Control Library" is a standard library used to communicate with instruments. It's incorporated into Keysight's "IO Suite" and in National Instruments "Max". The library can be used by graphical and textual languages.SICL is a modular instrument communications library that works with a variety of computer architectures, I/O interfaces, and operating systems. Applications written in C/C++/C# or Visual BASIC using this library can be ported at the source code level from one system to another with no (or very few) changes.SICL uses standard, commonly used functions to communicate over a wide variety of interfaces. For example, a program written to communicate with a particular instrument on a given interface can also communicate with an equivalent instrument on a different type of interface.
SICL即標(biāo)準(zhǔn)儀器控制庫
IVI-COM actually consists of two standards. The IVI part represents the "Interchangeable Virtual Instruments".The COM part represents the "Component Object Model" defined by Microsoft.Systems designed using IVI-COM drivers enjoy the benefits of standardized code that can be interchanged into other systems. This code also supports interchange of measurement devices -- helping to prevent hardware obsolescence. Interchangeability is supported on three levels : The IVI architecture specifications allow architectural interchangeability -- that is a standard driver architecture that can be reused.The class specifications provide syntactic interchangeability which supports instrument exchange with minimal code changes.The highest level of interchangeability is achieved by using the IVI signal specifications.
IVI即可交換虛擬儀器,負(fù)責(zé)儀器接口的抽象統(tǒng)一;COM即微軟定義的組件對(duì)象模型,是一個(gè)獨(dú)立于平臺(tái)的分布式面向?qū)ο蟮南到y(tǒng),用于創(chuàng)建可以交互的二進(jìn)制軟件組件。
有了以上基本概念,來看使用MATLAB控制儀器有多么簡(jiǎn)單:
首先確認(rèn)安裝了驅(qū)動(dòng)程序,例如Keysight的IO Library Suite,或者NI的VISA驅(qū)動(dòng),基本上是兼容的。可通過Keysight的Connection Expert搜索、查看、添加連接到計(jì)算機(jī)或者網(wǎng)絡(luò)上的儀器,獲取其設(shè)備ID。也可以使用MATLAB自帶的tmtool掃描可用的儀器:
instrhwinfo ans = HardwareInfo with properties: MATLABVersion: '9.10 (R2021a)' SupportedInterfaces: {1×10 cell} SupportedDrivers: {'matlab' 'ivi' 'vxipnp'} ToolboxName: 'Instrument Control Toolbox' ToolboxVersion: '4.4 (R2021a)' Access to your hardware may be provided by a support package. Go to the Support Package Installer to learn more.
例如比較常見的ITECH直流電源,低端的只支持RS232串口,假設(shè)使用計(jì)算機(jī)的COM1口連接到電源,則使用以下代碼:
ps=serial('com1',9600);%創(chuàng)建串口對(duì)象fopen(ps);%打開串口,與儀器建立連接fprintf(ps,'*IDN?');%發(fā)送SCPI指令詢問儀器ID號(hào)id=fscanf(ps,'%s');%讀取儀器回復(fù)的ID號(hào)fprintf('已連接到儀器:%s\n',id);%打印儀器 ID號(hào)
又例如創(chuàng)建通過串口連接的NI儀器對(duì)象,假設(shè)設(shè)備地址是'ASRL1::INSTR':
vs = visa('ni','ASRL1::INSTR');%創(chuàng)建儀器對(duì)象fopen(vs);%連接到儀器
GPIB、VXI、TCPIP、USB等全都類似:
vg = visa('keysight','GPIB0::1::30::INSTR');
-
vv = visa('keysight','VXI0::8::INSTR');
-
vt = visa('tek', 'TCPIP::216.148.60.170::INSTR')
-
vu = visa('keysight', 'USB::0x1234::125::A22-5::INSTR')
所有的虛擬儀器對(duì)象操作都可以視為一個(gè)文件進(jìn)行打開、關(guān)閉、讀寫操作
-
-
-
-
-
-
fopen(vs);%打開儀器對(duì)象fprintf(vs,'SCPI Command');%標(biāo)準(zhǔn)輸出fscanf(vs,'format',...);%標(biāo)準(zhǔn)輸入fread(vs,size,precision);%二進(jìn)制讀fwrite(vs,data,precision);%二進(jìn)制寫fclose(vs);%關(guān)閉儀器對(duì)象
不過serial/visa等接口函數(shù)比較老了,新版的MATLAB即將取消它們,替換成了serialport, visadev等儀器對(duì)象,例如:
-
-
-
usbdev = visadev("USB0::0x0699::0x036A::CU010105::0::INSTR");%創(chuàng)建USB虛擬儀器對(duì)象writeline(usbdev,"*IDN?");%發(fā)送SCPI指令id = readline(usbdev);%讀取指令返回值
-
-
serialdev = visadev("COM1");%創(chuàng)建串口儀器對(duì)象id = writeread(serialdev,"*IDN?");%發(fā)送SCPI指令并讀取返回值
-
serialdev = visadev("ASRL1::INSTR");
-
tcpdev = visadev("TCPIP0::169.254.2.20::inst0::INSTR");
最后給一個(gè)使用程控直流電源測(cè)晶體管DCIV的例子:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
ps=serial('COM1',9600); fopen(ps);fprintf(ps,'*IDN?\n');%查詢儀器是否在線str=fscanf(ps,'%s');fprintf('DC Power Supply:\t%s\n',str);if(isempty(str)) msgbox('連接直流電源失敗'); fclose(ps); return;endfprintf(ps,'SYST:REM\n');%遠(yuǎn)程控制模式fprintf(ps,'OUTP OFF\n');%關(guān)閉輸出fprintf(ps,'INST CH1\n');%選擇通道1(柵壓)fprintf(ps,'VOLT 2V\n');%設(shè)置電壓(柵壓-2V)fprintf(ps,'CURR 0.001A\n');%設(shè)置最大電流fprintf(ps,'CHAN:OUTP ON\n');%開啟柵壓輸出pause(1);%等待柵壓開啟1s后再開啟漏壓fprintf(ps,'INST CH2\n');%選擇通道2(漏壓)fprintf(ps,'VOLT 0V\n');%設(shè)置電壓(漏壓0V)fprintf(ps,'CURR 0.1A\n');%設(shè)置最大電流fprintf(ps,'CHAN:OUTP ON\n');%開啟漏壓輸出vgg = -2:0.1:0;%柵壓掃描范圍-2~0V,步進(jìn)0.1Vvdd = 0:0.5:5;%漏壓掃描范圍0~5V,步進(jìn)0.5Vvgs=zeros(length(vgg),length(vdd));%初始化柵電壓測(cè)量結(jié)果vds=zeros(length(vgg),length(vdd));%初始化漏電壓測(cè)量結(jié)果igs=zeros(length(vgg),length(vdd));%初始化柵電流測(cè)量結(jié)果ids=zeros(length(vgg),length(vdd));%初始化漏電流測(cè)量結(jié)果for i=1:length(vgg)%柵壓掃描 fprintf(ps,'INST CH1\n');%選擇通道1 fprintf(ps,'VOLT %fV\n',abs(vgg(i)));%設(shè)置柵壓 fprintf(ps,'INST CH2\n');%選擇通道2 for j=1:length(vdd)%漏壓掃描 fprintf(ps,'VOLT %sV\n',vdd(j));%設(shè)置漏壓 fprintf(ps,'MEAS:VOLT? ALL\n');%測(cè)量三個(gè)通道實(shí)際輸出電壓 dat=fscanf(ps,'%E, %E, %E');%讀回三個(gè)通道實(shí)際輸出電壓 vgs(i,j)=dat(1);%CH1是vgs vds(i,j)=dat(2);%CH2是vds fprintf(ps,'MEAS:CURR? ALL\n');%測(cè)量三個(gè)通道實(shí)際輸出電流 dat=fscanf(ps,'%E, %E, %E');%讀回三個(gè)通道實(shí)際輸出電流 igs(i,j)=dat(1);%CH1是igs ids(i,j)=dat(2);%CH2是ids endendfprintf(ps,'INST CH2\n');fprintf(ps,'CHAN:OUTP OFF\n');%先關(guān)漏壓pause(0.5);%等待0.5sfprintf(ps,'INST CH1\n');fprintf(ps,'CHAN:OUTP OFF\n');%后關(guān)柵壓 figure,plot(vds',1000*ids')title('DCIV Curve')xlabel('Vds: V');ylabel('Ids: mA'); figure,plot3(vds',vgs',1000*ids)title('3D DCIV Curve')xlabel('Vds: V');ylabel('Vgs: V');zlabel('Ids: mA');set(gca,'YTick',-1:0.1:0)grid on
歷史文章
-
ADS應(yīng)用技巧(12)——向量、總線、線束、迭代的用法
-
理論上OIP3究竟比P1dB高多少?
-
終于知道為什么OIP3比P1dB高10dB了
-
ADS應(yīng)用技巧(11)——將多個(gè)s2p文件合并成一個(gè)支持參數(shù)掃描的mdf文件
-
ADS應(yīng)用技巧(10)——將多個(gè)s2p文件合并成一個(gè)多端口的snp文件
關(guān)注本公眾號(hào)