Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

how to re-route source & gate for Buffered Period in DAmx

I am trying to write a DAQmx program that does the follow :

(1) creates 1 PulseTrain task; this task routes is output to a requested pin with will be used as a SOURCE for a Buffered Period task.
(2) if requested creates a second PulseTrain who's output will be used as the Buffered Period GATE.

(3) the Buffered period task needs to assign ANY SOURCE,GATE and run till its stopped by the user.
Note that this task needs to "sample/read" its data and show it to the user.


My questions are :

(a) is the PulseTrain "output" re-route done OK ?
(b) how to re-route the Period source/gate - I used DAQmxSetChanAttribute, but I an not sure it is right
©) how to make the Period task write the data into "my program buffer" so I do not have to read it when "stop" is pressed.

I try to run with simulated devices on a P4 3.2GHZ running XP :
First TrainPulse - ctr0, out->RSTI0
Second TrainPulse - ctr1, out->RSTI1
Period - ctr2, source=RSTI1, gate=RSTI0

Running this program with a SIMULATED device - OK (data = 0). with the real device - I get error -200141

I included my code.
0 Kudos
Message 1 of 10
(5,785 Views)
Hello fngitliz,

I took a look at your code and it seems that you are performing all of the signal routing correctly using the DAQmxSetChanAttribute functions.  You set the DAQmx_CO_Pulse_Term attribute to configure the output terminal of the pulse train tasks, the DAQmx_CI_CtrTimebaseSrc attribute to configure the source terminal of your period measurement task, and the DAQmx_CI_Period_Term attribute to configure the gate terminal of your period measurement task.

The error you are seeing is a result of a buffer overflow caused by not reading the period measurements fast enough before they are overwritten.  When you configure a sample clock for your period measurement task, you are configuring the task to be buffered.  If you have a buffered period measurement task, you will need to read multiple values to empty out the buffer and avoid an overflow.  You can read multiple channels with a single read function by using the DAQmxReadCounterF64 function.  On the other hand, you could remove the sample clock configuration to change your period task to non-buffered (single point) and just use the DAQmxReadCounterScalarF64 function to read a single measurement. 

For some more background information about configuring buffered read counter tasks, take a look at the following knowledgebase:

KB 2JCD04EW: How are Buffers Read in Finite vs. Continuous Buffer Mode for Counter Operations?

I hope this is clear and let me know if you have any further questions.

Regards,
Travis Gorkin
Applications Engineering
National Instruments
www.ni.com/support
Message 2 of 10
(5,774 Views)

It is not enough for me.

The program I wrote MUST be Buffered Period and MUST be "sample/read" every 1-2 seconds, so the user can see if the input data is OK. (I have 10-20 points per second).

 

I do not think this cann't be done with a PCI-6602 card.

 

Can same body help ?

 

0 Kudos
Message 3 of 10
(5,755 Views)
From your description, the 6602 should be able to handle your application.  What are the expected frequency ranges for the two pulse train generation tasks?
0 Kudos
Message 4 of 10
(5,748 Views)
one train is 1HZ and the other 10kZ.

Can you tell me what I have to put in the DAQmxCOPulseChganFreq for "freq" ?
If I want the same tie up and down is it 0.5 for duty OK ?
0 Kudos
Message 5 of 10
(5,738 Views)
fngitliz,

Running at these requencies should not present a problem. When you were getting the error before, were you using an external signal, or the one generated with your counter? Sometimes, external signals may be noisy and cause your device to attempt to latch and buffer data much faster than you think it is. The use of digital filters can help to alleviate this. Also, for your counter pulse generation, a duty cycle of .5 should provide equal high and low periods.

Hope this helps,
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 6 of 10
(5,719 Views)
Thanks every body for the help, I found my mistake, I had a wrong freq setup; now it is working.


Thanks, again
0 Kudos
Message 7 of 10
(5,714 Views)
I have a new question

