tutorial: data acquisition in labview
TRANSCRIPT
UniversityCollegeofSoutheastNorway
http://home.hit.no/~hansha
DataAcquisitioninLabVIEWHans-PetterHalvorsen,2016.10.28
2
PrefaceThistutorialexplainsthebasicconceptsofaDataAcquisitioninLabVIEW.
Youfindthisdocumentandadditionalresourcesonlineat:
http://home.hit.no/~hansha/?tutorial=daq
YoushouldhavesomebasicknowledgeaboutLabVIEW,e.g.,the“IntroductiontoLabVIEW”tutorial.Thisdocumentisavailablefordownloadathttp://home.hit.no/~hansha/.
FormoreinformationaboutLabVIEW,visit:http://home.hit.no/~hansha/?page=labview.
InadditiontoLabVIEW,youwillneedtoinstallthedriverNI-DAQmx.
[Figureontitlepage:www.ni.com]
iii
TableofContentsPreface......................................................................................................................................2
TableofContents.....................................................................................................................iii
1 IntroductiontoLabVIEW.....................................................................................................1
1.1 Dataflowprogramming................................................................................................1
1.2 Graphicalprogramming................................................................................................1
1.3 Benefits.........................................................................................................................2
2 IntroductiontoDataAcquisition.........................................................................................3
2.1 IntroductiontoDAQ-DataAcquisition........................................................................3
2.1.1 Physicalinput/outputsignals.................................................................................4
2.1.2 DAQdevice/hardware...........................................................................................4
2.1.3 Driversoftware......................................................................................................5
2.1.4 Yoursoftwareapplication(Applicationsoftware).................................................6
2.2 MAX–MeasurementandAutomationExplorer..........................................................6
2.3 NI-DAQmx.....................................................................................................................7
2.3.1 DAQAssistant........................................................................................................8
2.4 NIUSB-6008..................................................................................................................8
3 Physicalinput/outputsignals............................................................................................10
3.1 Transducers................................................................................................................10
3.2 Signals.........................................................................................................................11
3.2.1 AnalogSignals......................................................................................................11
3.3 DigitalSignals..............................................................................................................13
4 MAX...................................................................................................................................15
iv TableofContents
Tutorial: Data Acquisition in LabVIEW
5 NI-DAQmx.........................................................................................................................17
5.1.1 DAQAssistant......................................................................................................18
5.2 SimulatingaDAQDevice............................................................................................18
6 DAQDevices......................................................................................................................20
6.1 PerformingAnalog-to-DigitalConversion...................................................................21
6.2 PerformingDigital-to-AnalogConversion...................................................................21
6.3 UsingCounters...........................................................................................................21
6.4 UsingDigitalI/O..........................................................................................................22
7 NIUSB-6008......................................................................................................................23
7.1 ConnectNIUSB-6008tothePC..................................................................................23
7.1.1 TestingtheUSB-6008inMAX..............................................................................24
7.2 UsingNIUSB-6008inLabVIEW...................................................................................30
7.3 DAQAssistant.............................................................................................................31
7.3.1 AnalogInput........................................................................................................31
7.3.2 AnalogOutput......................................................................................................38
8 LoggingtoFile...................................................................................................................43
8.1 WritingtoMeasurementFile.....................................................................................43
8.2 ReadfromMeasurementFile.....................................................................................46
1
1 IntroductiontoLabVIEWLabVIEW(shortforLaboratoryVirtualInstrumentationEngineeringWorkbench)isaplatformanddevelopmentenvironmentforavisualprogramminglanguagefromNationalInstruments.Thegraphicallanguageisnamed"G".OriginallyreleasedfortheAppleMacintoshin1986,LabVIEWiscommonlyusedfordataacquisition,instrumentcontrol,andindustrialautomationonavarietyofplatformsincludingMicrosoftWindows,variousflavorsofUNIX,Linux,andMacOSX.VisitNationalInstrumentsatwww.ni.com.
Thecodefileshavetheextension“.vi”,whichisanabbreviationfor“VirtualInstrument”.LabVIEWofferslotsofadditionalAdd-OnsandToolkits.
1.1 DataflowprogrammingTheprogramminglanguageusedinLabVIEW,alsoreferredtoasG,isadataflowprogramminglanguage.Executionisdeterminedbythestructureofagraphicalblockdiagram(theLV-sourcecode)onwhichtheprogrammerconnectsdifferentfunction-nodesbydrawingwires.Thesewirespropagatevariablesandanynodecanexecuteassoonasallitsinputdatabecomeavailable.Sincethismightbethecaseformultiplenodessimultaneously,Gisinherentlycapableofparallelexecution.Multi-processingandmulti-threadinghardwareisautomaticallyexploitedbythebuilt-inscheduler,whichmultiplexesmultipleOSthreadsoverthenodesreadyforexecution.
1.2 GraphicalprogrammingLabVIEWtiesthecreationofuserinterfaces(calledfrontpanels)intothedevelopmentcycle.LabVIEWprograms/subroutinesarecalledvirtualinstruments(VIs).EachVIhasthreecomponents:ablockdiagram,afrontpanel,andaconnectorpanel.ThelastisusedtorepresenttheVIintheblockdiagramsofother,callingVIs.Controlsandindicatorsonthefrontpanelallowanoperatortoinputdataintoorextractdatafromarunningvirtualinstrument.However,thefrontpanelcanalsoserveasaprogrammaticinterface.Thusavirtualinstrumentcaneitherberunasaprogram,withthefrontpanelservingasauserinterface,or,whendroppedasanodeontotheblockdiagram,thefrontpaneldefinestheinputsandoutputsforthegivennodethroughtheconnectorpane.ThisimplieseachVIcanbeeasilytestedbeforebeingembeddedasasubroutineintoalargerprogram.
2 IntroductiontoLabVIEW
Tutorial: Data Acquisition in LabVIEW
Thegraphicalapproachalsoallowsnon-programmerstobuildprogramssimplybydragginganddroppingvirtualrepresentationsoflabequipmentwithwhichtheyarealreadyfamiliar.TheLabVIEWprogrammingenvironment,withtheincludedexamplesandthedocumentation,makesitsimpletocreatesmallapplications.Thisisabenefitononeside,butthereisalsoacertaindangerofunderestimatingtheexpertiseneededforgoodquality"G"programming.Forcomplexalgorithmsorlarge-scalecode,itisimportantthattheprogrammerpossessanextensiveknowledgeofthespecialLabVIEWsyntaxandthetopologyofitsmemorymanagement.ThemostadvancedLabVIEWdevelopmentsystemsofferthepossibilityofbuildingstand-aloneapplications.Furthermore,itispossibletocreatedistributedapplications,whichcommunicatebyaclient/serverscheme,andarethereforeeasiertoimplementduetotheinherentlyparallelnatureofG-code.
1.3 BenefitsOnebenefitofLabVIEWoverotherdevelopmentenvironmentsistheextensivesupportforaccessinginstrumentationhardware.Driversandabstractionlayersformanydifferenttypesofinstrumentsandbusesareincludedorareavailableforinclusion.Thesepresentthemselvesasgraphicalnodes.Theabstractionlayersofferstandardsoftwareinterfacestocommunicatewithhardwaredevices.Theprovideddriverinterfacessaveprogramdevelopmenttime.ThesalespitchofNationalInstrumentsis,therefore,thatevenpeoplewithlimitedcodingexperiencecanwriteprogramsanddeploytestsolutionsinareducedtimeframewhencomparedtomoreconventionalorcompetingsystems.Anewhardwaredrivertopology(DAQmxBase),whichconsistsmainlyofG-codedcomponentswithonlyafewregistercallsthroughNIMeasurementHardwareDDK(DriverDevelopmentKit)functions,providesplatformindependenthardwareaccesstonumerousdataacquisitionandinstrumentationdevices.TheDAQmxBasedriverisavailableforLabVIEWonWindows,MacOSXandLinuxplatforms.
3
2 IntroductiontoDataAcquisition
ThischapterexplainsthebasicconceptsofusingDAQinLabVIEW.
Topics:
• IntroductiontoDAQ-DataAcquisition• MAX–MeasurementandAutomationExplorer• NI-DAQmx
LabVIEWisverypowerfulwhenitcomestocreatingDAQapplications.LabVIEWincludesasetofVIsthatletyouconfigure,acquiredatafrom,andsenddatatoDAQdevices.Often,onedevicecanperformavarietyoffunctions,suchasanalog-to-digital(A/D)conversion,digital-to-analog(D/A)conversion,digitalI/O,andcounter/timeroperations.EachdevicesupportsdifferentDAQandsignalgenerationspeeds.Also,eachDAQdeviceisdesignedforspecifichardware,platformsandoperatingsystems.
NationalInstruments,theinventorofLabVIEW,alsomakeDAQdevices,sotheintegrationwiththeDAQdevicesfromNIandtheLabVIEWsoftwareisseamlessandmakesiteasytodoI/OoperationsfromtheLabVIEWenvironment.
2.1 IntroductiontoDAQ-DataAcquisitionThepurposeofdataacquisitionistomeasureanelectricalorphysicalphenomenonsuchasvoltage,current,temperature,pressure,orsound.PC-baseddataacquisitionusesacombinationofmodularhardware,applicationsoftware,andacomputertotakemeasurements.Whileeachdataacquisitionsystemisdefinedbyitsapplicationrequirements,everysystemsharesacommongoalofacquiring,analyzing,andpresentinginformation.Dataacquisitionsystemsincorporatesignals,sensors,actuators,signalconditioning,dataacquisitiondevices,andapplicationsoftware.
Sosummingup,DataAcquisitionistheprocessof:
• Acquiringsignalsfromreal-worldphenomena• Digitizingthesignals
4 IntroductiontoDataAcquisition
Tutorial: Data Acquisition in LabVIEW
• Analyzing,presentingandsavingthedata
TheDAQsystemhasthefollowingpartsinvolved,seeFigure:
Thepartsare:
• Physicalinput/outputsignals• DAQdevice/hardware• Driversoftware• Yoursoftwareapplication(Applicationsoftware)
ForanIntroductiontoDataAcquisition,seethiswebcast:http://zone.ni.com/wv/app/doc/p/id/wv-169
2.1.1 Physicalinput/outputsignals
Aphysicalinput/outputsignalistypicallyavoltageorcurrentsignal.
Avoltagesignalcantypicallybea0-5Vsignal,whileacurrentsignalcantypicallybea4-20mAsignal.
2.1.2 DAQdevice/hardware
DAQhardwareactsastheinterfacebetweenthecomputerandtheoutsideworld.Itprimarilyfunctionsasadevicethatdigitizesincominganalogsignalssothatthecomputercaninterpretthem
ADAQdevice(DataAcquisitionHardware)usuallyhasthesefunctions:
• Analoginput• Analogoutput
5 IntroductiontoDataAcquisition
Tutorial: Data Acquisition in LabVIEW
• DigitalI/O• Counter/timers
WehavedifferentDAQdevices,suchas:
• “DesktopDAQdevices”whereyouneedtoplugaPCIDAQboardintoyourcomputer.Thesoftwareisrunningonacomputer.
• “PortableDAQdevices”forconnectiontotheUSBport,Wi-Ficonnections,etc.Thesoftwareisrunningonacomputer
• “DistributedDAQdevices”wherethesoftwareisdevelopedonyourcomputerandthenlaterdownloadedtothedistributedDAQdevice.
[www.ni.com]
2.1.3 Driversoftware
Driversoftwareisthelayerofsoftwareforeasilycommunicatingwiththehardware.Itformsthemiddlelayerbetweentheapplicationsoftwareandthehardware.Driversoftwarealsopreventsaprogrammerfromhavingtodoregister-levelprogrammingorcomplicatedcommandsinordertoaccessthehardwarefunctions.
DriversoftwarefromNationalInstruments:
• NI-DAQmx
6 IntroductiontoDataAcquisition
Tutorial: Data Acquisition in LabVIEW
• NI-DAQmxBase
TheDAQAssistant,includedwithNI-DAQmx,isagraphical,interactiveguideforconfiguring,testing,andacquiringmeasurementdata.Withasingleclick,youcanevengeneratecodebasedonyourconfiguration,makingiteasierandfastertodevelopcomplexoperations.BecauseDAQAssistantiscompletelymenu-driven,youwillmakefewerprogrammingerrorsanddrasticallydecreasethetimefromsettingupyourDAQsystemtotakingyourfirstmeasurement.
NI-DAQmxBaseoffersasubsetofNI-DAQmxfunctionalityonWindowsandLinux,MacOSX,WindowsMobileandWindowsCE.
2.1.4 Yoursoftwareapplication(Applicationsoftware)
Applicationsoftwareaddsanalysisandpresentationcapabilitiestothedriversoftware.Yoursoftwareapplicationnormallydoessuchtasksas:
• Real-timemonitoring• Dataanalysis• Datalogging• Controlalgorithms• Humanmachineinterface(HMI)
InordertocreateyourDAQapplicationyouneedaprogrammingdevelopmenttool,suchasLabVIEW.
2.2 MAX–MeasurementandAutomationExplorer
Measurement&AutomationExplorer(MAX)providesaccesstoyourNationalInstrumentsdevicesandsystems.
WithMAX,youcan:
• ConfigureyourNationalInstrumentshardwareandsoftware • Createandeditchannels,tasks,interfaces,scales,andvirtualinstruments • Executesystemdiagnostics • Viewdevicesandinstrumentsconnectedtoyoursystem
7 IntroductiontoDataAcquisition
Tutorial: Data Acquisition in LabVIEW
• UpdateyourNationalInstrumentssoftware
Inadditiontothestandardtools,MAXcanexposeitem-specifictoolsyoucanusetoconfigure,diagnose,ortestyoursystem,dependingonwhichNIproductsyouinstall.AsyounavigatethroughMAX,thecontentsoftheapplicationmenuandtoolbarchangetoreflectthesenewtools.
2.3 NI-DAQmxTheNI-DAQmxDriversoftwareisthelayerofsoftwareforeasilycommunicatingwiththehardware.Itformsthemiddlelayerbetweentheapplicationsoftwareandthehardware.
8 IntroductiontoDataAcquisition
Tutorial: Data Acquisition in LabVIEW
Driversoftwarealsopreventsaprogrammerfromhavingtodoregister-levelprogrammingorcomplicatedcommandsinordertoaccessthehardwarefunctions.
TheDAQmxpaletteinLabVIEW:
The“DAQAssistant”isaneasywaytostartusingtheDAQfeaturesinLabVIEW.Wewilllearnmoreaboutthe“DAQAssistant”inalaterchapter.
2.3.1 DAQAssistant
TheDAQAssistant,includedwithNI-DAQmx,isagraphical,interactiveguideforconfiguring,testing,andacquiringmeasurementdata.Withasingleclick,youcanevengeneratecodebasedonyourconfiguration,makingiteasierandfastertodevelopcomplexoperations.BecauseDAQAssistantiscompletelymenu-driven,youwillmakefewerprogrammingerrorsanddrasticallydecreasethetimefromsettingupyourDAQsystemtotakingyourfirstmeasurement.
2.4 NIUSB-6008NIUSB-6008isasimpleandlow-costmultifunctionI/OdevicefromNationalInstruments.
9 IntroductiontoDataAcquisition
Tutorial: Data Acquisition in LabVIEW
Thedevicehasthefollowingspecifications:
• 8analoginputs(12-bit,10kS/s)• 2analogoutputs(12-bit,150S/s)• 12digitalI/O• USBconnection,Noextrapower-supplyneeeded• CompatiblewithLabVIEW,LabWindows/CVI,andMeasurementStudioforVisual
Studio.NET• NI-DAQmxdriversoftware
TheNIUSB-6008iswellsuitedforeducationpurposesduetoitssmallsizeandeasyUSBconnection.
10
3 Physicalinput/outputsignals
Dataacquisitioninvolvesgatheringsignalsfrommeasurementsourcesanddigitizingthesignalforstorage,analysis,andpresentationonaPC.Dataacquisition(DAQ)systemscomeinmanydifferentPCtechnologyformsforgreatflexibilitywhenchoosingyoursystem.ScientistsandengineerscanchoosefromPCI,PXI,PCIExpress,PXIExpress,PCMCIA,USB,WirelessandEthernetdataacquisitionfortest,measurement,andautomationapplications.TherearefivecomponentstobeconsideredwhenbuildingabasicDAQsystem
• Transducersandsensors• Signals• Signalconditioning• DAQhardware• Driverandapplicationsoftware
InthischapterwefocusonTransducers,sensorsandSignals.
3.1 TransducersDataacquisitionbeginswiththephysicalphenomenontobemeasured.Thisphysicalphenomenoncouldbehetemperatureofaroom,theintensityofalightsource,thepressureinsideachamber,theforceappliedtoanobject,ormanyotherthings.AneffectiveDAQsystemcanmeasureallofthesedifferentphenomena.Atransducerisadevicethatconvertsaphysicalphenomenonintoameasurableelectricalsignal,suchasvoltageorcurrent.TheabilityofaDAQsystemtomeasuredifferentphenomenadependsonthetransducerstoconvertthephysicalphenomenaintosignalsmeasurablebytheDAQhardware.TransducersaresynonymouswithsensorsinDAQsystems.Therearespecifictransducersformanydifferentapplications,suchasmeasuringtemperature,pressure,orfluidflow.Belowweseesomecommonphenomenaandthetransducersusedtomeasurethem.
Phenomenon Transducer
11 Physicalinput/outputsignals
Tutorial: Data Acquisition in LabVIEW
Temperature Thermocouple,RTD,Thermistor
Light PhotoSensor
Sound Microphone
ForceandPressure StrainGage,PiezoelectricTransducer
PositionandDisplacement
Potentiometer,LVDT,OpticalEncoder
Acceleration Accelerometer
pH pHElectrode
Differenttransducershavedifferentrequirementsforconvertingphenomenaintoameasurablesignal.Sometransducersmayrequireexcitationintheformofvoltageorcurrent.Othertransducersmayrequireadditionalcomponentsandevenresistivenetworkstoproduceasignal.
Refertoni.com/sensorsformoreinformationontransducers.
3.2 SignalsTheappropriatetransducersconvertphysicalphenomenaintomeasurablesignals.However,differentsignalsneedtobemeasuredindifferentways.Forthisreason,itisimportanttounderstandthedifferenttypesofsignalsandtheircorrespondingattributes.Signalscanbecategorizedintotwogroups:
• Analog• Digital
3.2.1 AnalogSignals
Analoginputistheprocessofmeasuringananalogsignalandtransferringthemeasurementtoacomputerforanalysis,display,orstorage.Ananalogsignalisasignalthatvariescontinuously.Analoginputismostcommonlyusedtomeasurevoltageorcurrent.Youcanusemanytypesofdevicestoperformanaloginput,suchasmultifunctionDAQ(MIO)devices,high-speeddigitizers,digitalmultimeters,andDynamicSignalAcquisition(DSA)devices.
12 Physicalinput/outputsignals
Tutorial: Data Acquisition in LabVIEW
[ww.ni.com]
Ananalogsignalcanbeatanyvaluewithrespecttotime.Afewexamplesofanalogsignalsincludevoltage,temperature,pressure,sound,andload.Thethreeprimarycharacteristicsofananalogsignalis:
• Level• Shape• Frequency
LevelBecauseanalogsignalscantakeonanyvalue,thelevelgivesvitalinformationaboutthemeasuredanalogsignal.Theintensityofalightsource,thetemperatureinaroom,andthepressureinsideachamberareallexamplesthatdemonstratetheimportanceofthelevelofasignal.Whenmeasuringthelevelofasignal,thesignalgenerallydoesnotchangequickly
13 Physicalinput/outputsignals
Tutorial: Data Acquisition in LabVIEW
withrespecttotime.Theaccuracyofthemeasurement,however,isveryimportant.ADAQsystemthatyieldsmaximumaccuracyshouldbechosentoaidinanaloglevelmeasurements.ShapeSomesignalsarenamedaftertheirspecificshape-sine,square,sawtooth,andtriangle.Theshapeofananalogsignalcanbeasimportantasthelevel,becausebymeasuringtheshapeofananalogsignal,youcanfurtheranalyzethesignal,includingpeakvalues,DCvalues,andslope.Signalswhereshapeisofinterestgenerallychangerapidlywithrespecttotime,butsystemaccuracyisstillimportant.Theanalysisofheartbeats,videosignals,sounds,vibrations,andcircuitresponsesaresomeapplicationsinvolvingshapemeasurements.
FrequencyAllanalogsignalscanbecategorizedbytheirfrequency.Unlikethelevelorshapeofthesignal,frequencycannotbedirectlymeasured.Thesignalmustbeanalyzedusingsoftwaretodeterminethefrequencyinformation.ThisanalysisisusuallydoneusinganalgorithmknownastheFouriertransform.Whenfrequencyisthemostimportantpieceofinformation,itisimportanttoconsiderincludingbothaccuracyandacquisitionspeed.Althoughtheacquisitionspeedforacquiringthefrequencyofasignalislessthanthespeedrequiredforobtainingtheshapeofasignal,thesignalmuststillbeacquiredfastenoughthatthepertinentinformationisnotlostwhiletheanalogsignalisbeingacquired.TheconditionthatstipulatesthisspeedisknownastheNyquistSamplingTheorem.Speechanalysis,telecommunication,andearthquakeanalysisaresomeexamplesofcommonapplicationswherethefrequencyofthesignalmustbeknown.
3.3 DigitalSignalsAdigitalsignalcannottakeonanyvaluewithrespecttotime.Instead,adigitalsignalhastwopossiblelevels:highandlow.Digitalsignalsgenerallyconformtocertainspecificationsthatdefinecharacteristicsofthesignal.Digitalsignalsarecommonlyreferredtoastransistor-to-transistorlogic(TTL).TTLspecificationsindicateadigitalsignaltobelowwhenthelevelfallswithin0to0.8V,andthesignalishighbetween2to5V.Theusefulinformationthatcanbemeasuredfromadigitalsignalincludesthestateandtherate.
14 Physicalinput/outputsignals
Tutorial: Data Acquisition in LabVIEW
StateDigitalsignalscannottakeonanyvaluewithrespecttotime.Thestateofadigitalsignalisessentiallythelevelofthesignal-onoroff,highorlow.Monitoringthestateofaswitch-openorclosed-isacommonapplicationshowingtheimportanceofknowingthestateofadigitalsignal.
RateTherateofadigitalsignaldefineshowthedigitalsignalchangesstatewithrespecttotime.Anexampleofmeasuringtherateofadigitalsignalincludesdetermininghowfastamotorshaftspins.Unlikefrequency,therateofadigitalsignalmeasureshowoftenaportionofasignaloccurs.Asoftwarealgorithmisnotrequiredtodeterminetherateofasignal
15
4 MAXMeasurement&AutomationExplorer(MAX)providesaccesstoyourNationalInstrumentsdevicesandsystems.
WithMAX,youcan:
• ConfigureyourNationalInstrumentshardwareandsoftware • Createandeditchannels,tasks,interfaces,scales,andvirtualinstruments • Executesystemdiagnostics • Viewdevicesandinstrumentsconnectedtoyoursystem • UpdateyourNationalInstrumentssoftware
Inadditiontothestandardtools,MAXcanexposeitem-specifictoolsyoucanusetoconfigure,diagnose,ortestyoursystem,dependingonwhichNIproductsyouinstall.AsyounavigatethroughMAX,thecontentsoftheapplicationmenuandtoolbarchangetoreflectthesenewtools.
LabVIEWinstallsMAXtoestablishalldevicesandchannelconfigurationparameters.MAXreadstheinformationtheDeviceManagerrecordsintheWindowsRegistryandassignsalogicaldevicenumbertoeachDAQdevice.
16 MAX
Tutorial: Data Acquisition in LabVIEW
YouusethedevicenumbertorefertothedeviceinLabVIEW.YoucanaccessMAXbyselectingTools»Measurement&AutomationExplorerinLabVIEW.ThisdisplaystheprimaryMAXwindow.
Beforeusingadataacquisitionboard,youmustconfirmthatthesoftwarecancommunicatewiththeboardbyconfiguringthedevices.ForWindows,theWindowsConfigurationManagerkeepstrackofallthehardwareinstalledinthecomputer,includingNationalInstrumentsDAQdevices.TheWindowsConfigurationManagerautomaticallydetectsandconfiguresPlug&Play(PnP)devices.
WindowsConfigurationManager
IfyouhaveaPnPdevice,suchasanESeriesMIOdevice,theWindowsConfigurationManagerautomaticallydetectsandconfiguresthedevice.Ifyouhaveanon-PnPdevice,orlegacydevice,youmustconfigurethedevicemanuallyusingtheAddNewHardwareoptionintheControlPanel.YoucanverifytheWindowsConfigurationbyaccessingtheDeviceManager.
17
5 NI-DAQmxDriversoftwareisthelayerofsoftwareforeasilycommunicatingwiththehardware.Itformsthemiddlelayerbetweentheapplicationsoftwareandthehardware.Driversoftwarealsopreventsaprogrammerfromhavingtodoregister-levelprogrammingorcomplicatedcommandsinordertoaccessthehardwarefunctions.
DriversoftwarefromNationalInstruments:
• NI-DAQmx• NI-DAQmxBase
TheDAQAssistant,includedwithNI-DAQmx,isagraphical,interactiveguideforconfiguring,testing,andacquiringmeasurementdata.Withasingleclick,youcanevengeneratecodebasedonyourconfiguration,makingiteasierandfastertodevelopcomplexoperations.BecauseDAQAssistantiscompletelymenu-driven,youwillmakefewerprogrammingerrorsanddrasticallydecreasethetimefromsettingupyourDAQsystemtotakingyourfirstmeasurement.
NI-DAQmxBaseoffersasubsetofNI-DAQmxfunctionalityonWindowsandLinux,MacOSX,WindowsMobileandWindowsCE.
NationalInstrumentsDAQboardshaveadriverenginethatcommunicatesbetweentheboardandtheapplicationsoftware.Therearetwodriverengines,NI-DAQmxandTraditionalNI-DAQ.YoucanalsousetheDAQAssistant,anExpressVIthatcommunicateswithNI-DAQmx,inLabVIEWtocommunicatewiththeDAQboard.Inaddition,NationalInstrumentsprovidesMeasurement&AutomationExplorer(MAX)forconfiguringDAQboards.
TheNI-DAQmxDriversoftwareisthelayerofsoftwareforeasilycommunicatingwiththehardware.Itformsthemiddlelayerbetweentheapplicationsoftwareandthehardware.Driversoftwarealsopreventsaprogrammerfromhavingtodoregister-levelprogrammingorcomplicatedcommandsinordertoaccessthehardwarefunctions.
TheDAQmxpaletteinLabVIEW:
18 NI-DAQmx
Tutorial: Data Acquisition in LabVIEW
5.1.1 DAQAssistant
TheDAQAssistant,includedwithNI-DAQmx,isagraphical,interactiveguideforconfiguring,testing,andacquiringmeasurementdata.Withasingleclick,youcanevengeneratecodebasedonyourconfiguration,makingiteasierandfastertodevelopcomplexoperations.BecauseDAQAssistantiscompletelymenu-driven,youwillmakefewerprogrammingerrorsanddrasticallydecreasethetimefromsettingupyourDAQsystemtotakingyourfirstmeasurement.
Scales
YoucanconfigurecustomscalesforyourmeasurementsusingMAX.Thisisveryusefulwhenworkingwithsensors.Itallowsyoutobringascaledvalueintoyourapplicationwithouthavingtoworkdirectlywiththerawvalues.Forexample,youcanuseatemperaturesensorthatrepresentstemperaturewithavoltage.Theconversionequationforthetemperatureis,Voltagex100=Celsius.Afterascaleisset,youcanuseitinyourapplicationprogram,providingthetemperaturevalue,ratherthanthevoltage.
Whenperforminganaloginput,thetaskcanbetimedto:
• Acquire1Sample• AcquirenSamples• AcquireContinuously
5.2 SimulatingaDAQDevice
19 NI-DAQmx
Tutorial: Data Acquisition in LabVIEW
YoucancreateNI-DAQmxsimulateddevicesinNI-DAQmx7.4orlater.UsingNI-DAQmxsimulateddevices:
YoucantryNIproductsinyourapplicationwithoutthehardware.
Later,whenyouacquirethehardware,youcanimporttheNI-DAQmxsimulateddeviceconfigurationtothephysicaldeviceusingtheMAXPortableConfigurationWizard.
Youcanworkonyourapplicationsonaportablesystemanduponreturningtotheoriginalsystem,youcaneasilyimportyourapplicationwork.
CreatingNI-DAQmxSimulatedDevices
TocreateanNI-DAQmxsimulateddevice,right-clickDevicesandInterfacesandselectCreateNew.TheCreateNewdialogboxpromptsyoutoselectadevicetoadd.SelectNI-DAQmxSimulatedDeviceandclickFinish.IntheChooseDevicedialogbox,selectthefamilyofdevicesforthedeviceyouwanttosimulate.SelectthedeviceandclickOK.IfyouselectaPXIdevice,youarepromptedtoselectachassisnumberandPXIslotnumber.IfyouselectanSCXIchassis,theSCXIconfigurationpanelsopen.
20
6 DAQDevicesDAQhardwareactsastheinterfacebetweenthecomputerandtheoutsideworld.Itprimarilyfunctionsasadevicethatdigitizesincominganalogsignalssothatthecomputercaninterpretthem
ADAQdevice(DataAcquisitionHardware)usuallyhasthesefunctions:
• Analoginput• Analogoutput• DigitalI/O• Counter/timers
WehavedifferentDAQdevices,suchas:
• “DesktopDAQdevices”whereyouneedtoplugaPCIDAQboardintoyourcomputer.Thesoftwareisrunningonacomputer.
• “PortableDAQdevices”forconnectiontotheUSBport,Wi-Ficonnections,etc.Thesoftwareisrunningonacomputer
• “DistributedDAQdevices”wherethesoftwareisdevelopedonyourcomputerandthenlaterdownloadedtothedistributedDAQdevice.
[www.ni.com]
21 DAQDevices
Tutorial: Data Acquisition in LabVIEW
MostDAQdeviceshavefourstandardelements:analoginput,analogoutput,digitalI/O,andcounters.TheDAQdevicetransfersthemeasuredsignalstoacomputerthroughdifferentbusstructures.Forexample,youcanplugaDAQdeviceintothePCIbusortheUSBportofacomputerorthePersonalComputerMemoryCardInternationalAssociation(PCMCIA)socketofalaptop.YoualsocanusePXI/CompactPCItocreateaportable,versatile,andruggedmeasurementsystem.
6.1 PerformingAnalog-to-DigitalConversionAnalog-to-digitalconversionisaprocessofacquiringandtranslatingsignalsintodigitaldatasothatacomputercanprocessit.Analog-to-digitalconverters(ADCs)arecircuitcomponentsthatconvertavoltagelevelintoaseriesofonesandzeroes.ADCssampletheanalogsignaloneachrisingorfallingedgeofasampleclock.Ineachcycle,theADCtakesasnapshotoftheanalogsignal,measuresandconvertsitintoadigitalvalue.TheADCobtainsandapproximatesthesignalwithfixedprecisionandconvertsitintoaseriesofdigitalvalues.
[www.ni.com]
6.2 PerformingDigital-to-AnalogConversionDigital-to-analogconversionistheoppositeofanalog-to-digitalconversion.Indigital-to-analogconversion,thecomputergeneratesthedata.
6.3 UsingCountersAcounterisadigitaltimingdevice.Youtypicallyusecountersforeventcounting,frequencymeasurement,periodmeasurement,positionmeasurement,andpulsegeneration.
22 DAQDevices
Tutorial: Data Acquisition in LabVIEW
6.4 UsingDigitalI/ODigitalsignalsareelectricalsignalsthattransferdigitaldataoverawire.Thesesignalstypicallyhaveonlytwostates:onandoff,alsoknownashighandlow,or1and0.Whensendingadigitalsignalacrossawire,thesenderappliesavoltagetothewireandthereceiverusesthevoltageleveltodeterminethevaluebeingsent.Thevoltagerangesforeachdigitalvaluedependonthevoltagelevelstandardbeingused.
Digitalsignalshavemanyusers:
• DigitalsignalscontrolormeasuredigitaldevicessuchasswitchesorLEDs
23
7 NIUSB-6008NIUSB-6008isasimpleandlow-costmultifunctionI/OdevicefromNationalInstruments.
Thedevicehasthefollowingspecifications:
• 8analoginputs(12-bit,10kS/s)• 2analogoutputs(12-bit,150S/s)• 12digitalI/O• USBconnection,Noextrapower-supplyneeded• CompatiblewithLabVIEW,LabWindows/CVI,andMeasurementStudioforVisual
Studio.NET• NI-DAQmxdriversoftware
TheNIUSB-6008iswellsuitedforeducationpurposesduetoitssmallsizeandeasyUSBconnection.
7.1 ConnectNIUSB-6008tothePCConfiguringandtesting:USB-6008canbeconfiguredandtestedusingMAX(MeasurementandAutomationExplorer),whichisinstalledwiththeNI-DAQmxDriverSoftware.
ThefirsttimeyouconnecttheUSB-6008tothePC,theWindowsHardwareInstallerWizardwillopen.
24 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
ThewizardsearchesthePCforthenecessarydriversoftwarefortheUSB-6008.ThisdriversoftwarewasinstalledalongwiththeinstallationoftheNI-DAQsoftware.Whenthewizardhasfinishedtheinstallationofthedriversoftware,theUSB-6008isreadyforuse.
7.1.1 TestingtheUSB-6008inMAX
BeforeyoustarttousetheUSB-6008inanapplication,youshouldtestthedeviceintheMeasurementandAutomationExplorer(MAX).
IntheMAXwindow,expandthe“DevicesandInterfaces”nodeandthen“NIDAQmxDevices”.Right-clickontheNIUSB-6008deviceandselect“Self-Test”.
25 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Hopefullytheself-testpasseswithouterrors.Then,youshouldtesttheindividualchannelsoftheUSB-6008tocheckthattheinputsignalsaredetectedcorrectlybytheUSB-6008,andthattheoutputsignalsgeneratedbytheUSB-6009havecorrectvalues.ThisI/Ocanbetestedinseveralways,dependingonwhichchannelsyouactuallywanttotest.
Wewillperformasimpleloopbacktest:
Here,letustestanalogoutputchannel0(AO0)andtheanaloginputchannel0(AI0)toseeiftheyworkcorrectly.Wewillperformaverysimpletest,whichissufficientifwearetocheckthatbothAO0andAI0workcorrectly.Thetestprocedure,whichisdenotedloopback,istoconnecttheAI0channeltotheAO0channel.ThenwegeneratesomelegalvoltageatAO0.IfAI0detectsthesamevoltage,weknowthatbothAO0andAI0work.(Wemaythenrepeatthisprocedureforotherchannels.)IfforsomereasonAI0detectssomeothervoltagethanthevaluewesetforAO0,thenthereisanerrorineithertheAI0channelorinthetheAO0channel,andfurtherinvestigationsarenecessary.
Topreparefortheloopbacktest,wewiretogetherAI0andAO0.ToseetheterminalsoftheUSB-6000,select“DevicePinouts”fromtheright-clickmenu.
26 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Toactuallyperformtheloopbacktest,right-clickontheNIUSB-6008deviceinMAX,andthenselect“TestPanels..”inordertoopentheTestPanels.IntheTestPanelswindow,selecttheAnalogOutputtab.
27 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
IntheAnalogOutputtab,selectanyvoltagebetween0Vand5V.
Next,clicktheAnalogInputtabintheTestPanelswindow.
28 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
TheAnalogInputtabshouldindicatethesame(oralmostthesame)voltageasissetoutonAO0.TheremaybeasmalldifferencebetweenthevaluesduetothelimitedresolutionintheDA-converter(digital-to-analog)andintheAD-converter(analog-to-digital).
29 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Youshouldalsoalwaysuseamulti-metertocheckifthevoltagelevelsontheoutputandinputchannelsarecorrectaccordingtoyoursettings.
30 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
7.2 UsingNIUSB-6008inLabVIEWInordertousetheNIUSB-6008inLabVIEWyouneedtousetheDAQmxfunctions,seeFigurebelow.
DAQmx–DataAcquisitionpalette:
31 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
7.3 DAQAssistantTheeasiestwaysistousetheDAQAssistant.
7.3.1 AnalogInput
WhenyoudragtheDAQAssistanticononyourBlockDiagram,thefollowingwindowappears:
32 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Inthiswindowyouneedtoselecteither“AcquireSignals”(i.e.,InputSignals)or“GenerateSignals”(i.e.,OutputSignals).
SelectAcquireSignals→AnalogInput→Voltage.
33 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
InthenextwindowyouselectwhichAnalogInputyouwanttouse.Selectai0(AnalogInputchannel0)andclickFinish.
Thefollowingwindowappears:
34 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
IntheTimingSettingsSelect“1Sample(OnDemand)”.
35 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
ThenextstepistoselecttheSignalInputRange.Acommonsignalis0-5V.
Youmayalsorenamethenameofthechannel(right-clickonthename):
36 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Youarenowfinishedwiththeconfiguration.ClickOKintheDAQAssistantwindowTheDAQAssistanticonappearsontheBlockDiagram:
37 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Example:
Wirethedataoutputtoanumericindicatorlikethis(andhittheRunbutton):
Thennumericindicatorwillshow,e.g.,thefollowingvalue:
[EndofExample]
Example:
Ifyouwanta“continuous”acquisition,putaWhilelooparoundtheDAQAssistantlikethis:
WecanalsocommunicatewiththeDAQdevicewithoutusingtheDAQAssistant:
38 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Formoreadvancedapplicationsthisapproachisrecommended.
[EndofExample]
7.3.2 AnalogOutput
AnalogOutputissimilar.
39 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
40 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Example:
Orinsidealoopfor“continuous”writingtotheDAQdevice:
41 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
HoweveryoushouldnotusetheDAQAssistantinsidealoopbecauseofthelackofperformance.Thefollowingisthereforebetter:
InthisexamplewehaveusedsomeoftheotherVisintheDAQmxpaletteraswell.
TheFrontPanelmayloooklikethis.
42 NIUSB-6008
Tutorial: Data Acquisition in LabVIEW
Inthisexampleweassumethatweconnectwiresfor“AnalogOut”and“AnalogIn”togetherlikethis(aso-calledloopbacktest).
WecanalsocommunicatewiththeDAQdevicewithoutusingtheDAQAssistant:
Formoreadvancedapplicationsthisapproachisrecommended.
[EndofExample]
43
8 LoggingtoFileInmanycasesyouwanttowriteyourdatayougetfromtheDAQdevicetoatextfileforlateruse.InthischapterwewilllearnhowtowritetoameasurementfileinLabVIEW.Wewillalsolearnhowtoreadthesamefile.
Youcanusethe“WritetoMeasurementFile”functionontheFileI/OpaletteinLabVIEWforwritingdatatotextfilesYoucansaveyourdatainatabseparatedtext(LVMdatafileformat)orasabinary(TDMSfileformat)file.
IfweusetheLVM,itiseasytoopenandviewthedatainNotepad.
8.1 WritingtoMeasurementFileWewillusethe“WritetoMeasurementFile”functionintheFileI/OpaletteinLabVIEWforwritingdatatotextfiles.WewillalsofocusontheLVMdatafileformat,nottheTDMSfileformatwhichgivebinaryfiles.
44 LoggingtoFile
Tutorial: Data Acquisition in LabVIEW
Whenyoudraginthe“WritetoMeasurementFile”,aconfigurationdialogwindowwillautomaticallypopup.
Recommendedsettingsforthe“WriteToMeasurementFile”isasfollows:
Example:
ExampleofLabVIEWProgramthatwritedatatoaMeasurementFile:
FrontPanel:
45 LoggingtoFile
Tutorial: Data Acquisition in LabVIEW
Inthisapplicationwelogdatafromaprocessbasedonamanualcontrolsignal.Boththeinputsignaluandtheoutputsignal(temperature)issavedtoaMeasurementFile.
BlockDiagram:
TheLVMfilemaylooksomethinglikethis:
46 LoggingtoFile
Tutorial: Data Acquisition in LabVIEW
Thefirstcolumnisthetime,thesecondcolumnistheinputsignal,andthethirdcolumnistheoutputsignal.
[EndofExample]
8.2 ReadfromMeasurementFile
Whenyoudraginthe“ReadfromMeasurementFile”,aconfigurationdialogwindowwillautomaticallypopup.
Recommendedsettingsforthe“ReadFromMeasurementFile”:
47 LoggingtoFile
Tutorial: Data Acquisition in LabVIEW
Example:
ExampleofLabVIEWProgramthatreaddatafromaMeasurementFile:
Thisapplicationreadsthedataandplotsitin2differentgraphs.
48 LoggingtoFile
Tutorial: Data Acquisition in LabVIEW
BlockDiagram:
[EndofExample]
Hans-PetterHalvorsen,M.Sc.
E-mail:[email protected]
Blog:http://home.hit.no/~hansha/
UniversityCollegeofSoutheastNorway
www.usn.no