玻尔贴温度控制VB程序_第1页
玻尔贴温度控制VB程序_第2页
玻尔贴温度控制VB程序_第3页
玻尔贴温度控制VB程序_第4页
玻尔贴温度控制VB程序_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1. a/d采集木次试验主要使用研华pcl812pg板卡的12位的a/d采集通道进行数据的采集,通道为1, 跳线设置为5v,使用的温度传感型号为lm35,其工作电压为(4-20) v,测虽温度范围为 0-100°c,其输出的电压每升高1°c,输出电压增加10mvo pcl812pg板卡通过口身的a/d采 集通道,将经过放大电路放大的模拟电压信号转化为12为的数字信号,通过板卡的自身携带 点的函数可以读取具电压值转化为十进制数存储。设计的vb界面和vb代码如下:鬥 analog in put demo: select in put deviceselect a device

2、from lististdevicerun.exit select a module ktmoduleinput channel .hannevoltage range| istvoltagerangeprivate sub cmdrun_click()dim tempnum as integer tempnum = lstvoltagerange.listlndexaictrmode = lpdevconhg_ai.usgainctrmodeipaiconfig.daschan = lstchanncl.listlndcxr gain code no use for adam seriesi

3、f gnnumofsubdevices = 0 thenipaiconfig.dasgain = lpdevfeatures.glgainlist(tempnum).usgaincdeend iferrcde = drv_aiconfig(devicehandle, ipaiconfig) if (errcde <> 0) thendrv_geterrormessage errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, "error!) exit subend if frmrunn.showfrmdevsel.hi

4、detimer 1 = trueend subprivate sub form_load()dim gnnumofdcviccs as integerdim noutentries as integerdim i, ii as integerdim tt as longdim tempstr as stringbrun = false'add type of pc laboratory cardtt = drv_getaddress(devicelist()errcdc = drv_dcviccgctlist(tt, maxentrics, noutentries)if (errcde

5、 <> 0) thendrv_geterrormessage errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, ”error!”)exit subend if'return the number of devices which you install in the system usingr device installationerrcde = drv_devicegetnumoflist(gnnumofdevices)if (errcdc <> 0) thendrv_geterrormessage

6、errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, herror!u)exit subend iffor i = 0 to (gnnumoldevices - 1)tempstr 二""for ii = 0 to maxdevnamelentempstr = tempstr + chr(devicelist(i).szdevicename(ii)next iiistdevice.additem tempstrnext ilabmodule.enabled = falselstmodulc.enablcd = false

7、labchannel.enabled = falseistchannel.enabled = falselabvoltagerange.enabled = falselstvoltagerange.enabled = false'labexpchl.enabled = falseistexpchlenabled = false'labthermocouple.e nabled = falseistthcrmocoupiablcd = false emdrun.enabled = falseend subprivate sub lstdevice_click()dim i, ii

8、 as integerdim tempnum as integerdim testres as booleandim noutentries as integerdim lpsubdcvicclist as longdim dwdevicenum as long'dim ipdevconfig.ai as devconf1g_aidim imaxsinglechannel as integerdim imaxdiffchanncl as integeristmodule.clearistchannel.clearistvoltagcrangc.cicar'istexpchlcl

9、earr avoid to open advantech demo cardtestres = teststr(lstdevice.text, "demo")if (testres) thenlabmodule.enabled = falselstmodule.enabled = falselabchannel.enabled = falseistchannel.enabled = falselabvoltagcrangc.enablcd = falseistvoltagerange.enabled = false'labexpchl.enabled = false

10、istexpchl.enabled = false"labthermocouple.enabled = falseistthcrmocoupiablcd = falseistchannel.additem "no use"emdrun.enabled = falseend ifif (not testres) then1 check if there is any device attatched on this com port or cangnnu mofsubdevices = devicelist(lstdevice.listindex). nnu mof

11、subdevicesif (gnnumofsubdcviccs > maxdcv) then gnnumofsubdcviccs = maxdcvend if1 retrieve the information of all installed devicesif (gnnumofsubdevices <> 0) then dwdcviccnum = dcvicclist(lstdcvicc.listindcx).dwdcviccnum ipsubdevicelist = drv_getaddress(subdevicelist(o)errcde = drv_devicege

12、tsublist(dwdevicenum, ipsubdevicelist, gnnumofsubdevices, noutentries)if (errcde <> 0) thendrv_gcterrormcssagc errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, nerror!u)exit subend iffor i = 0 to (gnnumofsubdevices 1) tcmpstr = ”“for ii = 0 to maxdevnamelentempstr = tempstr + chr(subdevic

13、elist(i).szdevicename(ii)next iilstmodule.addltem tempstrnext iistmodule.enabled = truelabmodule.enabled = trueend if'data acquisition & control or digital i/o cardif (gnn umo fs ubde vices = 0) thendwdevicenum = devicelist(lstdevice.listindex).dwdevicenumerrcde = drv_deviceopen(dwdevicenum,

14、 devicehandle)if (errcde <> 0) thendrv_gcterrormcssagc errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, nerror!u)exit subelsebrun = trueend ifptdevgetfeatures.buffer = drv_getaddress(lpdevfeatures)errcde = drv_devicegetfeatures(devicehandle, ptdevgetfeatures)if (errcde <> 0) thendrv

