MATLAB控制仪器自动测试就是这么简单
扫描二维码
随时随地手机看文章
【免责声明】
-
本公众号的主体为个人,作者在本公众号发表的所有文章均是出于无私分享、交流学习的目的。
-
作者在该公众号发表文章纯属个人行为,文章的观点也纯属个人观点,与作者曾经任职或者正在任职的公司、其他个人或组织均没有任何关系。
-
作者已经发表或者即将发表的MMIC设计系列文章将会严重倚赖于各类EDA软件,尤其是ADS和Cadence;作者个人的确没有实力购买这些软件的使用授权,但作者保证仅用于业余研究和交流学习的目的,绝对不会用于商业盈利;若软件商有异议,作者全力配合删除相关软件和文章。
-
文章中可能有些素材取材于网络,若有侵权请读者提醒,作者会在第一时间进行更正。
-
对于声明原创的文章,欢迎任何人转载分享,但须注明出处。
非常难得因为疫情静态管理,免费获得一天周五不需要上班的时间!高兴!!前段时间翻到以前用MATLAB做的功放自动测试程序,觉得以前的自己是真的很NB啊!那今天就随手撸一篇。
搞电路设计必然绕不过的测试,使用仪器完成测试任务是必备技能。一些常规的,非重复性的测试任务可以手动完成,但如果需要完成大量的重复性测试,使用自动化测试手段就非常有必要了。绝大部分仪器都是支持编程控制的,几个跟可编程仪器相关的概念包括:
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即虚拟仪器软件架构,将各类仪器、各种仪器的硬件接口(例如GPIB、VXI、PXI、PCI、USB、Serial、LAN(TCP/UDP)等全部抽象后统一起来,提供一套标准的软件接口
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即可编程仪器的标准指令集,这是一个有二十多年历史的老标准了,最初是为远程传感器控制设计的,使用ASCII码字符串来定义指令(有点类似电信中的AT&T信令),后来被其他仪器采用逐渐得以发展。任何符合SCPI规范的可编程仪器至少包含以下通用指令集:
*IDN? 查询设备ID*ESE *OPC*SRE?*RST 仪器复位*ESE?*OPC?*STB*CLS*ESR*SRE*TST?*WAI
除此之外,不同仪器根据需要再定义一些可选指令集。具体定义和语法参考https://www.ivifoundation.org/docs/scpi-99.pdf
给仪器编程时,应该查看其对应的编程手册,手册里会给出详细的指令格式和功能说明。
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即标准仪器控制库
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即可交换虚拟仪器,负责仪器接口的抽象统一;COM即微软定义的组件对象模型,是一个独立于平台的分布式面向对象的系统,用于创建可以交互的二进制软件组件。
有了以上基本概念,来看使用MATLAB控制仪器有多么简单:
首先确认安装了驱动程序,例如Keysight的IO Library Suite,或者NI的VISA驱动,基本上是兼容的。可通过Keysight的Connection Expert搜索、查看、添加连接到计算机或者网络上的仪器,获取其设备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串口,假设使用计算机的COM1口连接到电源,则使用以下代码:
ps=serial('com1',9600);%创建串口对象fopen(ps);%打开串口,与仪器建立连接fprintf(ps,'*IDN?');%发送SCPI指令询问仪器ID号id=fscanf(ps,'%s');%读取仪器回复的ID号fprintf('已连接到仪器:%s\n',id);%打印仪器 ID号
又例如创建通过串口连接的NI仪器对象,假设设备地址是'ASRL1::INSTR':
vs = visa('ni','ASRL1::INSTR');%创建仪器对象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')
所有的虚拟仪器对象操作都可以视为一个文件进行打开、关闭、读写操作
-
-
-
-
-
-
fopen(vs);%打开仪器对象fprintf(vs,'SCPI Command');%标准输出fscanf(vs,'format',...);%标准输入fread(vs,size,precision);%二进制读fwrite(vs,data,precision);%二进制写fclose(vs);%关闭仪器对象
不过serial/visa等接口函数比较老了,新版的MATLAB即将取消它们,替换成了serialport, visadev等仪器对象,例如:
-
-
-
usbdev = visadev("USB0::0x0699::0x036A::CU010105::0::INSTR");%创建USB虚拟仪器对象writeline(usbdev,"*IDN?");%发送SCPI指令id = readline(usbdev);%读取指令返回值
-
-
serialdev = visadev("COM1");%创建串口仪器对象id = writeread(serialdev,"*IDN?");%发送SCPI指令并读取返回值
-
serialdev = visadev("ASRL1::INSTR");
-
tcpdev = visadev("TCPIP0::169.254.2.20::inst0::INSTR");
最后给一个使用程控直流电源测晶体管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');%远程控制模式fprintf(ps,'OUTP OFF\n');%关闭输出fprintf(ps,'INST CH1\n');%选择通道1(栅压)fprintf(ps,'VOLT 2V\n');%设置电压(栅压-2V)fprintf(ps,'CURR 0.001A\n');%设置最大电流fprintf(ps,'CHAN:OUTP ON\n');%开启栅压输出pause(1);%等待栅压开启1s后再开启漏压fprintf(ps,'INST CH2\n');%选择通道2(漏压)fprintf(ps,'VOLT 0V\n');%设置电压(漏压0V)fprintf(ps,'CURR 0.1A\n');%设置最大电流fprintf(ps,'CHAN:OUTP ON\n');%开启漏压输出vgg = -2:0.1:0;%栅压扫描范围-2~0V,步进0.1Vvdd = 0:0.5:5;%漏压扫描范围0~5V,步进0.5Vvgs=zeros(length(vgg),length(vdd));%初始化栅电压测量结果vds=zeros(length(vgg),length(vdd));%初始化漏电压测量结果igs=zeros(length(vgg),length(vdd));%初始化栅电流测量结果ids=zeros(length(vgg),length(vdd));%初始化漏电流测量结果for i=1:length(vgg)%栅压扫描 fprintf(ps,'INST CH1\n');%选择通道1 fprintf(ps,'VOLT %fV\n',abs(vgg(i)));%设置栅压 fprintf(ps,'INST CH2\n');%选择通道2 for j=1:length(vdd)%漏压扫描 fprintf(ps,'VOLT %sV\n',vdd(j));%设置漏压 fprintf(ps,'MEAS:VOLT? ALL\n');%测量三个通道实际输出电压 dat=fscanf(ps,'%E, %E, %E');%读回三个通道实际输出电压 vgs(i,j)=dat(1);%CH1是vgs vds(i,j)=dat(2);%CH2是vds fprintf(ps,'MEAS:CURR? ALL\n');%测量三个通道实际输出电流 dat=fscanf(ps,'%E, %E, %E');%读回三个通道实际输出电流 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');%先关漏压pause(0.5);%等待0.5sfprintf(ps,'INST CH1\n');fprintf(ps,'CHAN:OUTP OFF\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应用技巧(12)——向量、总线、线束、迭代的用法
-
理论上OIP3究竟比P1dB高多少?
-
终于知道为什么OIP3比P1dB高10dB了
-
ADS应用技巧(11)——将多个s2p文件合并成一个支持参数扫描的mdf文件
-
ADS应用技巧(10)——将多个s2p文件合并成一个多端口的snp文件
关注本公众号