You are on page 1of 40

Exercise 1: Create a Simple LabVIEW VI

Inthisexercise,youwillcreateasimpleLabVIEWVIthatsimulatesananalogsignalandplotsitonawaveform graph.TheUserInterfaceyoucreatewillenableyoutochangetheattributesofthesimulatedsignal. 1.Ifyouhavenotalreadydoneso,launchLabVIEW.ClicktheLabVIEWicononyourquicklaunchtoolbar,orclick StartProgramsNationalInstrumentsLabVIEW2009. OnceyoulaunchLabVIEW,theGettingStartedwindowappears:

TheLabVIEWGettingStartedwindowappearseachtimeyoulaunchLabVIEWtoassistyouincreatingnew applicationsoropeningexistingapplications.AdditionallyyoucanuselinksontheGettingStartedwindowtofind localandonlinehelpresourcesoropenexampleprogramstoaidinapplicationdesign. 2.ClickMore 3.ExpandFromTemplate.Noticethedifferentcategoriesontheleftofthewindowthatcorrespondtothetypes oftasksfromwhichyoucanchoose.YoucanselectBlankVItostartfromscratch.TherearealsoTemplateVIsto useasastartingpointforbuildingyourapplication.ProjectsandOtherFilesaremoreadvancedcomponentsand willnotbedescribedindetail.TogetmoreinformationonanyofthelistingsintheNewDialogBox,clicktheHelp buttoninthelowerrightcornerofthewindow. 1

4.SelectVIFromTemplateTutorial(GettingStarted)GenerateandDisplayandclickOK.

Twowindowsappear.Thegreywindowisthefrontpanel,andthewhiteoneistheblockdiagram.Thefrontpanel containsthepartsofyourVIusedforpresentinginformation,whereastheblockdiagramcontainsthecodethat controlsthefunctionalityoftheVI. 5.ExaminethefrontpanelandblockdiagramofthistemplateVI.ThefrontpanelcontainsaWaveformChartand aSTOPbuttonasshowninthefollowingfigure.

Hoverthecursoroverthedifferentobjectsonthefrontpanel.Noticethatyourcursorturnstoapointerfinger whenabovetheStopbutton,andturnstoatexteditorwhenaboveatextfield.Bydefault,LabVIEWsAutomatic ToolSelectionwillchangethecursordependingonwhatoperationsarepossible.Alsonoticethatasyoumove overanyobject,resizingboxesappearonitsedges.Tryresizingafewobjectssizes.

YoucantogglebetweenthetwowindowsbyselectingWindowShowBlockDiagramorWindowShowFront Panel.Youcanalsoswitchbetweenthewindowsbypressing<CtrlE>onthekeyboard. TheblockdiagramcontainsaSimulateSignalVI,whichiscurrentlyconfiguredtosimulateasinewaveandplotit tothechart.

6.Switchbacktothefrontpanelbypressing<CtrlE>.Noticethemenubaratthetopofthewindow.Sincethe Runbutton(thewhitearrowinthetopleftcorner)issolid,youcanrunthisVIasitis.ClicktheRunbuttonand examinetheoperationoftheVI.Whenyouarefinished,clicktheSTOPbuttononthefrontpaneltostoprunning theVI.

Note:Asyouwillseelaterintheexercise,whentheRunbuttonintheupperleftcornerofboththefrontpanel andtheblockdiagramchangesfromasolidwhitearrow,toabrokengreyarrow,indicatesthatthereare unresolvederrorsinthecode.YoucanpressthebrokenRunarrowtoassistyouinresolvingtheseerrors.

7.Wewillnowaddcontrolstoadjustsignalfrequencyandamplitudewhiletheprogramisrunning.Openthe Controlspalette(ifitisnotopenalready)byrightclickingthefrontpanelwindow.Asmallpushpiniconinthe upperleftcornerofthispaletteappears.Clickthispushpintoforcethepalettetoremainonyourscreen.

8.ClicktheNumericControlspalette,andselectaKnobtobeplacedonthefrontpanel.Todothis,clickthe Knobanddragittothefrontpanel.Clickoncetoplaceit

