Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Outputting time when using 3 DMA channels

Hi! I've got a slight problem with my Labview code, and I was hoping you could help me. I'm outputting counts from three sepearte channels and would like to know the time (how many milliseconds from when the vi started) each value was taken. Right now, I just get three columns, each with the counts taken from my three channels. I need a fourth column to specify the time.
Someone suggested I "Use the tick count vi as a time base outside the while loop and subract this from a tick count vi inside the while loop to get the elapsed time since the start of the vi." That didn't work (get about 10 time values), probably cause i'm doing buffered counting. I'm enclosing the vi i'm using and a sample output file. any help wo
uld be greatly appreciated.

Thanks,
katie
Download All
0 Kudos
Message 1 of 5
(3,600 Views)
Each iteration of the loop adds 1 value to your tick count array while adding (it appears) 100 values to your count arrays. So when you build your overall array after the loop, you have 100 times as much data in the count arrays as you have in your tick count array. LabVIEW fills in all the empty space with default values - 0.

A couple other suggestions come to mind, but I'd need to understand the purpose of your program better to be sure they're applicable. Mostly they fall under the category of improving accuracy and synchronism of your timing measurements. Can you describe your app in a bit more detail?
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 2 of 5
(3,600 Views)
Essentially, I'm trying to keep track of when the counts are taken. After X msec, how many counts are there on each channel? That sort of thing. Ideally, I'd know the amount of time needed for each measurement (ie, acquire for 3 seconds), but we know the exact value so I neeed to have an idea of when these counts are coming in. Thanks for you help!

Katie
0 Kudos
Message 3 of 5
(3,600 Views)
First some very generic advice that's mostly stylistic, but hopefully still helpful.
- when using the same Gate config info for all 3 counters, use a single front panel control and let the wiring fork off to the 3 places. Ditto for the device # control and others that are necessarily shared.
- assign the most commonly used values to your config controls (Gate, Source, etc) then "save as default". The big boldface instructions are good, but having the vi launch with the correct values already in place is even better.

Now the more relevant thoughts along with the assumptions that drive them:

Synchronization
---------------
1. I expect you want all 3 counters to be referenced to the same t=0 point. You had a good idea to query the tick count that will be used as t=0 in the sequence frame immediately *after* programming a counter. However, there is no sequencing / data dependency that makes sure the other 2 counters are started as near as possible to simultaneously.
1a. Software timing. What you'd need to do is perform all the config operations for all 3 counters *except* arming them ('program' value fed to "Counter Control.vi"), then arm all 3, then capture your msec tick count. You can use the error cluster to tie together the various config chains and provide the sequencing you need. With this software-driven timing, you can probably get the counters started within several msec of one another. I'd suggest ensuring that all initializations and other stuff "floating" outside the main loop are forced to execute before the counters are armed.
1b. Hardware timing. The better approach would be to configure all 3 counters to be triggered. Then you would arm all 3 counters before providing the trigger signal (which could be generated by another counter or a DIO pin on your card). This way, they all have the exact same t=0 point.

Events relative to time and/or other events
-------------------------------------------
2. Your program seems to use an external gate signal, which acts as an acquisition clock for your measurements. Whatever the timing of that signal may be, you'll be storing the 3 count values on each active transition. You end up with 3 arrays of event counts, with each value corresponding to an active transition of your gate signal, but with no particular timing information. Is this what you need? Or could you more simply sample the 3 sets of count values at a constant rate?
2a. Hardware timing, constant sampling rate. This approach basically ignores the gate signal. Skip to the next approach if this isn't acceptable in your app. Set up a 4th counter to generate a continuous pulse train at your desired sampling rate. Route its output to a RTSI line. Set up other 3 counters to use that same RTSI line as their gate signal. Arm the 3 counters before arming the 4th. With this approach, the time of an event corresponds to its index in the final array, one element per sampling period.
2b. Software timing, external gate signal. Basic idea is to build up 2 separate datasets, possibly 2 separate files. One will hold all the raw count data from your 3 counters, each containing one element per active transition of the gate signal. The other will extract only the latest reading from each of the 3 counters each pass through the loop, and combine it with the elapsed msec tick count -- i.e., one element per software loop.
2c. Hardware timing, external gate signal, more tricky. You could configure a 4th counter for event counting off the same Gate signal but with the Source set to 100 kHz internal timebase. You would also need to explicitly set this one up to use interrupts instead of DMA for its buffering. I don't know the speed of your gate signal, but a ni.com search suggests that interrupts can often handle from speeds from a few hundred to a thousand Hz or more. If you go this route (sub-msec timing precision on measurements), you should definitely set up all 4 counters for hardware triggering.
In this approach, your 4th counter would be your time array, scaled as 1 count = 10 microseconds = 1/100 kHz. Then you would bundle up this time array with your 3 count arrays into a single dataset.

Better stop now. You can always check the shipping examples or ni.com for more info on such things as interrupts vs. DMA, routing signals to RTSI, triggering multiple counters, etc. Good luck!
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 5
(3,600 Views)
Hey Katie,

Kevin had some great suggestions!

One thing to be aware of with hardware triggering (suggestion 1b) is that this is only supported with our counter boards that have the NI-TIO chip.
Here's an example that will work with our TIO boards and a document discussing triggering multiple counters simultaneously.

Simultaneous Triggered Buffered Event Counting with Two Counters

Triggering Multiple Counters with a Single Pulse

Here's an example that simulates a hardware trigger with can be used with
boards that have the DAQ-STC chip.

Synchronized Event Counting (DAQ-STC)

I hope you find these helpful. Please post back if you have any additional questions.

Sarah Miracle
National Instruments
0 Kudos
Message 5 of 5
(3,600 Views)