tutorial: data acquisition in labview

53
University College of Southeast Norway http://home.hit.no/~hansha Data Acquisition in LabVIEW Hans-Petter Halvorsen, 2016.10.28

Upload: dinhkhanh

Post on 08-Dec-2016

259 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Tutorial: Data Acquisition in LabVIEW

UniversityCollegeofSoutheastNorway

http://home.hit.no/~hansha

DataAcquisitioninLabVIEWHans-PetterHalvorsen,2016.10.28

Page 2: Tutorial: Data Acquisition in LabVIEW

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]

Page 3: Tutorial: Data Acquisition in LabVIEW

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

Page 4: Tutorial: Data Acquisition in LabVIEW

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

Page 5: Tutorial: Data Acquisition in LabVIEW

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.

Page 6: Tutorial: Data Acquisition in LabVIEW

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.

Page 7: Tutorial: Data Acquisition in LabVIEW

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

Page 8: Tutorial: Data Acquisition in LabVIEW

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

Page 9: Tutorial: Data Acquisition in LabVIEW

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

Page 10: Tutorial: Data Acquisition in LabVIEW

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

Page 11: Tutorial: Data Acquisition in LabVIEW

7 IntroductiontoDataAcquisition

Tutorial: Data Acquisition in LabVIEW

• UpdateyourNationalInstrumentssoftware

Inadditiontothestandardtools,MAXcanexposeitem-specifictoolsyoucanusetoconfigure,diagnose,ortestyoursystem,dependingonwhichNIproductsyouinstall.AsyounavigatethroughMAX,thecontentsoftheapplicationmenuandtoolbarchangetoreflectthesenewtools.

2.3 NI-DAQmxTheNI-DAQmxDriversoftwareisthelayerofsoftwareforeasilycommunicatingwiththehardware.Itformsthemiddlelayerbetweentheapplicationsoftwareandthehardware.

Page 12: Tutorial: Data Acquisition in LabVIEW

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.

Page 13: Tutorial: Data Acquisition in LabVIEW

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.

Page 14: Tutorial: Data Acquisition in LabVIEW

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

Page 15: Tutorial: Data Acquisition in LabVIEW

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.

Page 16: Tutorial: Data Acquisition in LabVIEW

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

Page 17: Tutorial: Data Acquisition in LabVIEW

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.

Page 18: Tutorial: Data Acquisition in LabVIEW

14 Physicalinput/outputsignals

Tutorial: Data Acquisition in LabVIEW

StateDigitalsignalscannottakeonanyvaluewithrespecttotime.Thestateofadigitalsignalisessentiallythelevelofthesignal-onoroff,highorlow.Monitoringthestateofaswitch-openorclosed-isacommonapplicationshowingtheimportanceofknowingthestateofadigitalsignal.

RateTherateofadigitalsignaldefineshowthedigitalsignalchangesstatewithrespecttotime.Anexampleofmeasuringtherateofadigitalsignalincludesdetermininghowfastamotorshaftspins.Unlikefrequency,therateofadigitalsignalmeasureshowoftenaportionofasignaloccurs.Asoftwarealgorithmisnotrequiredtodeterminetherateofasignal

Page 19: Tutorial: Data Acquisition in LabVIEW

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.

Page 20: Tutorial: Data Acquisition in LabVIEW

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.

Page 21: Tutorial: Data Acquisition in LabVIEW

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:

Page 22: Tutorial: Data Acquisition in LabVIEW

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

Page 23: Tutorial: Data Acquisition in LabVIEW

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.

Page 24: Tutorial: Data Acquisition in LabVIEW

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]

Page 25: Tutorial: Data Acquisition in LabVIEW

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.

Page 26: Tutorial: Data Acquisition in LabVIEW

22 DAQDevices

Tutorial: Data Acquisition in LabVIEW

6.4 UsingDigitalI/ODigitalsignalsareelectricalsignalsthattransferdigitaldataoverawire.Thesesignalstypicallyhaveonlytwostates:onandoff,alsoknownashighandlow,or1and0.Whensendingadigitalsignalacrossawire,thesenderappliesavoltagetothewireandthereceiverusesthevoltageleveltodeterminethevaluebeingsent.Thevoltagerangesforeachdigitalvaluedependonthevoltagelevelstandardbeingused.