9.DoubleclickontheknobslabelandchangeittoAmplitude.

10.Repeatsteps79tomakeanotherknobforfrequency.ChangeitslabeltoFrequency.Doubleclickthe maximumvalueonFrequencysscaleandchangeitto50. 4

11.Ontheblockdiagram,movetheAmplitudeandFrequencycontrolsinsideofthewhileloopandconnectthem totheassociatedinputsoftheSimulateSignalExpressVI.Oncebothterminalsareinsidethewhileloop,onthe leftsideoftheSimulateSignalExpressVI,hoveryourcursorovertherightsideofeachterminaluntilthewiring toolappearsonthecursor.LeftclickanddragtheconnectiontotheidenticallynamedinputontheExpressVI. Yourblockdiagramshouldlookliketheimagebelow.

FrontPanel

BlockDiagram

12.UseBlockDiagramCleanuptoorganizeyourblockdiagram.Asyouprogram,andespeciallyasyoulearnhow toprograminLabVIEW,youarenotalwaysthinkingaboutlayoutandreadability.Thiscanresultinpoorly organizedblockdiagram.PresstheBlockDiagramCleanupiconfoundonthemenubarwhichwillorganizethe blockdiagramforyou.

Note:TocustomizehowtheBlockDiagramCleanuptoolorganizesyourcodeyoucanchangesettingsinthe BlockDiagram:CleanupsectionoftheOptionsmenu(ToolsOptions). 13.HighlightExecutionisadebuggingtoolthatallowsyoutoobservehowyourapplicationruns.Pressthe HighlightExecutionbuttononthemenubar.Noticethatthelightbulbiconnowappearstobeon.Thenhitthe Runbuttonwhilststillontheblockdiagramandwatchthedataflowthroughthewires.Stoptheapplicationand presstheHighlightExecutionbuttontodisableit.

14.UseContextHelptoidentifyobjectdetailswhileprogramming.PresstheContextHelpbuttonintheupper rightportionoftheblockdiagram.

15.WiththeContextHelpactive,hoveryourcursoroverdifferentobjectsontheblockdiagramandfrontpanel ofyourVI.Asyoudoso,theContextHelpWindowprovidesdetailsincludingdescriptionsandwiringdiagrams.

16.Rightclickontheblockdiagramandnavigatearoundthepalettes.NoticethattheContextHelpwindow providesdetailsontheobjectswhiletheyareinthepalettes.Alsonoticethatforsomeobjects,theContextHelp windowprovidesalinkforDetailedHelpThislinkwillopentheLVHelpandgiveyoumoreinformation. 17.SavetheVIintheC:\Seminars\DAQHandsOn\ExercisesfolderbyusingtheFilemenuandnameit Exercise1.vi. Note:BesuretosavethisVI,asyouwillbeusingitlaterintheseminar.Youcanaccessthefolderbythefolder shortcutonthedesktop EndofExercise1 6

Exercise 2a: Take a Basic Measurement with CompactDAQ


ThepurposeofthisexerciseistouseLabVIEWandNICompactDAQtoquicklysetupaprogramtoacquire temperaturedata. SetuptheHardware 1.MakesurethattheNICompactDAQchassis(cDAQ9172)ispoweredon. 2.ConnectthechassistothePCusingtheUSBcable. 3.TheNIDAQmxdriverinstalledonthePCautomaticallydetectsthechassisandbringsupthefollowingwindow.

4.ClickonConfigureandTestThisDeviceUsingNIMeasurement&AutomationExplorer(MAX). Note:NIMeasurement&AutomationExplorerisaconfigurationutilityforallNationalInstrumentshardware. 5.TheDevicesandInterfacessectionunderMySystemshowsalltheNationalInstrumentsdevicesinstalledand configuredonyourPC.TheNIDAQmxDevicesfoldershowsalltheNIDAQmxcompatibledevices.Bydefault,the NICompactDAQchassisNIcDAQ9172showsupwiththenamecDAQ1. 6.ThissectionofMAXalsoshowstheinstalledmodulesaswellasemptyslotsintheCompactDAQchassis. 7.RightclickonNIcDAQ9172andclickonSelfTest.