I need to create an event buffered task when the source=80mhz internal card timebase, gate=source of other counter (e.q for counter 1 use 0, for 3 use 2)


I know that with Traditional-DAQ it will look like )see attch file):


Now the convertion to DAQmx :
++++++++++++++++++++++++++++++


void SetupEvent(void)
{

if ( Internal.P6602_ID == -1 ) return;

sprintf(Chan,"Dev%d/ctr1",Internal.P6602_ID); // channel 1
DAQmxErrChk (DAQmxCreateTask("EventChan1",&DaqmxTasks.PCI_6602[1]));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(DaqmxTasks.PCI_6602[1],Chan,"EventChan1",DAQmx_Val_Rising,0,
DAQmx_Val_CountUp));
DAQmxErrChk (DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[1], DAQmx_SampTimingType, DAQmx_Val_SampClk) );
DAQmxErrChk (DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[1], DAQmx_SampQuant_SampMode,DAQmx_Val_ContSamps) );
DAQmxErrChk(DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[1],DAQmx_SampQuant_SampPerChan, BUF_MAX));
// set source
DAQmxErrChk (DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[1], DAQmx_SampClk_Src, "/Dev1/80MHzTimebase"));
// and gate
sprintf(msg,"/Dev%d/ctr0Source",Internal.P6602_ID);
DAQmxErrChk(DAQmxSetChanAttribute (DaqmxTasks.PCI_6602[1], Chan, DAQmx_CI_CountEdges_Term, msg,0));

sprintf(Chan,"Dev%d/ctr3",Internal.P6602_ID); // channel 3
DAQmxErrChk (DAQmxCreateTask("EventChan3",&DaqmxTasks.PCI_6602[3]));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(DaqmxTasks.PCI_6602[3],Chan,"EventChan3",DAQmx_Val_Rising,0,
DAQmx_Val_CountUp));
DAQmxErrChk (DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[3], DAQmx_SampTimingType, DAQmx_Val_SampClk) );
DAQmxErrChk (DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[3], DAQmx_SampQuant_SampMode,DAQmx_Val_ContSamps) );
DAQmxErrChk(DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[3],DAQmx_SampQuant_SampPerChan, BUF_MAX));
DAQmxErrChk (DAQmxSetTimingAttribute (DaqmxTasks.PCI_6602[1], DAQmx_SampClk_Src, "/Dev1/80MHzTimebase"));

sprintf(msg,"/Dev%d/ctr2Source",Internal.P6602_ID);
DAQmxErrChk(DAQmxSetChanAttribute (DaqmxTasks.PCI_6602[3], Chan, DAQmx_CI_CountEdges_Term, msg,0));

return;


Error:
Internal.StartStop = OFF;
if ( DAQmxFailed(error) ) DAQmxGetExtendedErrorInfo(errBuff,1024);
StopCallBack();
MessagePopup ("SetupEvent Error", errBuff);
return;


}


I am not sure this is the way to do it .

Can samebody help ?

Thanks, Galia
0 Kudos
Message 8 of 10
(5,694 Views)
fngitliz,
 
First of all, I would use the DAQmxCfgSampClkTiming function in place of all the DAQmxSetTimingAttribute function calls.  Using this one function, you can set the sample clock source (gate input), the sample mode, and the samples per channel.  The signal on the gate is the one that will latch the count values into the PC buffer, so it acts as the sample clock for a buffered event counting task.  The source, on the other hand, is the signal that increments the count value of the counter on each active edge. 
 
With the code that you posted, your gate and source assignments are backwards.  You are actually setting the gate input signal to "/Dev1/80MHzTimebase" and the source input to the signal specified in "msg."  If you want the source to be the 80 MHz timebase, you should switch these assignments. 
 
Hope this information helps.
 
0 Kudos
Message 9 of 10
(5,679 Views)
Thanks, now it is working
0 Kudos
Message 10 of 10
(5,664 Views)