LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with DAQ and Timed Loop

Hello,

 

I am very very new to LabVIEW and have gone through youtube tutorials but LabVIEW is very intimidating when I do not know anyone who uses it... I am doing a research project which requires vibrotactile stimulation. It's pretty simple stuff, just need NI DAQ to send out a signal from AO 0 for 4 seconds, go off for 8 seconds and repeat this 12 times, meanwhile it needs to receive input from AI 0 and write it to an excel file. I managed to send out a signal and receive my input but things start to fall apart with the timed loop. I tried to put DAQ assistant in the timed loop but it starts screaming at me with errors. I have attached my IV. Any help will be greatly appreciated.

0 Kudos
Message 1 of 3
(336 Views)

I'll try to help.  Turns out I've also done some work with sensory systems using LabVIEW.

  • DAQmx will be your friend, but you need to ditch the DDA (that's BS for Dreaded DAQ Assistant).  NI has a lovely White Paper (which taught me about how easy DAQmx can be) called Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Applications.   Skip over Chapter 1, which talks about the DDA.
  • Plug your DAQ device (what are you using, by the way, a USB-something-or-other?) into your PC and open MAX, the Measurement and Automation Explorer.  Find your DAQ device, select it, and choose "Test Panels".  Open the Analog Output section and select AO0.  Depending on the DAQ device you have, you should be able to configure it to output a waveform at a particular updating rate. 
  • Let's assume you want to sinusoidally stimulate a whisker at 50 Hz for 4 seconds, and you want the stimulus to be a 5 V sinusoid (to drive your "whisker-wiggler").  Set the output range to +5 and -5.  You should probably generate a 500 Hz signal to get a reasonably nice 50 Hz signal by stepping through those voltages, so you'll want to generate a waveform of 2000 points (500 points/sec X 4 sec).  But for now, just see if MAX will let you generate such a test signal "internally"
  • I don't have a suitable DAQ device to try this out myself, from my "home office", but you can also find Example Programs in LabVIEW by going to Help, Example Programs, Hardware Input and Output, DAQmx, Analog Output, Voltage.  I'd say look at Voltage - Finite Output.  Note that there's a lot of stuff there that you don't need -- the "Learn 10 Functions" article shows you that you really need a Task (which, if you are developing "inside" a LabVIEW Project, you can "build" in the Project Manager in a manner that you opened MAX, found your Device, selected Analog Output, specified the Timing, etc., and basically created a "Task" that you can wire to the "DAQmx Create Channel" function).
  • Once you have your Task defined in your Project, you can generate the entire 4-second AO stimulus by using basically DAQmx Create Channel (where you wire in the Channel or Task you defined with the A0 Channel of your device and the Voltage range), the DAQmx Timing (with # Sample, Sample Mode = Finite Samples, and Sample Rate) and a pre-generated Waveform which you can generate from the functions on the Waveform Palette.  Wire all this to a DAQmx Write, specifying Analog Output, 1 Channel, N Samples.  Now when you want to stimulate, start the Task, wait until it's done.  Once you've generated the Task, you can do the "Start, Wait-until-Done" part over and over again.
  • So now you have something that makes a sound for 4 seconds.  You simultaneously want to read input from AI0 and write it to an Excel file.  [I hope you don't mean Microsoft Excel, but rather something like a "Write Delimited Spreadsheet", which writes a .CSV file that Microsoft makes Windows "iconize" with an Excel-looking icon ...].  You go through the same DAQmx steps -- define your Task, set up the Sampling parameters, and take your data.  
  • Often when sampling physiological data, you want to record "continuously".  DAQmx makes this easy.  Let's say you want to sample at 1 kHz and you want to sample 4 seconds-worth at a time, i.e. a sample size of 4000 points.  It probably takes <0.1 sec to write 4000 points to disk.  You configure your loop with a DAQmx Loop with the DAQmx Start just before the Loop.  Inside you put your DAQmx Read, and pass the output to Write Delimited Spreadsheet.  How fast will your loop run?  It takes 4.0 seconds (well, maybe 4.003 seconds) to acquire the 4000 points and pass them to the Write Delimited Spreadsheet, which takes maybe 0.1 sec more.  Oops, that's 4.103 seconds -- won't my timing be off?  Nope, because you set "continuous sampling", so while you were "wasting" 0.103 seconds handling the data from the first loop, the second loop was acquiring 103 of the next 4000 points, without missing a sample.  Magic!
  • Try this out for yourself.  Come back with more questions.  Learn to use DAQmx functions, not the DDA (or its Evil Twin, the Dynamic Data Wire!).

Bob Schor

0 Kudos
Message 2 of 3
(298 Views)

Hello,

 

Thank you so much!! This has been immensely helpful and I was able to write a program to send out a stimuli at required frequency and timings. I am having trouble with DAQmx to Write Delimited Spreadsheet connection. I essentially the DAQmx to start reading and writing the AI1 output from the beginning and capture everything (Even when the stimulator is not creating vibration stimulation). This is to allow us to match ON and OFF timings to our fMRI output. I tried to write the AI1 to .CSV as a separate VI as I'll need it for a couple of stimulators. DAQ assistant was providing some output but it was sampling at milliseconds and stopping/restarting recording. Any help on this would be greatly appreciated!

0 Kudos
Message 3 of 3
(248 Views)