8.Thedevicepassestheselftest,whichmeansithasinitializedproperlyandisreadytobeusedinyourLabVIEW application.CloseMAX. 7

ProgramLabVIEWApplication 9.CreateanewVI.OntheLabVIEWmenubarclickFileNewVI.Onceopened,SavetheVIinthe C:\Seminars\DAQHandsOn\ExercisesfolderunderthenameExercise2a.vi. 10.Press<Ctrl+T>totilefrontpanelandblockdiagramwindows. 11.PulluptheFunctionsPalettebyrightclickingonthewhitespaceontheLabVIEWblockdiagramwindow. 12.MoveyourmouseovertheExpressInputpalette,andclicktheDAQAssistantExpressVI.Leftclickonthe emptyspacetoplaceitontheblockdiagram.

13.TheCreateNewExpressTaskwindowthenappears:

14.Toconfigureatemperaturemeasurementapplicationwithathermocouple,clickonAcquireSignalsAnalog InputTemperatureThermocouple.Clickthe+signnexttothecDAQ1Mod1(NI9211),highlightchannelai0, andclickFinish.Thisaddsaphysicalchanneltoyourmeasurementtask.

15.ChangetheCJCSourcetoBuiltInandAcquisitionModetoContinuousSamples.ClicktheRunbutton.Youwill seethetemperaturereadingsfromthethermocoupleintestpanelwindow.

16.ClickStopandthenclickOKtoclosetheExpressblockconfigurationwindowtoreturntotheLabVIEWblock diagram. 17.LabVIEWautomaticallycreatesthecodeforthismeasurementtask.ClickYestoautomaticallycreateaWhile Loop.

18.RightclickthedataterminaloutputontherightsideoftheDAQAssistantExpressVIandselectCreate GraphIndicator.RenameWaveformGraphtoTemperature.

19.Noticethatagraphindicatorisplacedonthefrontpanel. 20.Yourblockdiagramshouldnowlooklikethefigurebelow.Thewhileloopautomaticallyaddsastopbuttonto yourfrontpanelthatallowsyoutostoptheexecutionoftheloop.

21.Ratherthandisplayingourdatainagraphindicator,wewanttodisplayourtemperaturereadingsina thermometerindicator.Todothis,gotothefrontpanelbypressing<CtrlE>.Rightclickthegraphindicatorand selectReplace.TheControlspalettewillappear.SelectModernNumericThermometer.Thethermometer indicatorshouldnowappearinsteadofthegraphindicator.

10

22.Also,rightclickonthestop(F)buttonandselectReplace.TheControlspalettewillappear.Select BooleanStopButton.

23.Youcanusethepropertypageforanyfrontpanelobjecttochangeanyofitsassociatedproperties.Modify thethermometerindicatorbyrightclickingitandselectingProperties.OntheAppearanceTab,changetheLabel toTemperature.

11

24.OntheScaletab,changetheMinimumto20andtheMaximumto30.

25.ClickOKwhenyouarefinishedandsavetheVI. ExpressVIsmakecreatingbasicapplicationsveryeasy.Theirconfigurationdialogsallowyoutosetparameter andcustomiseinputsandoutputsbasedonyourapplicationrequirements.However,tooptimizeyourDAQ applicationsperformanceandallowforgreatercontrolyoushouldusestandardDAQmxdriverVIs.RightClick onblockdiagramFunctionsMeasurementI/OPaletteNIDAQmx. 26.BeforeyougenerateDAQmxcodeyouneedtoremoveallthecodethatwasautomaticallycreatedbythe ExpressVI.RightclickonthewhileloopandselectRemoveWhileLoop.ThenclickontheStopbuttoncontrol, andpresstheDeletekeytoremovetheStopbutton.RepeatactionsforTemperatureGraphaswellasany additionalwiresthatmayremain.Youcanpress<Control+B>toremoveallunconnectedwiresfromablock diagram.