Digitalsignalshavemanyusers:

• DigitalsignalscontrolormeasuredigitaldevicessuchasswitchesorLEDs

Page 27: Tutorial: Data Acquisition in LabVIEW

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.

Page 28: Tutorial: Data Acquisition in LabVIEW

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”.

Page 29: Tutorial: Data Acquisition in LabVIEW

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.

Page 30: Tutorial: Data Acquisition in LabVIEW

26 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Toactuallyperformtheloopbacktest,right-clickontheNIUSB-6008deviceinMAX,andthenselect“TestPanels..”inordertoopentheTestPanels.IntheTestPanelswindow,selecttheAnalogOutputtab.

Page 31: Tutorial: Data Acquisition in LabVIEW

27 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

IntheAnalogOutputtab,selectanyvoltagebetween0Vand5V.

Next,clicktheAnalogInputtabintheTestPanelswindow.

Page 32: Tutorial: Data Acquisition in LabVIEW

28 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

TheAnalogInputtabshouldindicatethesame(oralmostthesame)voltageasissetoutonAO0.TheremaybeasmalldifferencebetweenthevaluesduetothelimitedresolutionintheDA-converter(digital-to-analog)andintheAD-converter(analog-to-digital).

Page 33: Tutorial: Data Acquisition in LabVIEW

29 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Youshouldalsoalwaysuseamulti-metertocheckifthevoltagelevelsontheoutputandinputchannelsarecorrectaccordingtoyoursettings.

Page 34: Tutorial: Data Acquisition in LabVIEW

30 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

7.2 UsingNIUSB-6008inLabVIEWInordertousetheNIUSB-6008inLabVIEWyouneedtousetheDAQmxfunctions,seeFigurebelow.

DAQmx–DataAcquisitionpalette:

Page 35: Tutorial: Data Acquisition in LabVIEW

31 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

7.3 DAQAssistantTheeasiestwaysistousetheDAQAssistant.

7.3.1 AnalogInput

WhenyoudragtheDAQAssistanticononyourBlockDiagram,thefollowingwindowappears:

Page 36: Tutorial: Data Acquisition in LabVIEW

32 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Inthiswindowyouneedtoselecteither“AcquireSignals”(i.e.,InputSignals)or“GenerateSignals”(i.e.,OutputSignals).

SelectAcquireSignals→AnalogInput→Voltage.

Page 37: Tutorial: Data Acquisition in LabVIEW

33 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

InthenextwindowyouselectwhichAnalogInputyouwanttouse.Selectai0(AnalogInputchannel0)andclickFinish.

Thefollowingwindowappears:

Page 38: Tutorial: Data Acquisition in LabVIEW

34 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

IntheTimingSettingsSelect“1Sample(OnDemand)”.

Page 39: Tutorial: Data Acquisition in LabVIEW

35 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

ThenextstepistoselecttheSignalInputRange.Acommonsignalis0-5V.

Youmayalsorenamethenameofthechannel(right-clickonthename):

Page 40: Tutorial: Data Acquisition in LabVIEW

36 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Youarenowfinishedwiththeconfiguration.ClickOKintheDAQAssistantwindowTheDAQAssistanticonappearsontheBlockDiagram:

Page 41: Tutorial: Data Acquisition in LabVIEW

37 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Example:

Wirethedataoutputtoanumericindicatorlikethis(andhittheRunbutton):

Thennumericindicatorwillshow,e.g.,thefollowingvalue:

[EndofExample]

Example:

Ifyouwanta“continuous”acquisition,putaWhilelooparoundtheDAQAssistantlikethis:

WecanalsocommunicatewiththeDAQdevicewithoutusingtheDAQAssistant:

Page 42: Tutorial: Data Acquisition in LabVIEW

38 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Formoreadvancedapplicationsthisapproachisrecommended.

[EndofExample]

7.3.2 AnalogOutput

AnalogOutputissimilar.

Page 43: Tutorial: Data Acquisition in LabVIEW

