LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

setup counter gate input in CVI

Hi,
I have a PXI-6733 board and I want to make a gated edge counting using CVI.
I managed to make it count the edges but I cannot make the counting pause and resume from the gate input.
 
I feed 200 pulses to the source input and a (simultaneous) wider pulse to cover all or some of the 200 pulses to the gate input.
No matter how I change the gate pulse the counter always gives me 200, even if a do not connect the gate signal at all!
 
I went through the DAQmx and hadware documentation a few times but I could not find hoe I am going to "enable" the gate input so that counting is active only when the gate input is high.
 
Does anybody have experience doing this in CVI with DAQmx?
There are hundreds of posts about this but they are either incomplete or they talk about an older library other than DAQmx.
 
Regards,
S. Eren BALCI
IMESTEK
0 Kudos
Message 1 of 8
(4,756 Views)
Hello,

To enable the gate pin to pause a counter, you need to configure a pause trigger in CVI with DAQmx.  To do this, you need to use the DAQmxSetTrigAttribute function and set the Trigger Type to DAQmx_Val_DigLvl.  You will also want to use this function to set the Digital Level Source and the Pause when attributes.  You can find the Pause Trigger type attribute as well as the others under More >> Pause.

I hope this helps get you started.  If you run into problems let us know.

Regards,

Jesse O.
Applications Engineering
National Instruments
Jesse O. | National Instruments R&D
Message 2 of 8
(4,728 Views)
Hi Jesse,
Thank you very much for the answer.
 
From the documentation I see that the default gate inputs for counter 0 and 1 are PFI-9 and PFI-4 respectively.
So, are the following lines for configuring the gate input channel correct?
 
sprintf (gate, "Dev1/pfi%i" counter == 0 ? 9 : 4);
DAQmxSetTrigAttribute (task, DAQmx_DigLvl_PauseTrig_Src, gate);
 
I omitted other config code (trig type, level, etc) for clearity.
Regards,
S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 8
(4,708 Views)
Hello,

You are correct about the default gate pins being PFI 9 and PFI 4.  The only problem with your code that I see is the string you are using for the gate.  Typically you need another "/", so the pause trigger source would be "/Dev1/PFI9" instead of "Dev1/PFI9"

I hope this helps.  If not please let me know.

Regards,

Jesse O.
Applications Engineering
National Instruments
Jesse O. | National Instruments R&D
0 Kudos
Message 4 of 8
(4,688 Views)

Hi Jesse,

Yes, something was wrong when I tried the code. But it was not the beginning "/" it was the "Dev1/" prefix.
When I tried the code in the previous code, I got an error like invalid resource or smth like that.

Then, I changed the channel name from "Dev1/pfi9" to "pfi9" only and it worked without any errors and correctly counting the edges only during the gate pulse.
My gate pulse was supposed to block the counting of 80 edges out of 200 and I actually got a count of 120 which is what I wanted.

Could you please also verify that my way of channel name assignment is correct or not?

Thanks for all the help.

S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 8
(4,680 Views)
Hello,

I don't think you should be having any problems if your code executes and seems to be pausing correctly.  It should either work or not.  I setup a pause trigger for the CVI example by adding the following code:

        DAQmxErrChk (DAQmxSetTrigAttribute (gTaskHandle, DAQmx_PauseTrig_Type, DAQmx_Val_DigLvl));
        DAQmxErrChk (DAQmxSetTrigAttribute (gTaskHandle, DAQmx_DigLvl_PauseTrig_Src, "/Dev1/PFI0"));

If I specify the source as "/Dev1/pfi0" it works as well as "/Dev1/PFI0".  However if I specify "Dev1/PFI0" or "Dev1/pfi0" it does not. 

Regards,

Jesse O.
Applications Engineering
National Instruments    
Jesse O. | National Instruments R&D
0 Kudos
Message 6 of 8
(4,664 Views)

I think it is strange to be able to specify a digital port, for example, by "Dev1/port0" and getting an error message for "Dev1/pfi9".
Is there a specific reason for requiring the first "/" while specifying a PFI channel and not requiring it for a digital port or an analog channel?
In my application, writing only "pfi9" (without "Dev1/") worked. That was also unexpected for me.

S. Eren BALCI
IMESTEK
0 Kudos
Message 7 of 8
(4,659 Views)
Hello,

I just tested using "PFI0" and it works for me as well.  When specifying a channel for a digital or analog task with the create channel function, you are correct that you can specify "Dev1/ctr0", however "/Dev1/ctr0" also works.  When specifying the source for a pause trigger, you must have the extra "/".  This is just the convention used.

On a side note, using "pfi9" instead of "/dev1/pfi9" is that if you rename your device to dev2, you don't have to change your code.  I'm glad your code is not working.  If you have any questions please let us know.

Regards,

Jesse O.
Applications Engineering
National Instruments
Jesse O. | National Instruments R&D
0 Kudos
Message 8 of 8
(4,644 Views)