12

27.ConvertExpressVIcodetostandardVIs.WhilenotallExpressVIscanbeautomaticallyconvertedtostandard VIs,theDAQAssistantcan.Thiswillallowforgreaterapplicationcontrolandcustomization.Rightclickonthe DAQAssistantExpressVIyoucreatedinthisexerciseandselectGenerateNIDAQmxCode.

Yourblockdiagramshouldnowappearsomethinglikethis:

TheExpressVIhasbeenreplacedbytwoVIs.Wellexaminetheirfunctionalityinthefollowingsteps. 28.OpenContextHelpbyclickingontheContextHelpiconontheupperrightcorneroftheblockdiagram. HoveryourcursorovereachVIandexaminetheirdescriptionsandwiringdiagram. 29.DAQmxRead.vireadsdatabasedontheparametersitreceivesfromthecurrentlyuntitledVIonthefarleft. 30.DoubleclickontheuntitledVIandopenthatVIsblockdiagram(codeshownbelow).

13

AlltheparametersthatarewiredasinputstothedifferentDAQmxsetupVIsreflectthesettingyouoriginally configuredintheDAQAssistantExpressVI. Note:BymovingtheseparametersandsetupVIsontotheblockdiagram,youcannowprogrammatically changetheirvalueswithouthavingtostopyourapplicationandopentheExpressVIconfigurationdialog, savingdevelopmenttimeandpossiblyoptimizingperformancebyeliminatingunnecessarysettingsdepending onyourapplication. UsingtheLabVIEWExampleFinder TheLabVIEWExampleFinderprovideshundredsofexampleapplicationtouseasreferenceorasthestarting pointforyourapplication. 31.OpentheLabVIEWExampleFindertofindDAQexamplesthatuseDAQmxstandardVIs.GotoHelpFind ExamplestolaunchtheLabVIEWExampleFinder.LabVIEWthenindexesalltheexamplesinstalledonthelocal machine. 32.BrowsetotheDAQmxTemperaturefolderfromtheBrowsetabatHardwareInputandOutputDAQmx AnalogMeasurementsTemperature.DoubleClickontheAcqThermocoupleSample.vitoopenit.

14

33.ThefollowingVIwillthenappear:

34.SetthePhysicalChanneltomatchtheCompactDAQchassischannelandruntheapplication.Expandthe physicalchannelcontrolfromtheFrontPanelandselectcDAQ1Mod1/ai0.

PresstheRunbuttonseveraltimeswhileholdingandreleasingthethermocoupleontheCompactDAQchassis andobservethevaluechangeonthefrontpanel. 35.Opentheblockdiagramandexaminethecode.ThisVIonlyusesstandardVIsinsteadofExpressVIs,which allowsmuchmorecustomizationofinputsandruntimeconfiguration.AcqThermocoupleSample.vihasnowhile looptoallowforcontinuousexecution,andtheremainingstepsofthisexercisewillfocusonaddingthat functionality. 15

36.AddawhileloopandStopbuttontoAcqThermocoupleSample.vi.Rightclickontheblockdiagramtobring uptheFunctionspalette.FindtheWhileLoopontheProgrammingStructurespaletteanddragawhileloop overtheDAQmxRead.vi.YoumayneedtospreadtheVIsacrosstheblockdiagramsothatthereisroom.You cancreateadditionalspacebyholdingtheControlkeyanddraggingaboxontheblockdiagramorfrontpanel.

37.RightclickontheWhileLoopsConditionalterminalandselectCreateControl.Thisautomaticallywiresa Stopbuttontotheterminal.

NoticethattheStopbuttonhasappearedonthefrontpanel. 38.RuntheVI.AcqThermocoupleSample.vinowrunscontinuously. 39.SavethecustomizedexampleVI.GotoFileSaveAs,selectCopySubstituteCopyforOriginalandname theVITemperature.viSavetheVIintheC:\Seminars\DAQHandsOn\Exercisesfolder.Thisallowsforfurther developmentwithoutoverwritingtheLabVIEWexample. EndofExercise2a

