LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx and SPI Timing

Hello,

 

I am trying to synchronize data output from analog and digital sensors using the NI 9172 (analog) and NI 8452 (digital).  I have tried to use a timed loop and and put both a DAQmx read and SPI read vi in there.  This allows me to obtain the same number of data points for the analog and digital sensors which is halfway to my goal.  I still am having a problem getting the timing to have equal spacing.  With that I have a couple of questions related to the VI attached.

 

1. No matter what value I assign dt in the timed loop (currently assigned 100 ms (i assume)).  I have changed this value several times and the loop will run between 0-2 ms as shown in the "Time for Measure (ms)" indicator.  Any idea on why the period input to the timed loop is not obeyed?

 

2. Should I run the analog and digital measurements in their own timed loop and then synchronize them using the Synchronized Timed Structure Starts VI?

 

3. Is there a way to not use a sample clock for the DAQmx tasks?  All I want is to poll the analog signals at each loop iteration which ultimately would be driven by the digital sensors sampling rate.  As an aside, the rate specification for the DAQmx sample clock also doesn't seem to obey the input similarly to #1.

 

I realize the 9172 and 8452 are probably not ideal for this task but it is all I have to work with.  Any help is appreciated.  Thank you.

0 Kudos
Message 1 of 42
(4,646 Views)

lgbav8r,

 

I have a few clarifying questions for you. You said that you are using a 9172 module. The only 9172 I can see is a cDAQ chassis. Can you double check on that module number.

 

My other question is what is the overall application that you are trying to accomplish? What exactly is it that you are trying to do with each of these modules?

 

Regards,

Leah

0 Kudos
Message 2 of 42
(4,621 Views)

Hi Leah,

 

Sorry about the 9172 confussion.  I have 2 modules in the 9172 chassis; a 9236 collecting data from strain gages, a 9233 collecting data from 2 analog accelerometers and an impact hammer.

 

Ultimately I am trying to collect data from analog strain gages, impact hammer, and digital accelerometers across an SPI interface (using the 8452) which are in sync with equal time spacing up to 1 kHz sampling rate.  I currently need analog and digital acellerometer data taken at the same time in order to compare the capabilities of the analog and digital accelerometer in further post processing of the signals.

 

I believe my VI is accomplishing the data collection in sync for the analog and digital sensors.  However, I cannot seem to create equivalent time spacing in the data acquisition.  The problem seems to be the timed loop is not obeying the input for the period (dt).  With a value of 100, I should only be seeing 10 samples / second yet I am seeing over 1000 samples / second.

 

Hopefully, I cleared things up.

 

-lgbav8r

 

Edit:  I should also mention that I am using Labview 2009

0 Kudos
Message 3 of 42
(4,612 Views)

lgbav8r,

 

I think you might have a misunderstanding of timed loops. You shouldn't ever use a timed loop with DAQmx. Generally, timed loops are only used in a Real-Time environment. To configure timing for DAQmx tasks, you should configure timed acquisition in the DAQmx timing vi, and then read in a while loop. \

 

Regards,

Leah 

0 Kudos
Message 4 of 42
(4,601 Views)

Ok.  That makes sense on the DAQmx.  I will switch back to a while loop.  I'm still not sure how I would add the 8452 in the mix to be on the same timing as the DAQmx?  Should I just include the SPI read command on in the same while loop as the DAQmx read resulting in two separate queues for further processing (like what I have currently)?

0 Kudos
Message 5 of 42
(4,599 Views)

I have converted the VI back to using a while loop instead of a timed loop and still having issues.  I believe what I would like is the 1 sample from each DAQmx channel to go with the 1 sample from the SPI read.  However, it seems that the DAQmx is running much faster than the while loop and filling up the buffer with data.  This is despite the instructions I give the DAQmx timing VI.  I don't want a FIFO type operation from the DAQmx.  I need to have 1 to 1 data point acquisition between the analog and digital sensors.  I also don't understand why the dt in the measurement file that is written is 0.0005 s (2 kHz).  It seems I am unclear on the DAQmx timing commands.  Is there any key points I am missing?.

 

Also, as a side question, I can't seem to apply the timestamp from the DAQmx signal to a signal that is manually created from the digital sensor.  Any additional assistance is appreceated.  Thank you.

 

Updated vi is attached.

0 Kudos
Message 6 of 42
(4,584 Views)

Hi lgbav8r,

 

It looks like you are on the right track. I do see a fairly big issue in your while loop, however. It looks like you are setting the Sample Clock to Continuous samples at 1000Hz and you are only calling a DAQmx Read for one sample on each channel. The while loop cannot execute at 1000Hz due to the non-deterministic nature of the Windows Operating System. Since the 845x behaves very similarly to On Demand sampling in that you must send a read command before a write command is written, I would recommend using On Demand sampling for the DAQmx Timing as well. Another way to more closely synchronize the SPI and DAQ reads is to put them both in a flat sequence structure so that the sequence structure must wait for all of the inputs from the SPI and DAQmx reads; this will allow a closer synchronization.

 

As for the timestamp, DAQmx Read receives it's timestamp when the the read is called. It is not from hardware timing. It looks like in your code you are pulling the timestamp from the waveform data, which looks fine there.

 

Best,

 

tannerite

Tannerite
National Instruments
0 Kudos
Message 7 of 42
(4,567 Views)

Hi tannerite.

 

I have tried changing the timing source to on demand but can't seem to make that work (I have left the while loop for now).  I have removed all timing vi's from the code which means I should be getting on demand timing.  However, I get an the error 201087.  According to the cDAQ-9172 documentation, it looks like it is capable of performing on demand sampling.  If I try putting in a timing node and specifying on demand timing (value 10390), I get error code 200077.  I have attached a screenshot of the timing node inserted.  All other aspects of the code are the same as my previous attachment.  Also cDAQ1 is the name of my cDAQ-9172 device in the MAX.

 

Error -201087 occurred at DAQmx Start Task.vi:1

Possible reason(s):

Measurements: Task contains physical channels on one or more devices that require you to specify the Sample Clock Rate.

Specify a Sample Clock Rate.

Device: cDAQ1

Task Name: _unnamedTask<6>

 

 

 

Error -200077 occurred at DAQmx Start Task.vi:1

Possible reason(s):

Measurements: Requested value is not a supported value for this property.

Property: SampTimingType
You Have Requested: On Demand
You Can Select: Sample Clock

Device: cDAQ1

Task Name: _unnamedTask<9>

0 Kudos
Message 8 of 42
(4,558 Views)

Well I have found another thread that seems to indicate the 9233 module is not capable of on demand timing.  I tried removing the module and only using the 9236 which also gave me the same errors as above.  I wonder if the 9236 is the same?

 

The thread for the 9233 is here

0 Kudos
Message 9 of 42
(4,551 Views)

lgbav8r,

 

Yes that is correct. I apologize for not taking a closer look at the modules inside of your CompactDAQ chassis. Both the NI-9233 and the NI-9236 modules do not allow On Demand sampling as they are Dynamic Signal Acquisition (DSA) devices. I would like to get a little bit more information as to how precise the "synchronization" needs to be? What are the timing requirements? It is my understanding that you have a digital sensor that relays information via the SPI communication protocol. You also have an analog sensor that you are reading in with the NI-9233 that you want to compare to the digital sensor.

 

So the fundamental question is how often do you need to sample both signals and how closely do they need to be sampled from one another?

 

Best,

 

tannerite

Tannerite
National Instruments
0 Kudos
Message 10 of 42
(4,539 Views)