Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize ai reading with pfi signal

Hi,

I am a first time user.

 

I have an signal on Dev/ai1 1Mhz and I have digital signal on PFI0 about 800Hz (it can change in time from 760-815 HZ)

I have to read 700 samples (in continuous mode) from ai1 when signal on PFI0 is high.

 

I find one decision -  generate pulse and use it like external clock.

Here is my code

 

 

/*PULSE*/

errorCheck (DAQmxCreateTask("",&pulseTask));

errorCheck(DAQmxCreateCOPulseChanFreq(pulseTask,"Dev1/ctr0","",DAQmx_Val_Hz,DAQmx_Val_High ,0.0,1000000.0,0.5));

errorCheck (DAQmxCfgDigEdgeStartTrig(pulseTask,"/Dev1/PFI0",DAQmx_Val_Falling));

errorCheck (DAQmxCfgImplicitTiming(pulseTask,DAQmx_Val_FiniteSamps,700));

errorCheck(DAQmxSetStartTrigRetriggerable(pulseTask, 1));

errorCheck(DAQmxStartTask(pulseTask));

/*END PULSE*/

 

/*READ DATA */

 

float64 ddd[14000];

int32 cnt;

errorCheck(DAQmxCreateTask("",&aiTask));

errorCheck(DAQmxCreateAIVoltageChan(aiTask,"Dev1/ai1","",DAQmx_Val_Diff,-5.0,5.0,DAQmx_Val_Volts,NULL));

errorCheck(DAQmxCfgSampClkTiming(aiTask,"/Dev1/PFI12",800000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,7000));

errorCheck(DAQmxCfgDigEdgeStartTrig(aiTask,"/Dev1/PFI0",DAQmx_Val_Rising));

errorCheck(DAQmxStartTask(aiTask));

while(1){

errorCheck(DAQmxReadAnalogF64(aiTask,700,-1,DAQmx_Val_GroupByChannel,ddd,700,&cnt,NULL));

//code ...

}

DAQmxStopTask(aiTask);

DAQmxClearTask(aiTask);

 

This code works well. But my device support only one pulse gen. And I need gen. pulse in another task.

I don't know how to solve this problem. How to synchronize ai reading with pfi signal?

0 Kudos
Message 1 of 8
(6,906 Views)

What device are you using?

Nathan Murphy
0 Kudos
Message 2 of 8
(6,867 Views)

NI USB-6251

0 Kudos
Message 3 of 8
(6,848 Views)

Generating a pulse train only uses one counter, and there are two onboard the NI USB-6251. You should be able to create another counter output task using the resource dev1/ctr1. 

 

Are you getting any error messages when you run your code?

Nathan Murphy
0 Kudos
Message 4 of 8
(6,774 Views)

Hi, Nathan!

Thank you for answer. 

I generate one pulse using ctr0  and another one  using ctr1. I have no error if I use countiniouse mode, but if I use finite mode and DAQmxSetStartTrigRetriggerable(pulseTask, 1)  I have the error "NI Platform Services: The specified resource is reserved. The operation could not be completed as specified."

 

pulse.jpg

I want get only 700 samples of AI1 after PFI0 is Rising.

In countinious mode. 

P.S. Sorry for my English. Please ask additional question if my explanation is not enough

0 Kudos
Message 5 of 8
(6,748 Views)

I added some details to the picture to make task more  clear

pulse.jpg

0 Kudos
Message 6 of 8
(6,735 Views)

I understand what you are doing now, thank you for those pictures. 

 

Unfortunately, as you've already discovered, the method that you are currently taking needs three counters to function. A way around this limitation would be to configure the task as a continuous input and only read 700 samples. After you've read the needed samples, you'll have to stop and start the task to ensure that the data you read on the next iteration is new data. 

 

See this forum post for more details: http://forums.ni.com/t5/LabWindows-CVI/Flushing-of-all-channel-buffer-in-M-series-DAQ-card/td-p/6512...

Nathan Murphy
0 Kudos
Message 7 of 8
(6,685 Views)

Hi, Nathan!

Thank you for your help! But I have to solve this problem (stop and start task is not acceptable for me). If I find a solution I will post it.

0 Kudos
Message 8 of 8
(6,637 Views)