39 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Page 44: Tutorial: Data Acquisition in LabVIEW

40 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Example:

Orinsidealoopfor“continuous”writingtotheDAQdevice:

Page 45: Tutorial: Data Acquisition in LabVIEW

41 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

HoweveryoushouldnotusetheDAQAssistantinsidealoopbecauseofthelackofperformance.Thefollowingisthereforebetter:

InthisexamplewehaveusedsomeoftheotherVisintheDAQmxpaletteraswell.

TheFrontPanelmayloooklikethis.

Page 46: Tutorial: Data Acquisition in LabVIEW

42 NIUSB-6008

Tutorial: Data Acquisition in LabVIEW

Inthisexampleweassumethatweconnectwiresfor“AnalogOut”and“AnalogIn”togetherlikethis(aso-calledloopbacktest).

WecanalsocommunicatewiththeDAQdevicewithoutusingtheDAQAssistant:

Formoreadvancedapplicationsthisapproachisrecommended.

[EndofExample]

Page 47: Tutorial: Data Acquisition in LabVIEW

43

8 LoggingtoFileInmanycasesyouwanttowriteyourdatayougetfromtheDAQdevicetoatextfileforlateruse.InthischapterwewilllearnhowtowritetoameasurementfileinLabVIEW.Wewillalsolearnhowtoreadthesamefile.

Youcanusethe“WritetoMeasurementFile”functionontheFileI/OpaletteinLabVIEWforwritingdatatotextfilesYoucansaveyourdatainatabseparatedtext(LVMdatafileformat)orasabinary(TDMSfileformat)file.

IfweusetheLVM,itiseasytoopenandviewthedatainNotepad.

8.1 WritingtoMeasurementFileWewillusethe“WritetoMeasurementFile”functionintheFileI/OpaletteinLabVIEWforwritingdatatotextfiles.WewillalsofocusontheLVMdatafileformat,nottheTDMSfileformatwhichgivebinaryfiles.

Page 48: Tutorial: Data Acquisition in LabVIEW

44 LoggingtoFile

Tutorial: Data Acquisition in LabVIEW

Whenyoudraginthe“WritetoMeasurementFile”,aconfigurationdialogwindowwillautomaticallypopup.

Recommendedsettingsforthe“WriteToMeasurementFile”isasfollows:

Example:

ExampleofLabVIEWProgramthatwritedatatoaMeasurementFile:

FrontPanel:

Page 49: Tutorial: Data Acquisition in LabVIEW

45 LoggingtoFile

Tutorial: Data Acquisition in LabVIEW

Inthisapplicationwelogdatafromaprocessbasedonamanualcontrolsignal.Boththeinputsignaluandtheoutputsignal(temperature)issavedtoaMeasurementFile.

BlockDiagram:

TheLVMfilemaylooksomethinglikethis:

Page 50: Tutorial: Data Acquisition in LabVIEW

46 LoggingtoFile

Tutorial: Data Acquisition in LabVIEW

Thefirstcolumnisthetime,thesecondcolumnistheinputsignal,andthethirdcolumnistheoutputsignal.

[EndofExample]

8.2 ReadfromMeasurementFile

Whenyoudraginthe“ReadfromMeasurementFile”,aconfigurationdialogwindowwillautomaticallypopup.

Recommendedsettingsforthe“ReadFromMeasurementFile”:

Page 51: Tutorial: Data Acquisition in LabVIEW

47 LoggingtoFile

Tutorial: Data Acquisition in LabVIEW

Example:

ExampleofLabVIEWProgramthatreaddatafromaMeasurementFile:

Thisapplicationreadsthedataandplotsitin2differentgraphs.

Page 52: Tutorial: Data Acquisition in LabVIEW

48 LoggingtoFile

Tutorial: Data Acquisition in LabVIEW

BlockDiagram:

[EndofExample]

Page 53: Tutorial: Data Acquisition in LabVIEW

Hans-PetterHalvorsen,M.Sc.

E-mail:[email protected]

Blog:http://home.hit.no/~hansha/

UniversityCollegeofSoutheastNorway

www.usn.no