LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Accelerometer + DAQ

Solved!
Go to solution

I have a NI 9234 DAQ hooked to an accelerometer sampling at 20k. I am trying to get it to write to a csv file continously until stopped by the user. I have tried having the "Write to.."  inside the while loop but that just gives me an error:

Possible reason(s):

The application is not able to keep up with the hardware acquisition. 

Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.

Property: RelativeTo
Corresponding Value: Current Read Position
Property: Offset
Corresponding Value: 0

Task Name: _unnamedTask<16>

And when I put the "Write to.." outside the while loop, it only gives me one second worth of data.

I am not sure how to get it to work, should it be inside or outside of the loop? If it's outside, the RAM would of the PC would be storing all the info until stopped? Is there a simple solution?accelerometer daq.png

Here is a picture of the screen, it is also attached as a file.

0 Kudos
Message 1 of 6
(4,131 Views)

You are using the Dreaded DAQ Assistant, and its Evil Twin, the Dynamic Data Wire.  Both "hide details" and take away some of the flexibility that you need to do what you want to do.

 

Think about the problem as a series of steps, and use Data Flow in your thinking.  First, consider acquiring the data.  You want to Configure the DAQ Device to acquire samples (you don't say how many samples at a time, but let's say 1000 samples at 20KHz, which gives you 1000 points every 50 msec), acquire repetitively 1000 samples until you push the Stop button, then close the DAQ process.

 

On the other hand, you want to write the data (as it comes in) to a .csv file.  The "smart" way to do this is to open the file, wait for a set of points (say, 1000) to come in, write it to the file, wait for the next set, repeat until the Stop button is pushed, then close the file.

 

So where do you get the 1000 points to write?  Hmm, how about taking the 1000 points you just collected?  How about the timing?  Well, the collection "wakes up" every 50 msec and gives you 1000 points -- if you can manage to write them out before the next 50 msec when more points arrive, you'll be able to keep up and can continue this until you fill up your disk.

 

Now think how you can incorporate these ideas into a simple LabVIEW program.  It involves no Express VIs, uses no Dynamic Data Wires, and is very simple to program.  You should, however, do a Web Search for "Learn 10 Functions in NI-DAQmx" (the title is actually longer, but that search will locate it for you), read the excellent NI White Paper cited, and then (a) create a Task in MAX for your A/D task, (b) use DAQmx Start Task, Read, and Stop Task functions, and (c) read the Help for the Write Spreadsheet function on the File Palette to understand how to do this task sequentially.

 

Bob Schor

Message 2 of 6
(4,091 Views)

Bob,

Thank you for the reply and the explanation. This is what I was trying to go for as far as being able to have the data be written as it comes in.
Would it work with a single while loop?

I have taken your suggestion of the reading material you mention and have read it, although there's no straight forward answer as far as how to use DAQMx Start, Read, Stop. Would it be as simple as getting the three for separate channels of my accelerometer and putting it all in one while loop?


0 Kudos
Message 3 of 6
(4,073 Views)

Currently at JFK airport.  Will try to answer when i get home shortly.

 

BS

0 Kudos
Message 4 of 6
(4,049 Views)

Joaquinh,

 

In your DAQmx Virtual Channel setup, you specified a specific physical channel. It's possible to input more than one channel in the same Virtual Channel setup if they're all going to do the same thing (e.g. Analog Input).

 

You should be able to find information about doing this here.


GCentral
0 Kudos
Message 5 of 6
(4,048 Views)
Solution
Accepted by Joaquinh

Oops!  It has been a while since I re-read that White Paper, and I forgot that it failed to mention a key step in Getting Started with DAQmx -- the proper use of MAX to explore your device and to create Tasks.

  1. Make sure your Device is connected to your Computer.  It's not a bad idea to have its connectors wired to your Experiment/Test.
  2. Start MAX.  Find your Device and Open (double-click) it.
  3. This step is optional, but will help you with defining a Task.
    1. Open a Test Panel.  Choose Analog Input.  Choose a Channel to configure.
    2. Set Mode to Continuous, Input Configuration to Differential, and set the Max and Min that you want to use (probably 5 and 0).  Set Rate and Samples to Read (default is 1000, 1000, meaning every second you'll get 1000 new points).
    3. Press Start.  Observe 1000 samples updated every second.  Press Stop.
    4. Press Close to exit the Test Panel.
  4. You now will build a DAQmx Task to do the same thing.  Click Create Task (just to right of Test Panels).
  5. Click Acquire Signals., Analog Input, Voltage.  It should show you your Device, and the Analog Input Channels you can use.  Select the three Channels (use Shift-Click to select them all at the same time), then click Next.
  6. Choose a better Task Name (how about Accel_Inputs?).  I'm not sure if spaces are legal in Task Names.  Click Finish.
  7. You'll now be able to configure the Voltage Input and Timing Settings of your task.  Again, choose Continuous Samples and adjust the other settings to your liking.  You can also rename the Channels from Voltage_0, Voltage_1, Voltage_2 to X, Y, Z if you like.
  8. Run the Task (use button at the top).  You should see three continuous traces (it won't appear in 1-second bunches, I'm not sure why).
  9. Save the Task (button on top left).  It will appear in MAX under Data Neighborhood, NI-DAQmx Tasks.

Why do we do this?  Well, here is the Basic DAQmx Acquire -- four DAQmx functions, a Constant wired to the DAQmx Start Task "Task" input, and a While Loop around the Read.  See the little triangle in the Constant?  Click it and all the Tasks created in MAX (and your Project, another place to create Tasks) will pop up.

Basic DAQmx Acquire.png

Now all you have to do is modify the DAQmx Read (I recommend Multiple Channels, Multiple Samples -- I prefer 2D Dbl (one dimension for the N channels, the second for the N Samples), but if you like using Waveforms, you can choose 1D Waveforms (N Channels, the N samples being inside the Waveform).

Basic DAQmx Acquire with Task.png

 

Bob Schor

 

 

 

Message 6 of 6
(4,040 Views)