Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I Synchronize two counters in CVI using NI-DAQmx

Hi, I am new to NI-DAQmx, and I would like to program counting of random digital pulses using two counters in LabWindowsCVI and a PCI6229 multifunction card. I have the evaluation copy for CVI 7.1
I would like to set counter0, to count pulses from the 10MHz clock, to generate a single pulse (duration in the few ms timescale), that will gate counter1 in the same card.
When I try to route the output from counter0 to the gate of counter1 I get an error code
(-89137, "The specified route can not be satisfied because it requires resources that are currently in use by another route").
How can one do the equivalent of the "Select_Signal()" in the traditional NI-DAQ?"
I have also a hard time seting the counter0 to actually count a number of clock cycles from the 10 MHz clock.
What is the NI-DAQmx equivalent of the function "GPCTR_Change_Parameter()" to program a counter to count a predefined number of clock cycles?
Any suggestions are welcome.

Fundadero
0 Kudos
Message 1 of 13
(5,365 Views)
Hi Fundadero-

It sounds like you're programming for an M Series card with counter operations and need a bit of help with DAQmx functions.

In order to count edges of the 10MHz reference clock you will need to use a format similar to that found in the CVI shipping example "CntDigEv.prj." This is found in the NI Example Finder (Help>>Find Examples) under Hardware Input and Output>>DAQmx>>Counter Measurements>>Count Digital Events. In order to measure pulses from a source rather than the default input terminal (ctrXsource where X is the counter number), you will need to use the function DAQmxSetCICountEdgesTerm(taskhandle char[] counter, char source terminal) as follows:

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(taskHandle,chan,"",edge,initialCount,countDirection));
DAQmxErrChk (DAQmxSetCICountEdgesTerm(taskHandle, "/Dev2/Ctr0", "/Dev2/10MHzRefClock"));

What type of operation are you trying to perform on counter 1? The strategy for routing signals will change based on this. If you're trying to perform gated counting you can specify the the task similarly as above and use the terminal "/DevN/Ctr0InternalOutput" as before. If you are trying to perform frequency measurement you will need to use the DAQmxGetCIFreqTerm function.

Other channel properties are listed conveniently in the NI-DAQmx C Reference Help found at Start>>Programs>>National Instruments>>NI-DAQ on your start menu. A search for "channel properties list" returns this list.

Please let us know if you have any additional questions.

Thanks-
Tom W
National Instruments
0 Kudos
Message 2 of 13
(5,354 Views)
Tom,
Thank you for your clear explanation. I will try this right away. Yesterday after I submitted my query I found that function in the C reference.
You are correct, I am trying to program a NI PCI 6229 and I need to perform counting of digital pulses during a series of time intervals of precise duration, (in the 0.1 to 100 ms) The timing has to be hardware controlled because this counting operation will be done in conjunction with buffered analog waveform generation and they must be sinchronous. For each portion of a waveform that has been output, a number of digital pulses can be asociated, with minumum loos of pulses.

For now I am rying to set counter 1 as a single pulse generator, to generate a precisely generated Gate for counter 2 that will be "armed" and waiting for the gate to start counting. At the end of the Gate I read the count from Counter 1, and save it on n Array. Then the next piece of analog waveform is output, and a new ate is sent to counter 1.

With your help, I wiil be able to egnerete the Gate. I now need to understand how to route the output of counter 0 to the Gate input of counter 1.
I was trying to do this with DAQmxExportSignal();, and with DAQmxConnectTerms();, but I get errors, such as the specified route requires resources that are in use by another route. I used MAX to see the routing table and it shows that the interal output of conter0 can be direcctly connected to the gate oc Counter1. But I am missing something important, when I use the routing functions.

Sorry, for this long post, I hope it gives a better description so you can help.

Many thanks for the terrific service!

Fundadero.
0 Kudos
Message 3 of 13
(5,348 Views)
Hi Tom,
I have been looking at the functions that you suggested. Thanks for pointing them out to me.
They are a little hidden:)
I set the input terminal to count clock cycles from the 10 MHz clock. This is perfect. But when I try to set the number of ticks with the fucntions

unsigned long ulticks_per_Gate=10000;

DAQmxErrChk(DAQmxCreateTask("THGateOut", &taskOut));
DAQmxErrChk (DAQmxCreateCICountEdgesChan (taskOut, "Dev1/ctr0", "PulseOutput", DAQmx_Val_Rising, 0,DAQmx_Val_CountUp));
DAQmxErrChk (DAQmxSetCICountEdgesTerm(taskOut, "/Dev1/Ctr0", "/Dev1/10MHzRefClock"));
DAQmxSetCOPulseHighTicks(taskOut,"Dev1/ctr0", ulticks_per_Gate);