15、_gcterrormcssagc errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, nerror!u)exit subend if ptaigetconfig.buffer = drv_getaddress(lpdevconfig_ai)errcde = drv_aigetconfig(devicehandle, ptaigetconfig)if (errcde <> 0) thendrv_geterrormessage errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly

16、, ”error!”)exit subend ifaictrmode = lpdevconflg_al.usgainctrmodedim boardid as integerboardid = ipdevconfig.ai.dwboardldget the max channel rmmbertempnum = lpdevfeatures.usmaxaisiglchlimaxsinglechannel = lpdevfeatures.usmaxaisiglchlimaxdiffchanncl = ipdcvfcaturcs.usmaxaidiffchlif imaxsinglechannel

17、> imaxdiffchannel thentempnum = imaxsinglechannelelsetempnum = imaxdiffchannclend ifif (tempnum > 0) thenfor i = 0 to (tempnum 1)tcmp$ = "chan#" + str(i)istchanneladditem temps, inext iistchannel.text = lstchannel.list(o)labchannel.enabled = truelstchanncl.enablcd = trueend if1 add g

18、ain code listtempnum = lpde vfeatures. usn umgainif (lpdcvfcaturcs.usnumgain > 0) thenfor i = oto (lpdevfeatures.usnumgain 1)tempstr = ,n'for ii = 0 to 15tempstr = tempstr + chr(lpdevfeatures.glgainlist(i).szgainstr(ii)next iiistvoltagerange. additem tempstrnext iistvoltagcrangc.tcxt = istvol

19、tagcrangc.list(o) lstvoltagcrangc.enablcd = true labvoltagerange.enabled = trueend ifcmdrun.enabled = trueend ifend ifend subprivate sub lstmodule_click()dim i, ii as integerdim dwdevicenum as longdim tempnum as integeristchannel.clearlstvoltagcrangc.clcar1 open com device or can device dwdevicenum

20、= subdevicelist(lstmodule.listindex).dwdevicenum errcde = drv_deviceopen(dwdevicenum, devicehandle)if (errcde <> 0) thendrv_gcterrormcssagc errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, herror!m)exit subelsebrun = trueend ifptdevgetfeatures.buffer = drv_getaddress(lpdevfeatures)errcde

