Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Syncronization cDAQ of modules

Solved!
Go to solution

4 my application I need to read a voltage syncronized with a stimulus signal that I apply to a device.

In summary, I generate a staircase-shape  sequence voltage levels and make several readings on every step.

 

I've tried to use a common trigger for generation/acquisition using the "text-based" functions as reported in the following, but the generator 9263 that is used as master for timing, (through SampleClock or StartTrigger signals) rather surprisigly, starts some 20 millisecond later then the readings of slave 9239!

 

Using a very tricky workaround with an added delayed counter for timing the readings seems so solve the problem: a solution strongly dependent on delay settings and, as such, very unsatisfactory...

Sub Config_DAQmx(IN_TaskHandle As Long, OUT_TaskHandle As Long, TMR_TaskHandle As Long) ' ______________________OUT ' Create the DAQmx Output task DAQmxErrChk DAQmxCreateTask("OUT", OUT_TaskHandle) DAQmxTask_OUT_Running = True ' Add an analog Output channel to the task DAQmxErrChk DAQmxCreateAOVoltageChan(OUT_TaskHandle, "/cDAQ1Mod2/ao0", " ", _ -10#, 10#, DAQmx_Val_VoltageUnits2_Volts, "") ' Configure task for finite sample generation with internal clock DAQmxErrChk DAQmxCfgSampClkTiming(OUT_TaskHandle, "", OUTSmplRate, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_FiniteSamps, SmplsWritePerTrig) ' ______________________ COUNTER (Timer for IN delayed trigger) DAQmxErrChk DAQmxCreateTask("COUNTER", TMR_TaskHandle) DAQmxTask_TMR_Running = True DAQmxErrChk DAQmxCreateCOPulseChanFreq(TMR_TaskHandle, "/cDAQ1/_Ctr0", "", DAQmx_Val_FrequencyUnits2_Hz, DAQmx_Val_Level1_High, 0.0245, INSmplRate, 0.1) DAQmxErrChk DAQmxCfgImplicitTiming(TMR_TaskHandle, DAQmx_Val_AcquisitionType_FiniteSamps, 1) ' Define the parameters for a digital edge start trigger: set the counter to trigger off whith the ' AO start sample ' DAQmxErrChk DAQmxCfgDigEdgeStartTrig(TMR_TaskHandle, "/cDAQ1/ao/SampleClock", DAQmx_Val_Rising) DAQmxErrChk DAQmxGetStartTrigRetriggerable(TMR_TaskHandle, True) ' ______________________IN DAQmxErrChk DAQmxCreateTask("IN", IN_TaskHandle) DAQmxTask_IN_Running = True DAQmxErrChk DAQmxCreateAIVoltageChan(IN_TaskHandle, "/cDAQ1Mod1/ai0", "", DAQmx_Val_InputTermCfg_Diff, _ -10#, 10#, DAQmx_Val_VoltageUnits1_Volts, "") DAQmxErrChk DAQmxCfgSampClkTiming(IN_TaskHandle, "OnboardClock", OUTSmplRate, DAQmx_Val_Rising, _ DAQmx_Val_AcquisitionType_FiniteSamps, SmplsReadPerAcquisit) ' DAQmxErrChk DAQmxCfgDigEdgeStartTrig(IN_TaskHandle, "/cDAQ1/_ctr0InternalOutput", DAQmx_Val_Falling) DAQmxErrChk DAQmxSetReadReadAllAvailSamp(IN_TaskHandle, False) ' ______________________START ' ' Call the start function to arm the input tasks. ' The analog input is armed before the analog output: this will ensure both will start at the same time. ' DAQmxErrChk DAQmxStartTask(IN_TaskHandle) DAQmxErrChk DAQmxStartTask(TMR_TaskHandle) End Sub Function Output_DAQmx_Sequence(dataOUT() As Double, WriteArraySizeInSmpls As Long, TaskHandle As Long) As Long Dim NumSampsPerTrig_Written As Long Const AutoStart As Boolean = True ' Specifies if DAQmxWriteAnalogF64 automatically starts the task if you don't start it DAQmxErrChk DAQmxWriteAnalogF64(TaskHandle, WriteArraySizeInSmpls, AutoStart, DAQmxTimeOut, _ DAQmx_Val_GroupByChannel, dataOUT(0), NumSampsPerTrig_Written, ByVal 0&) 'DAQmxErrChk DAQmxStartTask(TaskHandle) End Function Function Read_DAQmx_Sequence(dataIN() As Double, ReadArraySizeInSmpls As Long, TaskHandle As Long) As Long Static NumSampsPerTrig_Read As Long 'DAQmx_Val_Auto: Read all available samples DAQmxErrChk DAQmxReadAnalogF64(TaskHandle, DAQmx_Val_Auto, DAQmxTimeOut, _ DAQmx_Val_GroupByChannel, dataIN(0), ReadArraySizeInSmpls, NumSampsPerTrig_Read, ByVal 0&) End Function

 

 