16

Exercise 2b: Add Analysis and Digital Output to the DAQ Application
SetupHardware 1.ConfirmthattheCompactDAQchassisispoweredonandconnectedtothePCviatheUSBcable.Ifnot,orifit isnotbehavingasexpected,repeatsteps18fromExercise2a. LabVIEWApplicationComparesignaltouserdefinedalarm 2.Exercise2bisfunctionallythesameastheendresultofExercise2a.YoucanopenExercise2b.vifromthe Exercisesfoldertosynchronisewiththeillustrationsinthissection.TheVIwillappearliketheimagebelow,with additionalspaceontheblockdiagramtoaddfunctionality:

3.Createanalarmthatsignalsifacquiredtemperaturegoesaboveauserdefinedlevel.Onthefrontpanel, rightclicktoopentheControlspaletteExpressNumericandplaceaVerticalPointerSlideonthefrontpanel.

17

4.RightclicktheVerticalPointerSlideandselectProperties.Apropertypagewillappear.Examinethedifferent propertiesthatyoucanmodify.MakethefollowingchangesontheAppearance. Label:AlarmLevel Slider1:CheckShowdigitaldisplay(s)

5.OntheScaletabmakethefollowingchangestoScaleRangeandclickOKtoapplythechanges. Maximum:30

18

6.UsetheComparisonExpressVItocomparetheacquiredtemperaturesignalwiththeAlarmLevelcontrol. Switchtotheblockdiagram,rightclickonanemptyspaceandopentheFunctionspalette.Placethe ComparisonExpressVIontheblockdiagramfromFunctionsExpressArithmetic&ComparisonComparison.

7.Onceplacedontheblockdiagram,theComparisonExpressVI'sconfigurationdialogwillappear.

Select">Greater"intheCompareConditionsectionand"Secondsignalinput"fromtheComparisonInputs sectionthenclickOK.

19

8.ConnecttheacquiredtemperaturedataandAlarmLevelinputstotheComparisonExpressVI.Hoveroverthe outputoftheDAQAssistantuntilthewiringtoolappearsonyourcursor,thenleftclickanddragyoumouseto theOperand1inputontheComparisonExpressVI.Performthesamehover,dragandconnecttowiretheAlarm LevelcontrolandtheOperand2inputontheComparisonExpressVI.Yourblockdiagramshouldnowlooklike this:

9.DisplaytheresultoftheComparisonExpressVIonthefrontpanel.Onthefrontpanel,rightclick,openthe ControlspaletteandaddaSquareLEDindicator.ThesquareLEDisfoundatExpressLED.ResizetheSquareLED sothatitiseasiertoseeandrenameit"Alarm."Yourfrontpanelshouldlooklikethis:

20

10.Ontheblockdiagram,wiretheoutputoftheComparisonExpressVItotheinputoftheAlarmindicator's terminal.

11.Runtheapplication.PresstheRunbuttonandthenchangetheAlarmLevelcontroltosomelevelabovethe currentacquiredtemperaturesignal.HoldthethermocoupleuntilthetemperatureexceedstheAlarmLevel value.TheAlarmLEDturnsonwhentheacquiredtemperaturesignalgoesabovethelevelsetonthefrontpanel. OutputAlarmtoCompactDAQChassis 12.UseanotherDAQAssistantExpressVItooutputAlarm'sstatustotheCompactDAQ's9472module.Open theFunctionspaletteontheblockdiagramandfindtheDAQAssistantExpressVIatFunctionsExpressOutput.

21

13.SelectGenerateSignalsDigitalOutputLineOutputfromtheCreateNewExpressTaskwindow.

14.Selectthephysicalchannelyouwanttouseasoutput.Expandthe+signnexttocDAQ1Mod4inthe followingwindowandselectport0/line0.

15.PressOKintheDAQAssistantwindowthatappears,sinceallofitssettingsarecorrectfortheapplication. 22

