Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous analog and counter acquisition in CVI

Hi all,
I'm trying to perform two separate acquisition simultaneously: an analog acquisition on some channels and a frequency measurement on a counter. The developing environment is CVI 7.1, using a PCI-6281 DAQ board, NI_DAQ 8.5.0f5
My problem is that the frequency comes from an encoder on a motor which is performing a speed ramp, so the period of the signal is not constant and I must syncronize speed values with analog measurements.
 
I have no access now to the device so I tried to develop a solution on a simulated device, my code is the following, on the simulated device it terminates with no error (but no measurements on Cdata Smiley Surprised but this is probably due to the board being a simulated one):
 
 
 // Create the analog task
 DAQmxChk (DAQmxCreateTask ("Analog", &taskAI));
 DAQmxChk (DAQmxCreateAIVoltageChan (taskAI, "/Dev1/ai0", "Voltage", DAQmx_Val_Cfg_Default, -5.0, 5.0, DAQmx_Val_Volts, ""));
 DAQmxChk (DAQmxCfgSampClkTiming (taskAI, "OnboardClock", 1000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, size));
 
 // Create the counter task
 DAQmxChk (DAQmxCreateTask ("Counter", &taskCI));
 DAQmxChk (DAQmxCreateCIFreqChan (taskCI, "/Dev1/ctr0", "Counter", 2.0, 100.0, DAQmx_Val_Hz, DAQmx_Val_Rising, DAQmx_Val_LowFreq1Ctr, 0.001, 4, ""));
 DAQmxChk (DAQmxCfgImplicitTiming (taskCI, DAQmx_Val_FiniteSamps, size));
 
 // Set counter task to share start with analog task
 DAQmxChk (DAQmxSetTrigAttribute (taskCI, DAQmx_ArmStartTrig_Type, DAQmx_Val_DigEdge));
 DAQmxChk (DAQmxSetTrigAttribute (taskCI, DAQmx_DigEdge_ArmStartTrig_Src, "/Dev1/AI/StartTrigger"));
 
 // Start the tasks
 DAQmxStartTask (taskCI);
 DAQmxStartTask (taskAI);
 
 // Wait until task done
 while (!doneAI) {
  DAQmxChk (DAQmxIsTaskDone (taskAI, &doneAI));
 }
 
 // Read measurements
 DAQmxChk (DAQmxReadAnalogF64 (taskAI, DAQmx_Val_Auto, 0.0, DAQmx_Val_GroupByChannel, Adata, size, &sRead, 0));
 DAQmxChk (DAQmxReadCounterF64 (taskCI, DAQmx_Val_Auto, 0.0, Cdata, size, &sRead, 0));
 
 
Question is: does this make sense at all? Can I expect it works on a real board the same as on the simulated one? And am I guaranteed that Cdata[n] was acquired exactly in the same moment as Adata[n]?
 
Since I am acquiring at very high rates, I can imagine that there isn't a new frequency measurement for every analog sample, so I suppose I will get an array of frequencies like that
[ 100.0, 100.0, 100.0, 110.0, 110.0, 110.0, 115.0, 115.0 ..... ] and so on, that is frequency measurement is repeated if there is no new value ready: is this true or am I doing wrong assumptions?


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 1 of 6
(3,606 Views)
Is there anybody that can help me with this question? I would like to have a second look at it.

Message Edited by Roberto Bozzolo on 03-11-2008 09:01 AM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,584 Views)

Hi Roberto,

I'm sorry for my late reply.

I've tested your code with a PCI 6251. I've used a BNC-2120 and I've acquired a sine wave on channel 0 and I've sent a TTL square wave into the CTR0 gate (PFI 9).

I was able to get values on Adata and Cdata. Your assumptions about Cdata were correct, the array has equal values since the frequency changes slowly.

I hope this can help you.

Ciao,

Andrea N.

 

Andrea N.
Principal Applications Engineer - Semiconductor EMEA
National Instruments Italy
Certified LabVIEW Architect - Certified TestStand Architect
0 Kudos
Message 3 of 6
(3,571 Views)

Ciao Andrea,

wow! This is *really* a good answer Smiley Happy I can now proceed to develop final application.

Just to clarify me some item:

  • My signal sweeps from 100Hz to 2kHz: I'm assuming the measure with one counter is enough to achieve a good precision for this range
  • In this case "Measurement time" parameter of DAQmxCreateCIFreqChan is not used (I suppose I will find a new value in Cdata as far as it is acquired, that is at variable time while the speed is varying)
  • Can I force the choice of timebase frequency to 20MHz or DAQmx automatically chooses it? In case I can, which parameter should I pass to DAQmxSetChanAttribute (task, "", DAQmx_CI_CtrTimebaseSrc, ???, NULL); instead of "???"

Thank you



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 6
(3,565 Views)
Ciao Roberto,
 
the Low Frequency measurements is good for your range of frequencies. Since the measurements have an error of +1/-1 source cycle, with a 20 MHz timebase you would get 10000 cicles for a frequency of 2 KHz. This means that you get a frequency of 2000,2 - 1999,8  Hz.
 
With the DAQmxCreateCIFreqChan the "Measurement time" parameter is not used as stated in the help:
The length of time to measure the frequency or period of a digital signal, when measMethod is DAQmx_Val_HighFreq2Ctr.
 
I used the DAQmxGetTimingAttribute (taskAI, DAQmx_SampClk_Timebase_Rate, &TBrate)  to get informations about the timebase rate.
For the taskAI I've gotten 20 MHz for my NI PCI 6251.
 
Ciao,
 
Andrea N.
 
 
Andrea N.
Principal Applications Engineer - Semiconductor EMEA
National Instruments Italy
Certified LabVIEW Architect - Certified TestStand Architect
0 Kudos
Message 5 of 6
(3,558 Views)

Ok, many thanks to you Smiley Happy

Ciao
Roberto



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(3,555 Views)