I get an error -200452
Function DAQmxSetCOPulseHighTicks
Specified property os not supported by the divice or it is not applicable to the task

It seems to be that ticks and edges is not the same. Am I using the wrong function to set the number of clock cycles that the output pulse should last?

Thanks again for your help.

Fundadero.
0 Kudos
Message 4 of 13
(5,337 Views)
Hi Fundadero-

That function will be useful, but I think your original task may be a bit misguided. Rather than creating a "DAQmxCreateCICountEdgesChan" you will actually need to create a "DAQmxCreateCOPulseChanTicks" channel. The source terminal specification is actually given in the channel creation function, so you won't need to call it seperately.

From the DAQmx C Reference Help, the parameters for the DAQmxCreateCOPulseChanTicks are as follow:

DAQmxCreateCOPulseChanTicks (TaskHandle taskHandle, const char counter[], const char nameToAssignToChannel[], const char sourceTerminal[], int32 idleState, int32 initialDelay, int32 lowTicks, int32 highTicks);

I hope this helps!

Thanks-
Tom W
National Instruments
0 Kudos
Message 5 of 13
(5,323 Views)
Hi Tom,
Thanks for your help. I have been trying the functin that you sugested, but I can't seem to be able to output a pulse longer than some 100 microseconds.
I look at the output of the "counter 0" on pin 2 in connector 0 on the NI PCI-6229 using the oscilloscope. Then when I try to generate a pulse on this output by using the function
DAQmxCreateCOPulseChanTicks (taskOut, "Dev1/ctr0", "", "/Dev1/10MHzRefClock", DAQmx_Val_Low, 0.0, 2,
10000);
I expect to see a pulse of 1.0 ms on the output of counter 0, but I see a pulse that is about 120 ms. If I count only 1000 ticks for the high state observe an output of EXACTLY 100 microseconds, as I expect. I see that if I call the function with 100 tick for the high state I observe an output puse of 10 microseconds, exactly.

Here is the task definition that I use,

int32 CreateGatePulse(TaskHandle *taskOut1)
{
int32 DAQmxError = 0;
TaskHandle taskOut;

DAQmxErrChk(DAQmxCreateTask("GatePulse", &taskOut));
DAQmxCreateCOPulseChanTicks (taskOut, "Dev1/ctr0", "", "/Dev1/10MHzRefClock", DAQmx_Val_Low, 0.0, 2,
100000);
*taskOut1 = taskOut;

Error:
return DAQmxError;
}

Why doesn't this task output a 1.0 ms pulse on the output of counter 0?
I am sure I am missin g something very basic here.
Can you please coment on this?.
Thanks
Best regards,

Fundadero.
0 Kudos
Message 6 of 13
(5,305 Views)
Hi It is me again...
I am sorry, the last question of my post should have read:
Why doeesm't this task output a 10.0 ms pulse on the output of counter 0.
(I am setting the high state of the output to be 100000 ticks of the 10 MHz clock, so I expect a pulse of 0.01 seconds)
Sorry for this mistake.
Thanks.
Fundadero
0 Kudos
Message 7 of 13
(5,304 Views)
I realized what I was doing wrong. I was starting the task, from a call back, and immediately after that I cleared the task. Thus, when the pulse output is less than some 100 microseconds it is completed before cleared, but for longer pulses it was being cleared as soon as the software and OS was able to do so, which it apparently takes about 120 ms under the debbugging mode.
I inserted a delay after I start the task, and now I can seee that the ouptut of the counter is exactly as I expect.


Now that this is more or less understood for me, I would like to know how can I route this pulse to the gate of counter 1, which will be used to count digital pulses from an external source.

Thanks for your help!!

Fundadero.
0 Kudos
Message 8 of 13
(5,305 Views)
Hi Fundadero-

This internal route should be available on your card. I am testing with an M Series card and seeing good results. cont...

Message Edited by Tom W. on 06-29-2005 06:15 PM

Tom W
National Instruments
0 Kudos
Message 9 of 13
(5,288 Views)
You will need to use the function "DAQmxConnectTerms (const char sourceTerminal[], const char destinationTerminal[], int32 signalModifiers);" to specify the connection. The sourceTerminal should be "Dev1/Ctr0InternalOutput" and the destinationTerminal should be "Dev1/Ctr1Gate"

You mentioned before that you were seeing an error when using this method. This connection works on my M Series card and should work for yours as well. If you are still having problems can you please describe the setup for your task on the second counter?

Thanks-
Tom W
National Instruments
0 Kudos
Message 10 of 13
(5,280 Views)