Data Acquisition in LabVIEW PAnS-L11L8 PALvC8SLn, 2013.08.16
2
Preface 1hls LuLorlal explalns Lhe baslc concepLs of a uaLa AcqulslLlon ln LabvlLW. ?ou flnd Lhls documenL and addlLlonal resources onllne aL: hLLp://home.hlL.no/~hansha/?LuLorlal=daq
?ou should have some baslc knowledge abouL LabvlLW, e.g., Lhe lnLroducLlon Lo LabvlLW" LuLorlal. 1hls documenL ls avallable for download aL hLLp://home.hlL.no/~hansha/. lor more lnformaLlon abouL LabvlLW, vlslL: hLLp://home.hlL.no/~hansha/?page=labvlew. ln addlLlon Lo LabvlLW, you wlll need Lo lnsLall Lhe drlver NI-DAmx.
3.1.1 uAC AsslsLanL .................................................................................................................. 18 3.2 SlmulaLlng a uAC uevlce ......................................................................................................... 18 6 uAC uevlces ................................................................................................................................... 20 6.1 erformlng Analog-Lo-ulglLal Converslon ............................................................................... 21 6.2 erformlng ulglLal-Lo-Analog Converslon ............................................................................... 21 6.3 uslng CounLers ........................................................................................................................ 21 6.4 uslng ulglLal l/C ...................................................................................................................... 21 7 nl uS8-6008 .................................................................................................................................... 23 7.1 ConnecL nl uS8-6008 Lo Lhe C .............................................................................................. 23 7.1.1 1esLlng Lhe uS8-6008 ln MAx .......................................................................................... 24 7.2 uslng nl uS8-6008 ln LabvlLW ............................................................................................... 30 7.3 uAC AsslsLanL .......................................................................................................................... 31 7.3.1 Analog lnpuL ..................................................................................................................... 31 7.3.2 Analog CuLpuL .................................................................................................................. 38 8 Logglng Lo llle ................................................................................................................................. 43 8.1 WrlLlng Lo MeasuremenL llle .................................................................................................. 43 8.2 8ead from MeasuremenL llle ................................................................................................. 46
1
1 Introduction to LabVIEW LabvlLW (shorL for LaboraLory VlrLual InsLrumenLaLlon Lnglneerlng Workbench) ls a plaLform and developmenL envlronmenL for a vlsual programmlng language from naLlonal lnsLrumenLs. 1he graphlcal language ls named "C". Crlglnally released for Lhe Apple MaclnLosh ln 1986, LabvlLW ls commonly used for daLa acqulslLlon, lnsLrumenL conLrol, and lndusLrlal auLomaLlon on a varleLy of plaLforms lncludlng MlcrosofL Wlndows, varlous flavors of unlx, Llnux, and Mac CS x. vlslL naLlonal lnsLrumenLs aL www.nl.com. 1he code flles have Lhe exLenslon .vl", whlch ls an abbrevlaLlon for vlrLual lnsLrumenL". LabvlLW offers loLs of addlLlonal Add-Cns and 1oolklLs. 1.1 Dataflow programming 1he programmlng language used ln LabvlLW, also referred Lo as C, ls a daLaflow programmlng language. LxecuLlon ls deLermlned by Lhe sLrucLure of a graphlcal block dlagram (Lhe Lv-source code) on whlch Lhe programmer connecLs dlfferenL funcLlon-nodes by drawlng wlres. 1hese wlres propagaLe varlables and any node can execuLe as soon as all lLs lnpuL daLa become avallable. Slnce Lhls mlghL be Lhe case for mulLlple nodes slmulLaneously, C ls lnherenLly capable of parallel execuLlon. MulLl-processlng and mulLl-Lhreadlng hardware ls auLomaLlcally explolLed by Lhe bullL-ln scheduler, whlch mulLlplexes mulLlple CS Lhreads over Lhe nodes ready for execuLlon. 1.2 Graphical programming LabvlLW Lles Lhe creaLlon of user lnLerfaces (called fronL panels) lnLo Lhe developmenL cycle. LabvlLW programs/subrouLlnes are called vlrLual lnsLrumenLs (vls). Lach vl has Lhree componenLs: a block dlagram, a fronL panel, and a connecLor panel. 1he lasL ls used Lo represenL Lhe vl ln Lhe block dlagrams of oLher, calllng vls. ConLrols and lndlcaLors on Lhe fronL panel allow an operaLor Lo lnpuL daLa lnLo or exLracL daLa from a runnlng vlrLual lnsLrumenL. Powever, Lhe fronL panel can also serve as a programmaLlc lnLerface. 1hus a vlrLual lnsLrumenL can elLher be run as a program, wlLh Lhe fronL panel servlng as a user lnLerface, or, when dropped as a node onLo Lhe block dlagram, Lhe fronL panel deflnes Lhe lnpuLs and ouLpuLs for Lhe glven node Lhrough Lhe connecLor pane. 1hls lmplles each vl can be easlly LesLed before belng embedded as a subrouLlne lnLo a larger program.
2 lnLroducLlon Lo LabvlLW Tutorial: Data Acquisition in LabVIEW
1he graphlcal approach also allows non-programmers Lo bulld programs slmply by dragglng and dropplng vlrLual represenLaLlons of lab equlpmenL wlLh whlch Lhey are already famlllar. 1he LabvlLW programmlng envlronmenL, wlLh Lhe lncluded examples and Lhe documenLaLlon, makes lL slmple Lo creaLe small appllcaLlons. 1hls ls a beneflL on one slde, buL Lhere ls also a cerLaln danger of underesLlmaLlng Lhe experLlse needed for good quallLy "C" programmlng. lor complex algorlLhms or large-scale code, lL ls lmporLanL LhaL Lhe programmer possess an exLenslve knowledge of Lhe speclal LabvlLW synLax and Lhe Lopology of lLs memory managemenL. 1he mosL advanced LabvlLW developmenL sysLems offer Lhe posslblllLy of bulldlng sLand-alone appllcaLlons. lurLhermore, lL ls posslble Lo creaLe dlsLrlbuLed appllcaLlons, whlch communlcaLe by a cllenL/server scheme, and are Lherefore easler Lo lmplemenL due Lo Lhe lnherenLly parallel naLure of C-code. 1.3 Benefits Cne beneflL of LabvlLW over oLher developmenL envlronmenLs ls Lhe exLenslve supporL for accesslng lnsLrumenLaLlon hardware. urlvers and absLracLlon layers for many dlfferenL Lypes of lnsLrumenLs and buses are lncluded or are avallable for lncluslon. 1hese presenL Lhemselves as graphlcal nodes. 1he absLracLlon layers offer sLandard sofLware lnLerfaces Lo communlcaLe wlLh hardware devlces. 1he provlded drlver lnLerfaces save program developmenL Llme. 1he sales plLch of naLlonal lnsLrumenLs ls, Lherefore, LhaL even people wlLh llmlLed codlng experlence can wrlLe programs and deploy LesL soluLlons ln a reduced Llme frame when compared Lo more convenLlonal or compeLlng sysLems. A new hardware drlver Lopology (uACmx8ase), whlch conslsLs malnly of C-coded componenLs wlLh only a few reglsLer calls Lhrough nl MeasuremenL Pardware uuk (urlver uevelopmenL klL) funcLlons, provldes plaLform lndependenL hardware access Lo numerous daLa acqulslLlon and lnsLrumenLaLlon devlces. 1he uACmx8ase drlver ls avallable for LabvlLW on Wlndows, Mac CS x and Llnux plaLforms.
3
2 Introduction to Data Acquisition 1hls chapLer explalns Lhe baslc concepLs of uslng uAC ln LabvlLW. 1oplcs: lnLroducLlon Lo uAC - uaLa AcqulslLlon MAx - MeasuremenL and AuLomaLlon Lxplorer nl-uACmx LabvlLW ls very powerful when lL comes Lo creaLlng uAC appllcaLlons. LabvlLW lncludes a seL of vls LhaL leL you conflgure, acqulre daLa from, and send daLa Lo uAC devlces. CfLen, one devlce can perform a varleLy of funcLlons, such as analog-Lo-dlglLal (A/u) converslon, dlglLal-Lo-analog (u/A) converslon, dlglLal l/C, and counLer/Llmer operaLlons. Lach devlce supporLs dlfferenL uAC and slgnal generaLlon speeds. Also, each uAC devlce ls deslgned for speclflc hardware, plaLforms and operaLlng sysLems. naLlonal lnsLrumenLs, Lhe lnvenLor of LabvlLW, also make uAC devlces, so Lhe lnLegraLlon wlLh Lhe uAC devlces from nl and Lhe LabvlLW sofLware ls seamless and makes lL easy Lo do l/C operaLlons from Lhe LabvlLW envlronmenL. 2.1 Introduction to DAQ - Data Acquisition 1he purpose of daLa acqulslLlon ls Lo measure an elecLrlcal or physlcal phenomenon such as volLage, currenL, LemperaLure, pressure, or sound. C-based daLa acqulslLlon uses a comblnaLlon of modular hardware, appllcaLlon sofLware, and a compuLer Lo Lake measuremenLs. Whlle each daLa acqulslLlon sysLem ls deflned by lLs appllcaLlon requlremenLs, every sysLem shares a common goal of acqulrlng, analyzlng, and presenLlng lnformaLlon. uaLa acqulslLlon sysLems lncorporaLe slgnals, sensors, acLuaLors, slgnal condlLlonlng, daLa acqulslLlon devlces, and appllcaLlon sofLware. So summlng up, uaLa AcqulslLlon ls Lhe process of: Acqulrlng slgnals from real-world phenomena ulglLlzlng Lhe slgnals Analyzlng, presenLlng and savlng Lhe daLa 4 lnLroducLlon Lo uaLa AcqulslLlon Tutorial: Data Acquisition in LabVIEW
1he uAC sysLem has Lhe followlng parLs lnvolved, see llgure:
1he parLs are: hyslcal lnpuL/ouLpuL slgnals uAC devlce/hardware urlver sofLware ?our sofLware appllcaLlon (AppllcaLlon sofLware) lor an lnLroducLlon Lo uaLa AcqulslLlon, see Lhls webcasL: hLLp://zone.nl.com/wv/app/doc/p/ld/wv-169 2.1.1 Physical input/output signals A physlcal lnpuL/ouLpuL slgnal ls Lyplcally a volLage or currenL slgnal. A volLage slgnal can Lyplcally be a 0-3v slgnal, whlle a currenL slgnal can Lyplcally be a 4-20mA slgnal. 2.1.2 DAQ device/hardware uAC hardware acLs as Lhe lnLerface beLween Lhe compuLer and Lhe ouLslde world. lL prlmarlly funcLlons as a devlce LhaL dlglLlzes lncomlng analog slgnals so LhaL Lhe compuLer can lnLerpreL Lhem A uAC devlce (uaLa AcqulslLlon Pardware) usually has Lhese funcLlons: Analog lnpuL Analog ouLpuL ulglLal l/C CounLer/Llmers We have dlfferenL uAC devlces, such as: Desktop uAC devlces" where you need Lo plug a Cl uAC board lnLo your compuLer. 1he sofLware ls runnlng on a compuLer. 3 lnLroducLlon Lo uaLa AcqulslLlon Tutorial: Data Acquisition in LabVIEW
ortab|e uAC devlces" for connecLlon Lo Lhe uS8 porL, Wl-ll connecLlons, eLc. 1he sofLware ls runnlng on a compuLer D|str|buted uAC devlces" where Lhe sofLware ls developed on your compuLer and Lhen laLer downloaded Lo Lhe dlsLrlbuLed uAC devlce.
2.1.3 Driver software urlver sofLware ls Lhe layer of sofLware for easlly communlcaLlng wlLh Lhe hardware. lL forms Lhe mlddle layer beLween Lhe appllcaLlon sofLware and Lhe hardware. urlver sofLware also prevenLs a programmer from havlng Lo do reglsLer-level programmlng or compllcaLed commands ln order Lo access Lhe hardware funcLlons. urlver sofLware from naLlonal lnsLrumenLs: nl-uACmx nl-uACmx 8ase 1he DA Ass|stant, lncluded wlLh nl-uACmx, ls a graphlcal, lnLeracLlve gulde for conflgurlng, LesLlng, and acqulrlng measuremenL daLa. WlLh a slngle cllck, you can even generaLe code based on your conflguraLlon, maklng lL easler and fasLer Lo develop complex operaLlons. 8ecause uAC AsslsLanL ls compleLely menu-drlven, you wlll make fewer programmlng errors and drasLlcally decrease Lhe Llme from seLLlng up your uAC sysLem Lo Laklng your flrsL measuremenL. nl-uACmx 8ase offers a subseL of nl-uACmx funcLlonallLy on Wlndows and Llnux, Mac CS x, Wlndows Moblle and Wlndows CL. 6 lnLroducLlon Lo uaLa AcqulslLlon Tutorial: Data Acquisition in LabVIEW
2.1.4 Your software application (Application software) AppllcaLlon sofLware adds analysls and presenLaLlon capablllLles Lo Lhe drlver sofLware. ?our sofLware appllcaLlon normally does such Lasks as: 8eal-Llme monlLorlng uaLa analysls uaLa logglng ConLrol algorlLhms Puman machlne lnLerface (PMl) ln order Lo creaLe your uAC appllcaLlon you need a programmlng developmenL Lool, such as LabvlLW. 2.2 MAX Measurement and Automation Explorer MeasuremenL & AuLomaLlon Lxplorer (MAx) provldes access Lo your naLlonal lnsLrumenLs devlces and sysLems. WlLh MAx, you can: Conflgure your naLlonal lnsLrumenLs hardware and sofLware CreaLe and edlL channels, Lasks, lnLerfaces, scales, and vlrLual lnsLrumenLs LxecuLe sysLem dlagnosLlcs vlew devlces and lnsLrumenLs connecLed Lo your sysLem updaLe your naLlonal lnsLrumenLs sofLware ln addlLlon Lo Lhe sLandard Lools, MAx can expose lLem-speclflc Lools you can use Lo conflgure, dlagnose, or LesL your sysLem, dependlng on whlch nl producLs you lnsLall. As you navlgaLe Lhrough MAx, Lhe conLenLs of Lhe appllcaLlon menu and Loolbar change Lo reflecL Lhese new Lools. 7 lnLroducLlon Lo uaLa AcqulslLlon Tutorial: Data Acquisition in LabVIEW
2.3 NI-DAQmx 1he nl-uACmx urlver sofLware ls Lhe layer of sofLware for easlly communlcaLlng wlLh Lhe hardware. lL forms Lhe mlddle layer beLween Lhe appllcaLlon sofLware and Lhe hardware. urlver sofLware also prevenLs a programmer from havlng Lo do reglsLer-level programmlng or compllcaLed commands ln order Lo access Lhe hardware funcLlons. 1he uACmx paleLLe ln LabvlLW: 8 lnLroducLlon Lo uaLa AcqulslLlon Tutorial: Data Acquisition in LabVIEW
1he uAC AsslsLanL" ls an easy way Lo sLarL uslng Lhe uAC feaLures ln LabvlLW. We wlll learn more abouL Lhe uAC AsslsLanL" ln a laLer chapLer. 2.3.1 DAQ Assistant 1he DA Ass|stant, lncluded wlLh nl-uACmx, ls a graphlcal, lnLeracLlve gulde for conflgurlng, LesLlng, and acqulrlng measuremenL daLa. WlLh a slngle cllck, you can even generaLe code based on your conflguraLlon, maklng lL easler and fasLer Lo develop complex operaLlons. 8ecause uAC AsslsLanL ls compleLely menu-drlven, you wlll make fewer programmlng errors and drasLlcally decrease Lhe Llme from seLLlng up your uAC sysLem Lo Laklng your flrsL measuremenL. 2.4 NI USB-6008 nl uS8-6008 ls a slmple and low-cosL mulLlfuncLlon l/C devlce from naLlonal lnsLrumenLs.
9 lnLroducLlon Lo uaLa AcqulslLlon Tutorial: Data Acquisition in LabVIEW
1he devlce has Lhe followlng speclflcaLlons: 8 analog lnpuLs (12-blL, 10 kS/s) 2 analog ouLpuLs (12-blL, 130 S/s) 12 dlglLal l/C uS8 connecLlon, no exLra power-supply neeeded CompaLlble wlLh LabvlLW, LabWlndows/Cvl, and MeasuremenL SLudlo for vlsual SLudlo .nL1 nl-uACmx drlver sofLware 1he nl uS8-6008 ls well sulLed for educaLlon purposes due Lo lLs small slze and easy uS8 connecLlon.
10
3 Physical input/output signals uaLa acqulslLlon lnvolves gaLherlng slgnals from measuremenL sources and dlglLlzlng Lhe slgnal for sLorage, analysls, and presenLaLlon on a C. uaLa acqulslLlon (uAC) sysLems come ln many dlfferenL C Lechnology forms for greaL flexlblllLy when chooslng your sysLem. SclenLlsLs and englneers can choose from Cl, xl, Cl Lxpress, xl Lxpress, CMClA, uS8, Wlreless and LLherneL daLa acqulslLlon for LesL, measuremenL, and auLomaLlon appllcaLlons. 1here are flve componenLs Lo be consldered when bulldlng a baslc uAC sysLem 1ransducers and sensors Slgnals Slgnal condlLlonlng uAC hardware urlver and appllcaLlon sofLware ln Lhls chapLer we focus on 1ransducers, sensors and Slgnals. 3.1 Transducers uaLa acqulslLlon beglns wlLh Lhe physlcal phenomenon Lo be measured. 1hls physlcal phenomenon could be he LemperaLure of a room, Lhe lnLenslLy of a llghL source, Lhe pressure lnslde a chamber, Lhe force applled Lo an ob[ecL, or many oLher Lhlngs. An effecLlve uAC sysLem can measure all of Lhese dlfferenL phenomena.
A Lransducer ls a devlce LhaL converLs a physlcal phenomenon lnLo a measurable elecLrlcal slgnal, such as volLage or currenL. 1he ablllLy of a uAC sysLem Lo measure dlfferenL phenomena depends on Lhe Lransducers Lo converL Lhe physlcal phenomena lnLo slgnals measurable by Lhe uAC hardware. 1ransducers are synonymous wlLh sensors ln uAC sysLems. 1here are speclflc Lransducers for many dlfferenL appllcaLlons, such as measurlng LemperaLure, pressure, or fluld flow. 8elow we see some common phenomena and Lhe Lransducers used Lo measure Lhem. henomenon 1ransducer 1emperaLure 1hermocouple, 81u, 1hermlsLor 11 hyslcal lnpuL/ouLpuL slgnals Tutorial: Data Acquisition in LabVIEW
ulfferenL Lransducers have dlfferenL requlremenLs for converLlng phenomena lnLo a measurable slgnal. Some Lransducers may requlre exclLaLlon ln Lhe form of volLage or currenL. CLher Lransducers may requlre addlLlonal componenLs and even reslsLlve neLworks Lo produce a slgnal. 8efer Lo nl.com/sensors for more lnformaLlon on Lransducers. 3.2 Signals 1he approprlaLe Lransducers converL physlcal phenomena lnLo measurable slgnals. Powever, dlfferenL slgnals need Lo be measured ln dlfferenL ways. lor Lhls reason, lL ls lmporLanL Lo undersLand Lhe dlfferenL Lypes of slgnals and Lhelr correspondlng aLLrlbuLes. Slgnals can be caLegorlzed lnLo Lwo groups: Analog ulglLal 3.2.1 Analog Signals Analog lnpuL ls Lhe process of measurlng an analog slgnal and Lransferrlng Lhe measuremenL Lo a compuLer for analysls, dlsplay, or sLorage. An analog slgnal ls a slgnal LhaL varles conLlnuously. Analog lnpuL ls mosL commonly used Lo measure volLage or currenL. ?ou can use many Lypes of devlces Lo perform analog lnpuL, such as mulLlfuncLlon uAC (MlC) devlces, hlgh-speed dlglLlzers, dlglLal mulLlmeLers, and uynamlc Slgnal AcqulslLlon (uSA) devlces. 12 hyslcal lnpuL/ouLpuL slgnals Tutorial: Data Acquisition in LabVIEW
An analog slgnal can be aL any value wlLh respecL Lo Llme. A few examples of analog slgnals lnclude volLage, LemperaLure, pressure, sound, and load. 1he Lhree prlmary characLerlsLlcs of an analog slgnal ls: Level Shape lrequency
Leve| 8ecause analog slgnals can Lake on any value, Lhe level glves vlLal lnformaLlon abouL Lhe measured analog slgnal. 1he lnLenslLy of a llghL source, Lhe LemperaLure ln a room, and Lhe pressure lnslde a chamber are all examples LhaL demonsLraLe Lhe lmporLance of Lhe level of a slgnal. When measurlng Lhe level of a slgnal, Lhe slgnal generally does noL change qulckly wlLh respecL Lo Llme. 1he accuracy of Lhe measuremenL, however, ls very lmporLanL. A uAC sysLem LhaL ylelds maxlmum accuracy should be chosen Lo ald ln analog level measuremenLs.
13 hyslcal lnpuL/ouLpuL slgnals Tutorial: Data Acquisition in LabVIEW
Shape Some slgnals are named afLer Lhelr speclflc shape - slne, square, sawLooLh, and Lrlangle. 1he shape of an analog slgnal can be as lmporLanL as Lhe level, because by measurlng Lhe shape of an analog slgnal, you can furLher analyze Lhe slgnal, lncludlng peak values, uC values, and slope. Slgnals where shape ls of lnLeresL generally change rapldly wlLh respecL Lo Llme, buL sysLem accuracy ls sLlll lmporLanL. 1he analysls of hearLbeaLs, vldeo slgnals, sounds, vlbraLlons, and clrculL responses are some appllcaLlons lnvolvlng shape measuremenLs. Irequency All analog slgnals can be caLegorlzed by Lhelr frequency. unllke Lhe level or shape of Lhe slgnal, frequency cannoL be dlrecLly measured. 1he slgnal musL be analyzed uslng sofLware Lo deLermlne Lhe frequency lnformaLlon. 1hls analysls ls usually done uslng an algorlLhm known as Lhe lourler Lransform.
When frequency ls Lhe mosL lmporLanL plece of lnformaLlon, lL ls lmporLanL Lo conslder lncludlng boLh accuracy and acqulslLlon speed. AlLhough Lhe acqulslLlon speed for acqulrlng Lhe frequency of a slgnal ls less Lhan Lhe speed requlred for obLalnlng Lhe shape of a slgnal, Lhe slgnal musL sLlll be acqulred fasL enough LhaL Lhe perLlnenL lnformaLlon ls noL losL whlle Lhe analog slgnal ls belng acqulred. 1he condlLlon LhaL sLlpulaLes Lhls speed ls known as Lhe nyqulsL Sampllng 1heorem. Speech analysls, LelecommunlcaLlon, and earLhquake analysls are some examples of common appllcaLlons where Lhe frequency of Lhe slgnal musL be known. 3.3 Digital Signals A dlglLal slgnal cannoL Lake on any value wlLh respecL Lo Llme. lnsLead, a dlglLal slgnal has Lwo posslble levels: hlgh and low. ulglLal slgnals generally conform Lo cerLaln speclflcaLlons LhaL deflne characLerlsLlcs of Lhe slgnal. ulglLal slgnals are commonly referred Lo as LranslsLor-Lo-LranslsLor loglc (11L). 11L speclflcaLlons lndlcaLe a dlglLal slgnal Lo be low when Lhe level falls wlLhln 0 Lo 0.8 v, and Lhe slgnal ls hlgh beLween 2 Lo 3 v. 1he useful lnformaLlon LhaL can be measured from a dlglLal slgnal lncludes Lhe sLaLe and Lhe raLe.
14 hyslcal lnpuL/ouLpuL slgnals Tutorial: Data Acquisition in LabVIEW
State ulglLal slgnals cannoL Lake on any value wlLh respecL Lo Llme. 1he sLaLe of a dlglLal slgnal ls essenLlally Lhe level of Lhe slgnal - on or off, hlgh or low. MonlLorlng Lhe sLaLe of a swlLch - open or closed - ls a common appllcaLlon showlng Lhe lmporLance of knowlng Lhe sLaLe of a dlglLal slgnal. kate 1he raLe of a dlglLal slgnal deflnes how Lhe dlglLal slgnal changes sLaLe wlLh respecL Lo Llme. An example of measurlng Lhe raLe of a dlglLal slgnal lncludes deLermlnlng how fasL a moLor shafL splns. unllke frequency, Lhe raLe of a dlglLal slgnal measures how ofLen a porLlon of a slgnal occurs. A sofLware algorlLhm ls noL requlred Lo deLermlne Lhe raLe of a slgnal
13
4 MAX MeasuremenL & AuLomaLlon Lxplorer (MAx) provldes access Lo your naLlonal lnsLrumenLs devlces and sysLems. WlLh MAx, you can: Conflgure your naLlonal lnsLrumenLs hardware and sofLware CreaLe and edlL channels, Lasks, lnLerfaces, scales, and vlrLual lnsLrumenLs LxecuLe sysLem dlagnosLlcs vlew devlces and lnsLrumenLs connecLed Lo your sysLem updaLe your naLlonal lnsLrumenLs sofLware ln addlLlon Lo Lhe sLandard Lools, MAx can expose lLem-speclflc Lools you can use Lo conflgure, dlagnose, or LesL your sysLem, dependlng on whlch nl producLs you lnsLall. As you navlgaLe Lhrough MAx, Lhe conLenLs of Lhe appllcaLlon menu and Loolbar change Lo reflecL Lhese new Lools.
LabvlLW lnsLalls MAx Lo esLabllsh all devlces and channel conflguraLlon parameLers. MAx reads Lhe lnformaLlon Lhe uevlce Manager records ln Lhe Wlndows 8eglsLry and asslgns a loglcal devlce number Lo each uAC devlce. ?ou use Lhe devlce number Lo refer Lo Lhe devlce ln LabvlLW. ?ou can access MAx by selecLlng 1oolsMeasuremenL & AuLomaLlon Lxplorer ln LabvlLW. 1hls dlsplays Lhe prlmary MAx wlndow.
16 MAx Tutorial: Data Acquisition in LabVIEW
8efore uslng a daLa acqulslLlon board, you musL conflrm LhaL Lhe sofLware can communlcaLe wlLh Lhe board by conflgurlng Lhe devlces. lor Wlndows, Lhe Wlndows ConflguraLlon Manager keeps Lrack of all Lhe hardware lnsLalled ln Lhe compuLer, lncludlng naLlonal lnsLrumenLs uAC devlces. 1he Wlndows ConflguraLlon Manager auLomaLlcally deLecLs and conflgures lug & lay (n) devlces. Wlndows ConflguraLlon Manager lf you have a n devlce, such as an L Serles MlC devlce, Lhe Wlndows ConflguraLlon Manager auLomaLlcally deLecLs and conflgures Lhe devlce. lf you have a non-n devlce, or legacy devlce, you musL conflgure Lhe devlce manually uslng Lhe Add new Pardware opLlon ln Lhe ConLrol anel. ?ou can verlfy Lhe Wlndows ConflguraLlon by accesslng Lhe uevlce Manager.
17
5 NI-DAQmx urlver sofLware ls Lhe layer of sofLware for easlly communlcaLlng wlLh Lhe hardware. lL forms Lhe mlddle layer beLween Lhe appllcaLlon sofLware and Lhe hardware. urlver sofLware also prevenLs a programmer from havlng Lo do reglsLer-level programmlng or compllcaLed commands ln order Lo access Lhe hardware funcLlons. urlver sofLware from naLlonal lnsLrumenLs: nl-uACmx nl-uACmx 8ase 1he DA Ass|stant, lncluded wlLh nl-uACmx, ls a graphlcal, lnLeracLlve gulde for conflgurlng, LesLlng, and acqulrlng measuremenL daLa. WlLh a slngle cllck, you can even generaLe code based on your conflguraLlon, maklng lL easler and fasLer Lo develop complex operaLlons. 8ecause uAC AsslsLanL ls compleLely menu-drlven, you wlll make fewer programmlng errors and drasLlcally decrease Lhe Llme from seLLlng up your uAC sysLem Lo Laklng your flrsL measuremenL. nl-uACmx 8ase offers a subseL of nl-uACmx funcLlonallLy on Wlndows and Llnux, Mac CS x, Wlndows Moblle and Wlndows CL.
naLlonal lnsLrumenLs uAC boards have a drlver englne LhaL communlcaLes beLween Lhe board and Lhe appllcaLlon sofLware. 1here are Lwo drlver englnes, nl-uACmx and 1radlLlonal nl-uAC. ?ou can also use Lhe uAC AsslsLanL, an Lxpress vl LhaL communlcaLes wlLh nl-uACmx, ln LabvlLW Lo communlcaLe wlLh Lhe uAC board. ln addlLlon, naLlonal lnsLrumenLs provldes MeasuremenL & AuLomaLlon Lxplorer (MAx) for conflgurlng uAC boards. 1he nl-uACmx urlver sofLware ls Lhe layer of sofLware for easlly communlcaLlng wlLh Lhe hardware. lL forms Lhe mlddle layer beLween Lhe appllcaLlon sofLware and Lhe hardware. urlver sofLware also prevenLs a programmer from havlng Lo do reglsLer-level programmlng or compllcaLed commands ln order Lo access Lhe hardware funcLlons. 1he uACmx paleLLe ln LabvlLW: 18 nl-uACmx Tutorial: Data Acquisition in LabVIEW
5.1.1 DAQ Assistant 1he DA Ass|stant, lncluded wlLh nl-uACmx, ls a graphlcal, lnLeracLlve gulde for conflgurlng, LesLlng, and acqulrlng measuremenL daLa. WlLh a slngle cllck, you can even generaLe code based on your conflguraLlon, maklng lL easler and fasLer Lo develop complex operaLlons. 8ecause uAC AsslsLanL ls compleLely menu-drlven, you wlll make fewer programmlng errors and drasLlcally decrease Lhe Llme from seLLlng up your uAC sysLem Lo Laklng your flrsL measuremenL. Scales ?ou can conflgure cusLom scales for your measuremenLs uslng MAx. 1hls ls very useful when worklng wlLh sensors. lL allows you Lo brlng a scaled value lnLo your appllcaLlon wlLhouL havlng Lo work dlrecLly wlLh Lhe raw values. lor example, you can use a LemperaLure sensor LhaL represenLs LemperaLure wlLh a volLage. 1he converslon equaLlon for Lhe LemperaLure ls, volLage x 100 = Celslus. AfLer a scale ls seL, you can use lL ln your appllcaLlon program, provldlng Lhe LemperaLure value, raLher Lhan Lhe volLage. When performlng analog lnpuL, Lhe Lask can be Llmed Lo: Acqulre 1 Sample Acqulre n Samples Acqulre ConLlnuously 5.2 Simulating a DAQ Device ?ou can creaLe nl-uACmx slmulaLed devlces ln nl-uACmx 7.4 or laLer. uslng nl-uACmx slmulaLed devlces: ?ou can Lry nl producLs ln your appllcaLlon wlLhouL Lhe hardware. 19 nl-uACmx Tutorial: Data Acquisition in LabVIEW
LaLer, when you acqulre Lhe hardware, you can lmporL Lhe nl-uACmx slmulaLed devlce conflguraLlon Lo Lhe physlcal devlce uslng Lhe MAx orLable ConflguraLlon Wlzard. ?ou can work on your appllcaLlons on a porLable sysLem and upon reLurnlng Lo Lhe orlglnal sysLem, you can easlly lmporL your appllcaLlon work. CreaLlng nl-uACmx SlmulaLed uevlces 1o creaLe an nl-uACmx slmulaLed devlce, rlghL-cllck uevlces and lnLerfaces and selecL CreaLe new. 1he CreaLe new dlalog box prompLs you Lo selecL a devlce Lo add. SelecL nl-uACmx SlmulaLed uevlce and cllck llnlsh. ln Lhe Choose uevlce dlalog box, selecL Lhe famlly of devlces for Lhe devlce you wanL Lo slmulaLe. SelecL Lhe devlce and cllck Ck. lf you selecL a xl devlce, you are prompLed Lo selecL a chassls number and xl sloL number. lf you selecL an SCxl chassls, Lhe SCxl conflguraLlon panels open.
20
6 DAQ Devices uAC hardware acLs as Lhe lnLerface beLween Lhe compuLer and Lhe ouLslde world. lL prlmarlly funcLlons as a devlce LhaL dlglLlzes lncomlng analog slgnals so LhaL Lhe compuLer can lnLerpreL Lhem A uAC devlce (uaLa AcqulslLlon Pardware) usually has Lhese funcLlons: Analog lnpuL Analog ouLpuL ulglLal l/C CounLer/Llmers We have dlfferenL uAC devlces, such as: Desktop uAC devlces" where you need Lo plug a Cl uAC board lnLo your compuLer. 1he sofLware ls runnlng on a compuLer. ortab|e uAC devlces" for connecLlon Lo Lhe uS8 porL, Wl-ll connecLlons, eLc. 1he sofLware ls runnlng on a compuLer D|str|buted uAC devlces" where Lhe sofLware ls developed on your compuLer and Lhen laLer downloaded Lo Lhe dlsLrlbuLed uAC devlce.
21 uAC uevlces Tutorial: Data Acquisition in LabVIEW
MosL uAC devlces have four sLandard elemenLs: analog lnpuL, analog ouLpuL, dlglLal l/C, and counLers. 1he uAC devlce Lransfers Lhe measured slgnals Lo a compuLer Lhrough dlfferenL bus sLrucLures. lor example, you can plug a uAC devlce lnLo Lhe Cl bus or Lhe uS8 porL of a compuLer or Lhe ersonal CompuLer Memory Card lnLernaLlonal AssoclaLlon (CMClA) sockeL of a lapLop. ?ou also can use xl/CompacLCl Lo creaLe a porLable, versaLlle, and rugged measuremenL sysLem. 6.1 Performing Analog-to-Digital Conversion Analog-Lo-dlglLal converslon ls a process of acqulrlng and LranslaLlng slgnals lnLo dlglLal daLa so LhaL a compuLer can process lL. Analog-Lo-dlglLal converLers (AuCs) are clrculL componenLs LhaL converL a volLage level lnLo a serles of ones and zeroes. AuCs sample Lhe analog slgnal on each rlslng or falllng edge of a sample clock. ln each cycle, Lhe AuC Lakes a snapshoL of Lhe analog slgnal, measures and converLs lL lnLo a dlglLal value. 1he AuC obLalns and approxlmaLes Lhe slgnal wlLh flxed preclslon and converLs lL lnLo a serles of dlglLal values.
6.2 Performing Digital-to-Analog Conversion ulglLal-Lo-analog converslon ls Lhe opposlLe of analog-Lo-dlglLal converslon. ln dlglLal-Lo-analog converslon, Lhe compuLer generaLes Lhe daLa. 6.3 Using Counters A counLer ls a dlglLal Llmlng devlce. ?ou Lyplcally use counLers for evenL counLlng, frequency measuremenL, perlod measuremenL, poslLlon measuremenL, and pulse generaLlon. 6.4 Using Digital I/O 22 uAC uevlces Tutorial: Data Acquisition in LabVIEW
ulglLal slgnals are elecLrlcal slgnals LhaL Lransfer dlglLal daLa over a wlre. 1hese slgnals Lyplcally have only Lwo sLaLes: on and off, also known as hlgh and low, or 1 and 0. When sendlng a dlglLal slgnal across a wlre, Lhe sender applles a volLage Lo Lhe wlre and Lhe recelver uses Lhe volLage level Lo deLermlne Lhe value belng senL. 1he volLage ranges for each dlglLal value depend on Lhe volLage level sLandard belng used.
ulglLal slgnals have many users: ulglLal slgnals conLrol or measure dlglLal devlces such as swlLches or LLus
23
7 NI USB-6008 nl uS8-6008 ls a slmple and low-cosL mulLlfuncLlon l/C devlce from naLlonal lnsLrumenLs.
1he devlce has Lhe followlng speclflcaLlons: 8 analog lnpuLs (12-blL, 10 kS/s) 2 analog ouLpuLs (12-blL, 130 S/s) 12 dlglLal l/C uS8 connecLlon, no exLra power-supply needed CompaLlble wlLh LabvlLW, LabWlndows/Cvl, and MeasuremenL SLudlo for vlsual SLudlo .nL1 nl-uACmx drlver sofLware 1he nl uS8-6008 ls well sulLed for educaLlon purposes due Lo lLs small slze and easy uS8 connecLlon. 7.1 Connect NI USB-6008 to the PC Conflgurlng and LesLlng: uS8-6008 can be conflgured and LesLed uslng MAx (MeasuremenL and AuLomaLlon Lxplorer), whlch ls lnsLalled wlLh Lhe nl-uACmx urlver SofLware. 1he flrsL Llme you connecL Lhe uS8-6008 Lo Lhe C, Lhe Wlndows Pardware lnsLaller Wlzard wlll open. 1he wlzard searches Lhe C for Lhe necessary drlver sofLware for Lhe uS8-6008. 1hls drlver sofLware was lnsLalled along wlLh Lhe lnsLallaLlon of Lhe nl-uAC sofLware. When Lhe wlzard has flnlshed Lhe lnsLallaLlon of Lhe drlver sofLware, Lhe uS8-6008 ls ready for use. 24 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
7.1.1 Testing the USB-6008 in MAX 8efore you sLarL Lo use Lhe uS8-6008 ln an appllcaLlon, you should LesL Lhe devlce ln Lhe MeasuremenL and AuLomaLlon Lxplorer (MAk).
ln Lhe MAx wlndow, expand Lhe uevlces and lnLerfaces" node and Lhen nl uACmx uevlces". 8lghL-cllck on Lhe nl uS8-6008 devlce and selecL Self-1esL".
23 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
Popefully Lhe self-LesL passes wlLhouL errors. 1hen, you should LesL Lhe lndlvldual channels of Lhe uS8-6008 Lo check LhaL Lhe lnpuL slgnals are deLecLed correcLly by Lhe uS8-6008, and LhaL Lhe ouLpuL slgnals generaLed by Lhe uS8-6009 have correcL values. 1hls l/C can be LesLed ln several ways, dependlng on whlch channels you acLually wanL Lo LesL. We wlll perform a slmple loopback LesL: Pere, leL us LesL analog ouLpuL channel 0 (AC0) and Lhe analog lnpuL channel 0 (Al0) Lo see lf Lhey work correcLly. We wlll perform a very slmple LesL, whlch ls sufflclenL lf we are Lo check LhaL boLh AC0 and Al0 work correcLly. 1he LesL procedure, whlch ls denoLed !""#$%&', ls Lo connecL Lhe Al0 channel Lo Lhe AC0 channel. 1hen we generaLe some legal volLage aL AC0. lf Al0 deLecLs Lhe same volLage, we know LhaL boLh AC0 and Al0 work. (We may Lhen repeaL Lhls procedure for oLher channels.) lf for some reason Al0 deLecLs some oLher volLage Lhan Lhe value we seL for AC0, Lhen Lhere ls an error ln elLher Lhe Al0 channel or ln Lhe Lhe AC0 channel, and furLher lnvesLlgaLlons are necessary. 1o prepare for Lhe loopback LesL, we wlre LogeLher Al0 and AC0. 1o see Lhe Lermlnals of Lhe uS8-6000, selecL uevlce lnouLs" from Lhe rlghL-cllck menu.
26 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
1he llgure shows Lhe Al0 and AC0 channels wlred LogeLher.
1o acLually perform Lhe loopback LesL, rlghL-cllck on Lhe nl uS8-6008 devlce ln MAx, and Lhen selecL 1esL anels.." ln order Lo open Lhe 1esL anels. ln Lhe 1esL anels wlndow, selecL Lhe Analog CuLpuL Lab. 27 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
ln Lhe Analog CuLpuL Lab, selecL any volLage beLween 0v and 3v. nexL, cllck Lhe Analog lnpuL Lab ln Lhe 1esL anels wlndow. 28 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
1he Analog lnpuL Lab should lndlcaLe Lhe same (or almosL Lhe same) volLage as ls seL ouL on AC0. 1here may be a small dlfference beLween Lhe values due Lo Lhe llmlLed resoluLlon ln Lhe uA-converLer (dlglLal-Lo-analog) and ln Lhe Au-converLer (analog-Lo-dlglLal).
29 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
?ou should also always use a mu|t|-meter Lo check lf Lhe volLage levels on Lhe ouLpuL and lnpuL channels are correcL accordlng Lo your seLLlngs.
30 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
7.2 Using NI USB-6008 in LabVIEW ln order Lo use Lhe nl uS8-6008 ln LabvlLW you need Lo use Lhe uACmx funcLlons, see llgure below.
uACmx - uaLa AcqulslLlon paleLLe: 31 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
7.3 DAQ Assistant 1he easlesL ways ls Lo use Lhe uAC AsslsLanL. 7.3.1 Analog Input When you drag Lhe uAC AsslsLanL lcon on your 8lock ulagram, Lhe followlng wlndow appears:
32 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
ln Lhls wlndow you need Lo selecL elLher Acqulre Slgnals" (l.e., lnpuL Slgnals) or CeneraLe Slgnals" (l.e., CuLpuL Slgnals). SelecL Acqulre Slgnals - Analog lnpuL - volLage.
ln Lhe nexL wlndow you selecL whlch Analog lnpuL you wanL Lo use. SelecL al0 (Analog lnpuL channel 0) and cllck llnlsh. 33 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
1he followlng wlndow appears: 34 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
ln Lhe 1|m|ng Sett|ngs SelecL 1 Samp|e (Cn Demand)". 33 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
1he nexL sLep ls Lo selecL Lhe Slgnal lnpuL 8ange. A common slgnal ls 0-3v.
?ou may also rename Lhe name of Lhe channel (rlghL-cllck on Lhe name): 36 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
?ou are now flnlshed wlLh Lhe conflguraLlon. Cllck Ck ln Lhe uAC AsslsLanL wlndow 1he uAC AsslsLanL lcon appears on Lhe 8lock ulagram:
37 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
Lxamp|e: Wlre Lhe daLa ouLpuL Lo a numerlc lndlcaLor llke Lhls (and hlL Lhe 8un buLLon):
1hen numerlc lndlcaLor wlll show, e.g., Lhe followlng value:
[Lnd of Lxample] Lxamp|e: lf you wanL a conLlnuous" acqulslLlon, puL a Whlle loop around Lhe uAC AsslsLanL llke Lhls:
We can also communlcaLe wlLh Lhe uAC devlce wlLhouL uslng Lhe uAC AsslsLanL: 38 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
lor more advanced appllcaLlons Lhls approach ls recommended. [Lnd of Lxample] 7.3.2 Analog Output Analog CuLpuL ls slmllar.
39 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
40 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
Lxamp|e:
Cr lnslde a loop for conLlnuous" wrlLlng Lo Lhe uAC devlce:
Powever you should noL use Lhe uAC AsslsLanL lnslde a loop because of Lhe lack of performance. 1he followlng ls Lherefore beLLer:
41 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
ln Lhls example we have used some of Lhe oLher vls ln Lhe uACmx paleLLer as well. 1he lronL anel may loook llke Lhls.
ln Lhls example we assume LhaL we connecL wlres for Analog CuL and Analog ln LogeLher llke Lhls (a socalled loopback LesL):
42 nl uS8-6008 Tutorial: Data Acquisition in LabVIEW
We can also communlcaLe wlLh Lhe uAC devlce wlLhouL uslng Lhe uAC AsslsLanL:
lor more advanced appllcaLlons Lhls approach ls recommended. [Lnd of Lxample]
43
8 Logging to File ln many cases you wanL Lo wrlLe your daLa you geL from Lhe uAC devlce Lo a LexL flle for laLer use. ln Lhls chapLer we wlll learn how Lo wrlLe Lo a measuremenL flle ln LabvlLW. We wlll also learn how Lo read Lhe same flle. ?ou can use Lhe WrlLe Lo MeasuremenL llle" funcLlon on Lhe llle l/C paleLLe ln LabvlLW for wrlLlng daLa Lo LexL flles ?ou can save your daLa ln a Lab separaLed LexL (LvM daLa flle formaL) or as a blnary (1uMS flle formaL) flle.
lf we use Lhe LvM, lL ls easy Lo open and vlew Lhe daLa ln noLepad. 8.1 Writing to Measurement File We wlll use Lhe WrlLe Lo MeasuremenL llle" funcLlon ln Lhe llle l/C paleLLe ln LabvlLW for wrlLlng daLa Lo LexL flles. We wlll also focus on Lhe LvM daLa flle formaL, noL Lhe 1uMS flle formaL whlch glve blnary flles. 44 Logglng Lo llle Tutorial: Data Acquisition in LabVIEW
When you drag ln Lhe WrlLe Lo MeasuremenL llle", a conflguraLlon dlalog wlndow wlll auLomaLlcally pop up. 8ecommended seLLlngs for Lhe WrlLe 1o MeasuremenL llle" ls as follows:
Lxamp|e: Lxample of LabvlLW rogram LhaL wrlLe daLa Lo a MeasuremenL llle: lronL anel: 43 Logglng Lo llle Tutorial: Data Acquisition in LabVIEW
ln Lhls appllcaLlon we log daLa from a process based on a manual conLrol slgnal. 8oLh Lhe lnpuL slgnal u and Lhe ouLpuL slgnal (LemperaLure) ls saved Lo a MeasuremenL llle. 8lock ulagram:
1he LvM flle may look someLhlng llke Lhls: 46 Logglng Lo llle Tutorial: Data Acquisition in LabVIEW
1he flrsL column ls Lhe Llme, Lhe second column ls Lhe lnpuL slgnal, and Lhe Lhlrd column ls Lhe ouLpuL slgnal. [Lnd of Lxample] 8.2 Read from Measurement File
When you drag ln Lhe 8ead from MeasuremenL llle", a conflguraLlon dlalog wlndow wlll auLomaLlcally pop up. 8ecommended seLLlngs for Lhe kead Irom Measurement I||e": 47 Logglng Lo llle Tutorial: Data Acquisition in LabVIEW
Lxamp|e: Lxample of LabvlLW rogram LhaL read daLa from a MeasuremenL llle:
1hls appllcaLlon reads Lhe daLa and ploLs lL ln 2 dlfferenL graphs. 48 Logglng Lo llle Tutorial: Data Acquisition in LabVIEW
nans-etter na|vorsen, M.Sc. 1e|emark Un|vers|ty Co||ege Iacu|ty of 1echno|ogy Department of L|ectr|ca| Lng|neer|ng, Informat|on 1echno|ogy and Cybernet|cs