21、= drv_devicegetfeatures(devicehandle, ptdevgetfeatures)if (errcde <> 0) thendrv_gcterrormcssagc errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, herror!h)exit subend if add analog input channel itemptaigetconfig.buffer = drv_getaddress(lpdevconfig_ai) errcde = drv_aigetconfig(devicehandle

22、, ptaigetconfig) if (errcde <> 0) thendrv_geterrormessage errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, herror!n)exit subend iftcmpnum = lpdcvfcaturcs.usmaxaisiglchlif (tempnum > 0) thenfor i = 0 to (tempnum - 1) temp$ = "chan#" + str(i) lstchannel.addltem temps, inext iis

23、tchanneltext = lstchannel.list(o) labchannel.enabled = true lstchannel.enabled = trueend if'add gain code listtempnum = lpdevfeatures.usnumgainif (lpdevfeatures.usnumgain > 0) thenfor i = 0 to (lpdevfeatures.usnumgain - 1) tcmpstr = ”“for ii = 0 to 15tempstr = tempstr + chr(lpdevfeatures.glga

24、inlist(i).szgainstr(ii) next iilstvoltagerange.addltem tempstrnext iistvoltagerange.text = lstvoltagerange.list(o)istvoltagerange.enabled = true lab voltagerange.enabled = trueend ifcmdrun.enabled = trueend subprivate sub timer l_timer()dim voltage as singleaivolin.chan = ipaiconfig.daschanaivolin.g

25、ain = ipaiconfig.dasgainaivolin.trigmode = 0aivolin.voltage = drv_getaddress(voltage)errcde = drv_aivoltagein(devicehandle, aivolin)if (errcde <> 0) thendrv_geterrormessage errcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, herror!u)exit subend ifupdatevalue (voltage)'采集温度传感器输出的电压值end s

26、ubprivate sub updatevalue(fvalue as single)m = format(fvalue, "#0.0000")end sub2. pwm波输出控制铝板的温度主耍有珀尔贴进行降温,而利用外界坏境的温度进行升温,要对铝板的温度 进行控制就必须控制珀尔贴的工作状态。为了进行更精准的控制,我们再次使用研华 pci 1760板卡输h1pwm波对珀尔贴进行控制。木实验采用pid控制的方法对铝板温度进行精 确的控制,通过建立的数学模型,计算jiipwm波的占空比对珀尔贴进行控制。设计的vb界 面和vb主要代码如下:dim m_cxpcctcm as si

27、ngledim curerror as singledim preerror as singledim lasterror as singledim sumerror as singledim dutycycle as singledim t as singledim kp as singledim ki as singledim kd as singledim ptdevfeatures as devfeatures' structure for device featuresdim ptdevgetfeatures as pt_devicegetfeaturesdim ptcoun

28、terpwmsetting as pt_counterpwmsettingpublic de vicenum as longpublic devicehandle as longpublic errornum as longpublic brun as booleandim b as integerprivate declare sub kcybd_cvcnt lib huscr32" (byvai bvk as byte, by vai bscan as byte, by vai dwflags as long, byvai dwextralnfo as long)private

29、const keyeventf_keyup = &h2private sub command l_click()timer 1.enabled = trueend subprivate sub cominand2_click()drv_deviceclose devicehandlefrmrunn.hidefrmdevsel.showfrmdcvscl.cmdexit.sctfocusend subprivate sub command3_ciick()frmdevsel.showcall form_activateend subprivate sub cominand4_click(

30、)autoredraw = truedim description as stringdescription = string(8(), vbnullchar)errornum = drv_scicctdcvicc(hwnd, false, dcviccnum, description)end subprivate sub command5_click()end subprivate sub form_load()b = 0brun = falselasterror = 0sumerror = 0picture 1 autoredraw = truepicture l.backcolor =

31、qbcolor(7)text 1 .text"text2.text = ”“tex t3 .text = ,httcxt4.tcxt = ”“tcxt5.tcxt=,ntext6.text =""text8.text =""text9.text = ,ntimcr2.enabled = truetimer 1.enabled = falsetimer3. enabled = falsetimer4.enabled = trueend subprivate sub form_activatc()dim x as integerdim y as i