16.CreateanadditionalwirethatconnectstheComparisonExpressVIsResultoutputtothedatainputonthe newDAQAssistantExpressVI.AConvertfromDynamicDatafunctionappearsautomatically.LabVIEWwill alwaystrytocoerceunlikedatatypeswhentwonodesarewiredtogether.Inthiscase,theoutputofthe CompareExpressVIisaDynamicDatatype,andtheinputoftheDAQAssistantisBoolean.LabVIEWplacedthe ConvertfromDynamicDatanodeinbetweenthetwonodessotheycouldbeconnected.Youcandoubleclick theConvertfromDynamicDatatoviewitsconfiguration.Yourblockdiagramshouldnowlooklikethis:

17.RuntheVI.PresstheRunbutton.NoticethattheLEDbankontheCompactDAQ9472moduleturnsonand offtomatchAlarm'svalueonthefrontpanel. 18.SaveandclosetheVI. EndofExercise2b

23

Exercise 3a: Writing Data to File with LabVIEW


1.Ifnotalreadyopened,openExercise2b.vifromtheExercisesfolderfoundinC:\Seminars\DAQHands On\Exercises. 2.RightclickontheblockdiagramandselectFunctionsExpressOutputWritetoMeasurementFileand placeitinsidetheWhileLoopontheblockdiagram.

3.Aconfigurationwindowwillappear.ConfigurethewindowasshownbelowandclickOK.

Note:ClickontheHelpbuttonforamoredetailedexplanationofthesettingsinthisdialogbox. 24

4.WiretheoutputoftheDAQAssistantExpressVItotheinputoftheWritetoMeasurementFileExpressVI. 5.Yourblockdiagramshouldnowresemblethefollowingfigure.

6.SavetheVIintheC:\Seminars\DAQHandsOn\ExercisesfolderbyusingtheFileSaveAsmenu,selectthe CopySubstituteCopyforOriginalandnameitExercise3a.vi. 7.RuntheVImomentarilyandpressSTOPtostoptheVI. 8.Yourfilewillbecreatedinthefolderspecified. 9.OpenthefileusingMicrosoftOfficeExcelorNotepad.Reviewtheheaderandtemperaturedatasavedinthe file. 10.Closethedatafile. EndofExercise3a 25

Exercise 3b: Controlling Program Execution


InthisexerciseyouwilluseaCaseStructuretoaddintelligenceintoyourapplication.Youaregoingtomodifythe VIsothatthetemperatureisonlyloggedtodiskifthealarmconditionismet. 1.Ifnotalreadyopened,openExercise3a.vifromtheExercisesfolderfoundinC:\Seminars\DAQHands On\Exercises. 2.SelecttheCaseStructurefromtheExecutionControlpaletteandplaceitaroundtheWritetoMeasurement FileExpressVIasshownbelow.

Thecasestructurehasoneormoresubdiagrams,orcases,exactlyoneofwhichexecuteswhenthestructure executes.ThevaluewiredtotheselectorterminaldetermineswhichcasetoexecuteandcanbeBoolean,string, integer,orenumeratedtype.Rightclickthestructurebordertoaddordeletecases.Thecodeforthesedifferent stateswouldresidewithintheboundariesofthecasestructure,andyouwouldswitchbetweenthestateswith eitherbuttonsonafrontpanelorsomecombinationoflogicbuiltintoyourLabVIEWapplication. 3.ExaminetheCaseStructure.

26

4.WiretheResultfromtheCompareExpressVItotheselectorterminalofthecasestructureasshownbelow.

Nowthedatawillonlybeloggedtodiskwhenthealarmisactive.BecausetheFalsecaseisempty,nothingwill happenwhenalarmconditionisnotmet. 5.SavetheVIintheC:\Seminars\DAQHandsOn\ExercisesfolderbyusingtheFileSaveAsmenu,selectthe CopySubstituteCopyforOriginalandnameitExercise3b.vi. 6.RuntheVI.Changethealarmlevelandheatthethermocouplesothatthealarmgoesonandoffafewtimes. PressSTOPtostoptheVI. 7.Yourfilewillbecreatedinthefolderspecified. 8.OpenthefileusingMicrosoftOfficeExcelorNotepad.Reviewtheheaderandtemperaturedatasavedinthe file. 9.Closethedatafile. 27

