Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Gated edge count with NI-DAQmx

Hello,
using a TIO-based counter board (PCI-660x) and NI-DAQmx I wish to achieve the following result: acquiring the number of pulses at the source input when a single gate pulse is at logic high level. I try to show this in the following time diagram (!):

signal at the source input, PFI35 on PCI-6601 _|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_

signal at the gate input, PFI34 on PCI-6601 ______|---------------|________

counter 1 count 1 2 3 4 5 6 7 8


I was able to do this with traditional NI-DAQ, but how to specify that I want to use a GATE and count only those source pulses corresponding to its high state in NI-DAQmx ?

Here is my traditional Ni-DAQ code, for a sake of completeness:

GPCTR_Control(daqdev, ND_COUNTER_1, ND_RESET);
GPCTR_Set_Application(daqdev, ND_COUNTER_1, ND_SIMPLE_EVENT_CNT);
GPCTR_Change_Parameter(daqdev, ND_COUNTER_1, ND_SOURCE, COUNTER1_SOURCE);
GPCTR_Change_Parameter(daqdev, ND_COUNTER_1, ND_GATE, COUNTER1_GATE);
GPCTR_Change_Parameter(daqdev, ND_COUNTER_1, ND_INITIAL_COUNT, 0);
GPCTR_Control(daqdev, ND_COUNTER_1, ND_PROGRAM);


Thanks a lot for your help,
Marco
0 Kudos
Message 1 of 11
(9,518 Views)
It looks like you are just counting events. There is a DAQmx example called Count Digital Events which should do the same thing for you. Also, if you want to do this continuously there is a continuously Count Buffered Edges example.

StuartG
0 Kudos
Message 2 of 11
(9,510 Views)
Unfortunately this is not simple event counting.
The availbale sample programs either perform real event counting, software triggered (the program starts counting when I press a start button and stops when I press a stop button), or event counting using external clock (the counter updates the count every rising or falling edge of an externally-provided clock signal).
This is quite different from using an external gate pulse. My need, in fact, is to count clock pulses on the source pin only during the high state of the signal present at the gate pin.
Thanks,
Marco
0 Kudos
Message 3 of 11
(9,504 Views)
For gated event counting in DAQmx, you'll want to configure a digital pause trigger. I don't have any information to help you with this in front of me at the moment, but if you need more help getting this configured post to this thread again.

I hope this helps!
gus....
0 Kudos
Message 4 of 11
(9,503 Views)
Yes please, when you have time try to let me figure out how this works. I tried DAQmxSetTrigAttribute specifying PFI34 as the trigger input (i.e. the GATE) but this causes an error (the function is not applicable to this pin etc.).
Thanks in advance,
Marco
0 Kudos
Message 5 of 11
(9,501 Views)
Hi!
Take a look at this snipplet...

/*
* chan /dev1/ctr0
* gate /dev1/PFI4
* source /Dev1/20MHzTimebase
*/

DAQmxErrChk (DAQmxCreateTask("",taskHandle));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(*taskHandle,chan,"",edge,initialCount,countDirection));

DAQmxSetChanAttribute (*taskHandle, chan, DAQmx_CI_CountEdges_Term,source);
DAQmxErrChk (DAQmxSetTrigAttribute (*taskHandle, DAQmx_PauseTrig_Type,DAQmx_Val_DigLvl));
DAQmxErrChk (DAQmxSetTrigAttribute (*taskHandle, DAQmx_DigLvl_PauseTrig_Src, gate));
DAQmxErrChk (DAQmxSetTrigAttribute (*taskHandle, DAQmx_DigLvl_PauseTrig_When,DAQmx_Val_Low));

DAQmxErrChk (DAQmxStartTask(taskHandle));

while( gRunning ) {
DAQmxErrChk (DAQmxReadCounterScalarU32(taskHandle,10.0,data,NULL));
//...
}
DAQmxClearTask(taskHandle);


I also attach a CVI project that works on M-series board (should work fine also on NI-TIO based devices).

Hope this help.
Ciao. Nicola.
0 Kudos
Message 6 of 11
(9,490 Views)
Many thanks for your help, for the code snipplet and for the sample !
This fixes the problem.
Just for a sake of completeness, for those who in the future will come to this posts: if you have in mind to to measure the number of pulses occurring in 1s gate (i.e. to have a direct, although rough, measure of the frequency) please notice that you can avoid at all these troubles in generating a gate etc., since there is a dedicated feature of NI-DAQmx which directly creates a task to measure frequency and takes care of every internal connections. The task is available in "Counter input" and "Frequency measurement" of the DAQ Assistant.
The arguments of this post, instead, remain valid for all other purposes dealing with a gate.
0 Kudos
Message 7 of 11
(9,484 Views)

