03-11-2009 05:49 PM
I am using an NI 6123 card.
Anyone knows how to put 6 analog values and counter value in FIFOs with the same rate: 4k.
So, every second, there should be 6*4k analog values and 4k counter value in FIFOs.
The problem is:
1. the counter is a digital value, so I cannot set a sample rate on it. Then how can I put the counter value in FIFO every 1/4000 second
2. how to synchronize analog channels and counter channel.
-------------------------
DAQmxErrChk (DAQmxCreateTask("",&datHandler));DAQmxErrChk (DAQmxCreateAIVoltageChan(datHandler,"Dev1/ai0:5","",DAQmx_Val_Cfg_Default,-5.0,5.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(datHandler,"",4000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,4000));
DAQmxErrChk (DAQmxCreateTask("",&ctrHandler));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(ctrHandler,"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_ExtControlled));
DAQmxErrChk (DAQmxStartTask(datHandler));
DAQmxErrChk (DAQmxStartTask(ctrHandler));
-----------------------------------
Thanks
Solved! Go to Solution.
03-12-2009 10:29 AM
it is possible to do a buffered counter application. (this is actually prefered). Simply specify a sample clock and source. Considering you want the counter to 'latch' data from the counter at the same rate as the analog sample clock simply specify this sample clock as the sample clock for the counter.
An example of buffered event counting (continuous acquisition) is found here using an external clock (your AI sample clock):....\National Instruments\NI-DAQ\Examples\MStudioVC2005\Counter\Count Digital Events\CountDigEventsBuffContinuous_ExtClk
Check out this example and I think that it should get you up and running.
03-12-2009 05:35 PM
thank you CharlesD for your very helpful reply, I got the 1st problem solved.
But how can I synchronize the two tasks. When I run the code below, an error occured:
Measurements: Analog input (AI) task started or committed during a counter 0 DMA acquisition.
If possible, use counter 1 instead of counter 0. Otherwise, start/commit the AI task before starting the counter 0 DMA acquisition.
Device: Dev1
Task Name: _unnamedTask<0>
Status Code: -200078
--------------------------------------------------------------------------------------
DAQmxErrChk (DAQmxCreateTask("",&datHandler));DAQmxErrChk (DAQmxCreateAIVoltageChan(datHandler,"Dev1/ai0:5","",DAQmx_Val_Cfg_Default,0-SCALE,SCALE,DAQmx_Val_Volts,NULL));DAQmxErrChk (DAQmxCfgSampClkTiming(datHandler,
"",RATE,DAQmx_Val_Rising,DAQmx_Val_ContSamps,RATE*NUMOFLASER));DAQmxErrChk (GetTerminalNameWithDevPrefix(datHandler,"ai/StartTrigger",startTrigger));DAQmxErrChk (DAQmxCreateTask("",&ctrHandler));DAQmxErrChk (DAQmxCreateCICountEdgesChan(ctrHandler,"Dev1/ctr0","",DAQmx_Val_Rising,0,DAQmx_Val_ExtControlled));
DAQmxErrChk (DAQmxCfgSampClkTiming(ctrHandler,startTrigger,RATE,DAQmx_Val_Rising,DAQmx_Val_ContSamps,RATE*NUMOFLASER));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(datHandler,DAQmx_Val_Acquired_Into_Buffer,RATE,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(datHandler,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxStartTask(ctrHandler));
DAQmxErrChk (DAQmxStartTask(datHandler));
-----------------------------------------------------------------------------------------------------------
03-13-2009 10:31 AM
The following KnowledgeBase aticle addresses this particular issue directly. You will have to use ctr 1 instead of ctr0.
http://digital.ni.com/public.nsf/allkb/FE8F3ECB7ED7328286256EEE0076FE13
Hope this helps let us know how it shapes up!
03-13-2009 03:15 PM
thank you CharlesD
I use ctr1 instead of ctr0 and it runs very well. The six ai channels and one counter channel are synchronized and stored in buffer.
code:
-----------------------------------------------------
DAQmxErrChk (DAQmxCreateTask("",&datHandler));DAQmxErrChk (DAQmxCreateAIVoltageChan(datHandler,"Dev1/ai0:5","",DAQmx_Val_Cfg_Default,0-SCALE,SCALE,DAQmx_Val_Volts,NULL));DAQmxErrChk (DAQmxCfgSampClkTiming(datHandler,
"",RATE,DAQmx_Val_Rising,DAQmx_Val_ContSamps,RATE*NUMOFLASER));DAQmxErrChk (GetTerminalNameWithDevPrefix(datHandler,"ai/SampleClock",trigName));DAQmxErrChk (DAQmxCreateTask("",&ctrHandler));DAQmxErrChk (DAQmxCreateCICountEdgesChan(ctrHandler,"Dev1/ctr1","",DAQmx_Val_Rising,0,DAQmx_Val_ExtControlled));
DAQmxErrChk (DAQmxCfgSampClkTiming(ctrHandler,trigName,RATE,DAQmx_Val_Rising,DAQmx_Val_ContSamps,RATE*NUMOFLASER));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(datHandler,DAQmx_Val_Acquired_Into_Buffer,RATE,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(datHandler,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxStartTask(ctrHandler));
DAQmxErrChk (DAQmxStartTask(datHandler));
-----------------------------------------------------
08-26-2019 08:24 PM
The knowledge base article is missing. Can you explain why one would need to use ctr 0 and ctr 1? I'm having a similar problem; the measurements from an analog card and a digital card won't sync, but I'm using ctr0.