OptionalSteps AddlogictotheVIsoitwillstopeitherwhenyoupresstheSTOPbuttonorwhentheloopiterationshave exceeded10,000. 1.InsertanOrgatefromtheBooleanpalettebeforetheSTOPbutton,byrightclickingonthegreenwireoutof thestopterminal,asshownbelow.

2.NextSelectthegreaterthanfunctionfromtheComparisonspalette.

28

3.Wireasfollows.

4.RightclickontheopenterminalofthegreaterthanblockandselectCreateConstant.

5.Changetheconstantto10000asshownbelowandSaveandRuntheVI.

29

6.SavetheVIintheC:\Seminars\DAQHandsOn\ExercisesfolderbyusingtheFileSaveAsmenu,selectthe CopySubstituteCopyforOriginalandnameitExercise3b.vi. 7.Finally,openandexaminetheStateDiagramtemplatethatshipswithLabVIEW.SelectFileNewandselect StandardStateMachinefromthelistboxasshownbelow.Examinethecommentsincludedonthetemplate. ThereareseveraltemplatessuchasthisonetohelpyougetstartedwithyourLabVIEWapplications.Takeafew minutestofamiliarizeyourselfwithwhatisavailable.

EndofExercise3b.

30

(Optional) Exercise 4: Multiple Operations with Analog I/O


1.IfyouclosedLabVIEWafterthelastexercise,launchit.OpenanewVI. 2.Press<CtrlE>toswitchtotheLabVIEWblockdiagram. 3.BrowsetotheInputsubpaletteontheFunctionsExpresspaletteandclicktheSimulateSigExpressVIas shownbelow.PlacetheVIontheblockdiagram.

4.IntheSignalsectionofthewindow,setAmplitudeto5. 5.IntheTimingsectionofthewindow,setSamplespersecond(Hz)to10,000.ClickOK.

6.BringuptheFunctionsExpresspaletteagain,andbrowsetotheDAQAssistantExpressVIontheOutput subpaletteoftheFunctionspalette.PlacetheVIontheblockdiagram. 31

7.IntheCreateNewwindow,selectAnalogueOutputastheMeasurementTypeandthenselectVoltage.

8.Inthenextwindow,clickthe+signnexttocDAQ1Mod3(NI9263),selectao0,andclicktheFinishbutton.

32

9.IntheDAQAssistantconfigurationwindow,selectContinuousSamplesfromtheTaskTimingtabinthelower partofthewindow.UncheckUsetimingfromwaveformdata,settheSamplestowriteandRate(Hz)to10,000. ClicktheOKbuttonandselectnowhenaskedifyouwanttoinsertawhileloop.

10.Ontheblockdiagram,movetheDAQAssistantExpressVItotherightsideoftheSimulateSignalExpressVI. WiretheSineoutputoftheSimulateSignalVItothedatainputoftheDAQAssistantVI.Tocreateawire,move yourcursoroverthebluearrowontheSineoutputterminaloftheSimulateSignalVIandleftclicktostartthe wire.MoveyourcursortothedatainputterminaloftheDAQAssistantVIandleftclickagaintoattachthewire. Yourblockdiagramshouldresemblethefollowingfigure.

33

11.TomaketheVIruncontinuously,createaWhileLoop.AWhileLoopcausesallpartsoftheprograminsidethe looptoruncontinuouslyuntilaStopbuttonisclicked.TocreatetheWhileLoop,browsetotheExecCtrl subpaletteoftheFunctionspaletteandselectaWhileLoop.

12.DrawtheWhileLooparoundyourentireblockdiagram.Yourblockdiagramshouldresemblethefollowing figure.