0 Kudos
Message 1 of 6
(4,854 Views)
Solution
Accepted by andreasosso

Hi andreasosso,

 

I think you're seeing the effects of filter delay, which makes the task acquire samples from before the start trigger. The NI 9239 specifications list the input delay as 38.4/fs + 3 μs where fs=sample rate. If your sample rate is the minimum supported rate, 1613 S/s, then the input delay is the worst case, around 23.8 ms.

 

If the only AI module you are using is the NI 9239, then you might find the Start.Delay and Start.DelayUnits properties (DAQmxSetStartTrigDelay and DAQmxSetStartTrigDelayUnits in C) useful to delay the acquisition without using a general purpose counter. These properties cause the AI task to wait a specified amount of time after the start trigger before generating the first sample clock.

 

Other reasonable approaches include: discarding the first 39 samples, resampling the data, or filtering the other AI modules' data in software (if you are using multiple types of module in the same task).

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 6
(4,839 Views)

hi i am new to labview  

 

i am using LB 8.5  

c daq 9178 / 9262 module

 

is it possible to create a task using 9262 module 15 channels generating array input DBL  value

 

& one channels sine waveform

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

Hi TCL,

 

It's better to post a new question in a new thread, rather than add it to an unrelated thread.

 

Anyway, assuming that you are using the NI 9264 (since there is no NI 9262), the answer is yes: it is possible. All you have to do is build a 2 dimensional array where one row contains a sine wave and the other rows contain DC values, and pass it to a 2D array version of DAQmx Write. (You also need to have all 16 channels in the same task.) Such an array might look like this (with the rows and columns numbered):

 

    0  1  2  3  4   5   6   7

  +---------------------------

0 | 5  5  5  5  5   5   5   5

1 | 5  5  5  5  5   5   5   5

2 | 5  5  5  5  5   5   5   5

3 | 5  5  5  5  5   5   5   5

4 | 5  5  5  5  5   5   5   5

5 | 0 0.7 1 0.7 0 -0.7 -1 -0.7

6 | 5  5  5  5  5   5   5   5

7 | 5  5  5  5  5   5   5   5

8 | 5  5  5  5  5   5   5   5

9 | 5  5  5  5  5   5   5   5

10| 5  5  5  5  5   5   5   5

11| 5  5  5  5  5   5   5   5

12| 5  5  5  5  5   5   5   5

13| 5  5  5  5  5   5   5   5

14| 5  5  5  5  5   5   5   5

15| 5  5  5  5  5   5   5   5

 

You should be able to build an array like this programmatically using for-loops and/or VIs from the array palette. A DAQmx example like Cont Gen Wfm-Int Clk should be a good starting point if you replace the waveform generation and DAQmx Write.

 

Brad


---
Brad Keryan
NI R&D
0 Kudos
Message 4 of 6
(4,448 Views)

Hi brad,

 

both DAQmxSetStartTrigDelay and DAQmxSetStartTrigDelayUnits are not working: I keep getting an error -200436: .. not available when an extermal samle clock source is used. But I'm using the "Onboard Clock"!

 

DAQmxErrChk DAQmxCfgSampClkTiming(IN_TaskHandle, "OnboardClock", OUTSmplRate,DAQmx_Val_Rising, _
DAQmx_Val_AcquisitionType_FiniteSamps, SmplsReadPerAcquisit)

DAQmxErrChk DAQmxSetStartTrigDelay(IN_TaskHandle,0.024)
DAQmxErrChk DAQmxGetStartTrigDelay(IN_TaskHandle,TrDly)






0 Kudos
Message 5 of 6
(4,226 Views)

Hi andreasosso,

 

Sorry, I forgot that start trigger delay is incompatible with external sample clock. I guess you'll have to discard the first 39 samples in your program instead.

 

Why does the NI 9239 act like it's using an external sample clock, when you have specified OnboardClock? When possible, cDAQ uses the AI timing engine in the chassis to generate the sample clock. However, when you are using a module that has a delta-sigma ADC (like the NI 9239), the module must control the sample clock timing, so DAQmx configures the chassis's AI timing engine to import the module-generated sample clock as an external sample clock. This imposes the same restrictions as if you had selected an external sample clock.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 6 of 6
(4,218 Views)