Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

how to cascade 2 counters to get 64 bit timer?

Solved!
Go to solution

I am working with the PCI-6225 which has multiple counters.  I have configured CTR0 at 20MHz.  I obtain the time from CTR0 by calling the NI-DAQmx C function 'DAQmxReadCounterScalarU32' to get the frequency count and then dividing the frequency count by 20MHz to get a time value.   The maximum time value that can be obtain is only 214.7483648 seconds (i.e. 2^32 / 20e6).    I would like to cascade/link two counters (i.e. CTR0 and CTR1) to obtain 64 bit frequency values.    To be clear,  CTR0 would be configured as the LSB 32 bits and CTR1 would be configured as the MSB 32 bytes so that each time CTR0 reaches the maximum values and 'rolls over' then CTR1 would be incremented by 1.   How can I do this using the C functions in NI-DAQmx?

 

Thanks

 

Ian

0 Kudos
Message 1 of 7
(4,785 Views)

Hi Ian,

 

This can be done by physically wiring the Out of Counter 0 to the Source of Counter 1 and changing the output behavior of Counter 0 from Toggle to Pulse.  If the output behavior is still in Toggle, Counter 1 will only detect every other time Counter 0 rolls over.

Jeff S.
National Instruments
0 Kudos
Message 2 of 7
(4,766 Views)

Hello Jeff,

 

So just to be clear, there is no way to do this in software?

 

Thanks,

 

Ian

0 Kudos
Message 3 of 7
(4,756 Views)
Solution
Accepted by I_B

Doing it in hw is gonna be more reliable, but here are a couple possible ways to approach it in sw.

 

1.  There's a DAQmx property with a name similar to "Terminal Count Reached" that I've used in LabVIEW but don't know the underlying C syntax.  When you query it in software, it will return a True once and reset itself back to False.   I'm pretty sure it will return a True again on the *next* rollover event, but you'd better double-check me on that.  Not knowing your whole app, I suppose you will probably need to be prepared to handle multiple rollovers.

 

2. In some apps, rather than setting up a measurement that tracks cumulative time, you can set up the hw to measure periods and then do a cumulative sum in sw to get your "timestamps."   Unless an individual interval might exceed 200+ seconds, you can just do your software accumulation with a 64-bit datatype.

 

Technically, you can even do both.  Do a hw measurement of 32-bit intervals, do a software query for the tc event, accumulate intervals & rollover counts into a 64-bit int.

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 7
(4,740 Views)

You can avoid the physical wiring by using the Ctr0InternalOutput terminal as the source for counter 1.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
0 Kudos
Message 5 of 7
(4,733 Views)

Also note that if you cascade ctr0 and ctr1, the value can change between when you read ctr0 and when you read ctr1. I think the usual solution involves reading MSB, then LSB, then MSB again. If the MSB counter changed between the two reads, then the LSB counter rolled over.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 6 of 7
(4,730 Views)

To bstreiff and Brad, 

 

Thanks, this is what I was looking for.

 

Ian

0 Kudos
Message 7 of 7
(4,719 Views)