13.Tocreateaslidecontrolforvaryingthefrequencyofthesinewave,press<CtrlE>toswitchtotheLabVIEW frontpanel.RightclickontheemptygreyspacetopulluptheControlspalette.SelectVerticalPointerSlidefrom theNumericControlssubpaletteoftheControlspalette.Placetheverticalpointerslideonthefrontpanel.

34

14.RightclicktheslidecontrolandselectProperties.OntheAppearancetab,changethelabeltoFrequency.On theScaletab,changetheScaleRangesoMinimumequals0.00andMaximumequals1000.00.ClickOKtoclose thePropertieswindow. 15.Press<CtrlE>toswitchtotheblockdiagram.NoticetheorangeFrequencyslidecontrolterminal.Movethe controlinsidetheWhileLooptotheleftsideoftheSimulateSignalExpressVI.Wiretheknobcontroltothe FrequencyinputterminaloftheSimulateSignalExpressVI(thesecondorangearrowontheleftsideofthe SimulateSignalExpressVI). Note:MakesurethatyouwiretheknobcontroltothecorrectinputterminaloftheSimulateSignalExpressVI.If youmakeabadwireconnection,doubleclickthewiretoselectitandpress<Delete>. Yourblockdiagramshouldresemblethefollowingfigure.

16.ThisVIwillnowusethefrequencyslideontheLabVIEWfrontpaneltogenerateasinewaveatthespecified frequency.Thissinewaveisthengeneratedonanalogoutputchannel0oftheNI9263CSeriesmodulebythe DAQAssistantExpressVI. 17.SavetheVIasAnalogoutput.viintheC:\Seminars\DAQHandsOn\Exercisesfolder. 18.IncreasethesizeoftheblockdiagramwindowtomakespaceforanotherWhileLooptogobelowtheexisting AnalogOutputcode.

35

19.PlaceaDAQAssistantExpressVIfromtheInputsubpaletteoftheFunctionsExpresspalette.SelectAnalog InputastheMeasurementTypeandselectVoltage.Inthenextwindow,expandchannelsofthecDAQ1Mod2(NI 9215)byselectingthe+sign,andselectai0.ClicktheFinishbutton.

20.IntheDAQAssistantwindow,selectContinuousSamplesfromtheTaskTimingtabinthelowerpartofthe window.SettheSamplestowriteandRate(Hz)to10,000andclickOK.

36

21.OnceyouclickOK,adialogwindowwillappearaskingifyouwouldliketocreateaWhileLooparoundthe DAQAssistant.SelectYestoautomaticallycreateaWhileLoopforthiscontinuousacquisition.

22.Theblockdiagramshouldresemblethefigureabove.Next,createagraphindicatortodisplaytheanalog inputdata.Tocreateagraphindicator,rightclickthedataoutputterminaloftheDAQAssistantExpressVI,and selectCreateGraphIndicator.

37

23.Belowisapictureofthecompletedblockdiagram.

24.Press<CtrlE>toswitchtotheLabVIEWfrontpanel. 25.Locatethestop(F)PushButtoncontrolandrightclicktoreplaceitwithaStopButtoncontrol,asshownon thediagrambelow.(ReplaceBooleanStopButton)

38

26.Rearrangethefrontpanelcontrolsandindicatorstoresemblethefigurebelow.

27.SavetheVIasAnalogInputandOutput.viintheC:\Seminars\DAQHandsOn\Exercisesfolder. 28.RuntheVI 29.Theanalogoutputloopisgeneratingasinewaveonanalogoutputchannel0,whichiswireddirectlyto channel0oftheanaloginputmodule.Usetheslidercontrolonthefrontpaneltocontrolthesinewave frequency,andlookatthegraphonthefrontpaneltomonitorthesinewave. 30.Pressbothstopbuttonstostoptheexecutionofbothloops. 39

BeyondtheExercise ForLoopscanbeusedtogeneratearraysusingafeaturecalledautomaticindexing,asshowninthefollowing figure.

Trybuildingthefollowingblockdiagramtofurthermanipulatethewaveformbeinggenerated.

EndofExercise4

40

You might also like