Hi,

I would like to ask some queries regarding gated event counting to be done by using NIDAQmx using VB 6.0 or VB.Net

1) I would like to use 7 counters ( 6 as source and 1 as gate)

2) Would like to assign the RTSI from the gate to other 6 counter source

3) Have a program written in Traditional DAQ and need to transform the same function of the program using NIDAQmx drivers

4) Sample code from traditional DAQ is

    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_2, ND_RESET)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_3, ND_RESET)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_4, ND_RESET)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_5, ND_RESET)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_6, ND_RESET)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_7, ND_RESET)
    Err "c2-7 reset"
       
   
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_2, ND_SIMPLE_EVENT_CNT)
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_3, ND_SIMPLE_EVENT_CNT)
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_4, ND_SIMPLE_EVENT_CNT)
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_5, ND_SIMPLE_EVENT_CNT)
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_6, ND_SIMPLE_EVENT_CNT)
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_7, ND_SIMPLE_EVENT_CNT)
    Err "c2-7 set_app"
   
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_2, ND_GATE, ND_RTSI_0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_3, ND_GATE, ND_RTSI_0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_4, ND_GATE, ND_RTSI_0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_5, ND_GATE, ND_RTSI_0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_6, ND_GATE, ND_RTSI_0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_7, ND_GATE, ND_RTSI_0)
    Err "c2-7 set gate"
   
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_2, ND_SOURCE, ND_PFI_31)    ' SOURCE_2
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_3, ND_SOURCE, ND_PFI_27)    ' SOURCE_3
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_4, ND_SOURCE, ND_PFI_23)    ' SOURCE_4
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_5, ND_SOURCE, ND_PFI_19)    ' SOURCE_5
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_6, ND_SOURCE, ND_PFI_15)    ' SOURCE_6
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_7, ND_SOURCE, ND_PFI_11)    ' SOURCE_7
    Err "c2-7 set source"
   
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_2, ND_INITIAL_COUNT, 0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_3, ND_INITIAL_COUNT, 0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_4, ND_INITIAL_COUNT, 0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_5, ND_INITIAL_COUNT, 0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_6, ND_INITIAL_COUNT, 0)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_7, ND_INITIAL_COUNT, 0)
    Err "c2-7 initial count"
   
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_2, ND_PROGRAM)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_3, ND_PROGRAM)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_4, ND_PROGRAM)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_5, ND_PROGRAM)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_6, ND_PROGRAM)
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_7, ND_PROGRAM)
    Err "c2-7 program"
   
    ' Generate next gate
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_0, ND_RESET)                                    ' Reset counter
    iStatus = GPCTR_Set_Application(i6602DeviceNum, ND_COUNTER_0, ND_SINGLE_PULSE_GNR)                 ' Set counter type
    iStatus = Select_Signal(i6602DeviceNum, ND_RTSI_0, ND_GPCTR0_OUTPUT, ND_DONT_CARE)                 ' Output to RTSI 0 line
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_0, ND_SOURCE, ND_INTERNAL_100_KHZ)     ' Set clock
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_0, ND_COUNT_1, GateLength / 10)        ' Low cycles (10%)
    iStatus = GPCTR_Change_Parameter(i6602DeviceNum, ND_COUNTER_0, ND_COUNT_2, GateLength)             ' High cycles
    iStatus = GPCTR_Control(i6602DeviceNum, ND_COUNTER_0, ND_PROGRAM)       

5)  I have tried to use DAQmxSetChanAttribute to set the channel as source and to also to set the trigger, but I don't have any similar function like that in VB, It will be great if I am getting some assistance in letting me to know the function.

 

Thanks in advance

 

 

0 Kudos
Message 8 of 11
(8,579 Views)
Rajaram,

Let's please continue this in your other post, here. Keeping an issue on one forum helps the community follow along, as well as collaborating on answers.
David L.
Systems Engineering
National Instruments
0 Kudos
Message 9 of 11
(8,552 Views)

One example of when you would need to set up the gated count this way (instead of using the much simpler frequency) is when the pulses you want to count don't come at regular intervals. For instance, you might be counting nuclear decay events.

0 Kudos
Message 10 of 11
(6,179 Views)