32、ntegerpicture 1.cispicture l.currentx = 15()picture l.currcnty = 350picture lprint ”温度/°c“picture 1 .currentx = 11500picture 1.current y = 4200picture 1.print ”时间/min”picture 1.scale (-150, 60)-(7400, -10)'定义坐标系 '画坐标系picture 1 .forecolor = rgb(200, 5, 200)picture l.drawwidth = 1picture

33、1 .drawstyle = 0picture 1.line (0, 50)-(0, 0)for i = 240 to 7200 step 240picture 1 .drawstyle = 2picture 1.line (i, 50)-(i, 0)picture 1 .print i / 240next ipicture 1 .drawstyle = 0picture 1.line (7200, 0)-(0, 0)picture 1.print 0for j = 5() to 1() step-1()picture 1.drawstyle = 2picture 1.line (7200,

34、j)-(oj)picture i .print jnext j'価温度坐标点(以10度为1个单位)picture 1 .forccolor = rgb(0, 0, 255)picture 1 .drawwidth = 4for y = 0 to 50 step 10picturel.psct (0, y)ncxty'画时间坐标点(以1分钟为1个单位)picture 1 .drawwidth = 4for x = 0 to 7200 step 240picturel.pset (x, 0)ncxtxend subprivate sub text8_change()end subp

35、rivate sub timerl_timer()picture 1.drawwidth = 1.5ifb> 7200 thenkeybd_event 18, 0, 0, 0kcybd_cvcnt vbkcysnapshot, 0&, 0&, 0&doeventskeybd.event 1& 0, keyeventf_keyup, 0savepicture clipboard.getdata, hd:abc.bmpnpicture l.clscall form_activatcb = 0end iftext3.text = format(m, ”#0.00

36、00”)x = ba = my = a/5.28 * 100'将采集的电压值转化为对应的温度值text 1.text = format(y, ”#0.0000“)picturel.pset (x, y)b = b + 1end subprivate sub timer2_timer()label6.caption 二 datelabel2.capti on = timeend subprivate sub picture 1 _mouscdown(button as integer, shift as integer, x as single, y assingle)if button

37、 = 1 thenif y >= 0 and y<= 100 and x >= 0 and x <= 7200 thentext2.text = format(y, ”#0.0000”)elsetext2.text = ”越界"end ifend ifend subprivate sub form_unload(cancel as integer)frmdevsel.showend subprivate sub timcr3_timcr()errornum = drv_deviceopen(devicenum, devicehandle)if checkerr

38、or(errornumi) <> 0 thenexit subend if ptdevgetfeatures.buffer = drv_getaddress(ptdevfeatures) 'ptdevgetfeatures.size = sizeof(ptdevfeatures)errornum = drv_devicegetfeatures(devicehandle, ptdevgetfeatures) if chcckerror(errornum) <> 0 thendrv_deviceclose (devicehandle)exit sub,选择0通道,输

39、出pwm波周期为100ms ,cun为占空比"00后的数值end ifptcounterpwmsetting.port = 0 ptcounterpwmsetting.period = 100 ptcounterpwmsetting.hiperiod = cur ptcounterpwmsetting.gatemode = 0 ptcounterpwmsetting.outcount = 100'enable channel 0 pwmerrornum = drv_countcrpwmsctting(dcvicchandlc, ptcountcrpwmsctting)if c

40、heckerror(errornum) <> 0 thendrv_deviceclose (devicehandle)exit subend if* start channel 0 pwmerrornum = drv_counterpwmenable(devicehandle, 1)if checkerror(errornum) <> 0 thendrv_deviceclose (devicehandle)exit subend ifbrun = trueend subpublic function checkerror(byval lerrcde as long) as booleandim szerrmsg as string * 8()if (lerrcde <> 0) thendrv_geterrormessage lerrcde, szerrmsgresponse = msgbox(szerrmsg, vbokonly, "error!")chcckerror = trueelsecheckerror =

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论