Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

counter source and gate config for timestamping

Hi,
 
I was loooking for advice on setting a counter's Gate and Source terminals.
I'm using an M-series PCI-6221 under DAQmx 8.3. I'm programming in C++.
 
I got some good advice in a previous thread (Multifunction DAQ | timestamping asynchronous digital inputs) about setting up a timestamping operation. Essentially, I connect a clock to the Source terminal of the counter, and the signal I want to timestamp to the Gate terminal.
 
What I'm not clear on is what are the functions to:
1) set the terminal pin for the Gate, 
2) set the terminal pin for the Source, 
3) when I utilize  DAQmxCfgSampClockTiming(taskHandle, "100kHzTimebase", ...) will this by default route the 100kHzTimebase to the default terminal for a Counting Edges operation?
 
I'm interested in routing the internal 100kHzTimebase to the Counter Source terminal, and the PFI4(=Ctr1 Gate) to the Counter Gate. 
 
Thanks for any suggestions.
0 Kudos
Message 1 of 17
(5,024 Views)
Hi IUB,

Are you looking to do counter input or output? From you discussing the gate and source, I believe you are doing counter input. The way to setup your gate and source terminals is to create a counter input task. Once this is done, the driver knows to associate the appropriate lines for the counter gate and source, and no other setup is necessary besides connection to the appropriate pins.

For your third question, the function "DAqmxCfgSampClockTiming" simply uses the parameter 'const char source[]' as a source for your sample clock. Therefore, if you have 100kHzTimebase, your sample clock will run at 100Khz. The NI-DAQmx C Reference Help is a great guide to use, and can be found under Start » Programs » National Instruments » NI-DAQ.

Lastly, our shipping examples are located here C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter , and are always a great starting point for a program.
David L.
Systems Engineering
National Instruments
0 Kudos
Message 2 of 17
(5,012 Views)

Hi David L.,

Yes you are correct in my objective, a Counter Input (CI) task. I started with a code example shipped with NI DAQ, namely Cnt_Buf_Cont_ExtClk.c  .Unfortunately, using the DAQmxCICountEdgesChan function (which is the only function call for a Counter Edge task) only senses inputs at a single terminal (Gate or Source) of the specified Counter (default being Source). It ignores the activity on the other terminal. I've tried to use DAQmxConnectTerm and DAQmxCICoutnEdgesTerm to route a particular terminal (e.g. PFI4) to the gate, while using DAQmxCfgSampClockTiming but run into resource conflicts.

Do you have a suggestion for another function to create CI task, or how best to have the system use both gate and source terminals to timestamp?

Thanks for your assistance

0 Kudos
Message 3 of 17
(5,010 Views)
IUB,

You can put a digital pause trigger in your code by using a Daqmx trigger property node. The Digital Edge Properties can be found in the NI-DAQmx C Reference Help under "NI DAQmx C Properties » List of Trigger Properties » Pause ". I would also suggest looking at the shipping examples to see how they are setup to use digital triggers. A good example of using a trigger can be found under C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Generate Pulse\Dig Pulse Train Cont-Pause Trig. When using a pause trigger, your counter will count, unless the trigger occurs.
David L.
Systems Engineering
National Instruments
0 Kudos
Message 4 of 17
(4,983 Views)

Hi,

Thanks for the information. I'll try the digital pause trigger method and see how it goes. However, if the counter stops counting when the digital input (to be timestamped) occurs, then the absolute 'time' (counter state) will be delayed. Even if the counter state is delayed by one update, I imagine the accrued error will be large after minutes of recording.

Just in case others are tracking this thread, I found a good description of timestamping at  http://zone.ni.com/devzone/cda/tut/p/id/5404 : Buffered Event Counting. Unfortunately, for me, it's in reference to LabView and not C/C++.

0 Kudos
Message 5 of 17
(4,982 Views)

Dear DAQ learners,

In recent days,I read the DAQ X Series user Manual about Counter.

I want to use Gate signal and Source signal to make counter work on the high time of Gate Signal and not work on the low time of Gate time.

I really want to know that how can i use Gate siganl ?

When i connect the a TTL siganl to the Gate Terminal according to the NI MAX,the counter will work with the gate signal automaticly?

What parameters should i set?

Can i connect Gate signal to any PFI terminal?

Relative figures are showed below.

Looking forward to your reply!

Thank you very much!

Yuzn

July 9 2021

Yuzn_0-1625839373721.pngYuzn_1-1625839436754.png

Yuzn_2-1625839460916.png

 

 

0 Kudos
Message 6 of 17
(3,178 Views)

1. No, the gate signal is not automatic.  The gate signal can play several different roles, depending on how you configure your counter task -- so you need to configure the task according to the behavior you want in response to the gate signal.

 

2. I *think* you are looking to use the gate signal as a "pause trigger".  In this configuration, the count only counts while the gate signal is in the active state -- for you that would be the high state.  Which means you'd configure to "pause" the task when the gate signal is low.

    It isn't clear whether your task is about counting edges or generating pulses.  What I said above is true for either one, but it may not be obvious what "counting" has to do with pulse generation.   Down at the lower level, the timing of the pulse train is governed by counting a known constant timebase clock.

 

3. MAX will show you the available routes for your timing signals.  In general, X-series are highly flexible for routing, so there's a large variety of PFI pins you'll be able to specify as your gate signal (aka your "pause trigger source").

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 7 of 17
(3,169 Views)

Thanks for your reply!

I want  to genetate pulses and use gate as 'Pause Trigger'.But my pluse is defined by me.

There is a good news.I dicover that the retrigger function is useful for me to relize my control too.

But Labview has error that  the fuction 'wait until done' warn my program overtime.But i have set a righttime for my program.

My program is showned below.

Thank you very much!

Yuzn

July 11 2021

0 Kudos
Message 8 of 17
(3,165 Views)

I *think* I recall that a retriggerable task will never be considered "done".  So you need to avoid calling "DAQmx Wait Until Done."  Instead, you can put a software loop there to prevent the code from falling straight through to DAQmx Stop immediately after you call DAQmx Start.

 

You can look at the shipping example for continuous counter output for guidance.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 9 of 17
(3,158 Views)

You are right!Thank you very much!

By the way , I  also have two questions.

First,i also want to know that how can  i configure Gate signal to output signal as 'pause trigger' and what function should i use?

I think that if i connect a TTL signal which i  defined as the source of Sample clock or StartTrigger  ,the daq will connect the  TTL signal to the Gate Signal automaticly.

Is my idea right? 

Yuzn_0-1626081142804.png

Second,i want to use Continue pulse train genration to realize a Frequency Division ,should i use two counters to realize this function(one is used as source ,the other  is used as Frequency Diviosion Out). What parameters should i configure? 

Yuzn_0-1626084156237.png

Looking forward your reply!

 Yuzn

July 12 2021

 

 

 

 

0 Kudos
Message 10 of 17
(3,135 Views)