03-03-2014 10:18 PM
Hi all,
I am working on an application where I need to send some digital outputs seperated by precise timing delays.
So for example, I may want to output a 'high' to channel 1, then have a 20ms delays, then output a 'high' to channel 2, then have a 50ms delay, and so on.
I want the timing delays to be easily adjustable and I would like them to be precise.
The program is being set up for hundreds of tests and it will be run once per test. In between tests I will have the opportunity to modify timing delays.
I already have a cDAQ-9174 chassis and am planning to buy a NI 9401 high speed digital I/O card. It has been suggested to me that I use a counter (which is built into the chassis) to generate the timing delays, which sounds like a good idea to me. However, I don't really understand how to access the counters and configure the 'DAQmx create channel' function because there are so many options for the reference clock which I don't understand.
I am thinking that I need to implement something like this:
http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/hwtimedcounter/
However I'm if this is what I need and I'm not sure how I would go about testing this code. I guess I would need to connect some sort of output to the counter to see if it's working correctly.
Any help would be much appreciated.
03-04-2014 12:51 AM
I have had a go at creating a basic counter Labview program and it does not work as I expect. Perhaps I am missing an important concept. I have attached a screenshot of my program. As you can see it's a basic 'CO-pulse generation-tick' function with a 20Mhz timebase. I am using cycles of 2 high ticks and 2 low ticks, so I expect that I should get 5000 cycles per second (20,000/(2+2)).In the while loop I divide the loop counter by 5000 so that 'quotent' should increment one per second. When I run my program for 60 seconds this is what the final values are:
Real time elapsed: 60s
Loop counter: 67,870,363
Quotent: 13
As you can see, I would expect quotent to be 60, but it is 13. Can anybody explain this to me?
03-06-2014 12:41 AM - edited 03-06-2014 12:45 AM
Just noticed that the attachment wasn't attached! Fixed.
03-06-2014 01:03 AM
03-06-2014 11:56 PM
I thought it was similar to a digital output, where the 'Is task done' function waits untill an output is sent, and then iterates. By the sounds of it I am mistaken.
So then how do I track the counter? I would like to have the counter count up to 100,000 (with a 20MHz timebase, to give me a 5ms delay) and then so something else in the program.
03-07-2014 06:25 AM
03-11-2014 01:00 AM
Hi GerdW,
Thanks for the tip. I am having a bit more success with the finite setting for the counter.
The reason I want to use a counter over a simple 'wait' function is because I want precise timing, as I mentioned in my first post. An engineer from NI recommended that I do it this way.
I have currently implemented this:
https://decibel.ni.com/content/docs/DOC-12165
However, because there is no option to select the physical clock, I am not sure if this is a physical clock or a software clock that is being used? I would appreciate any comments on this.
Ultimately, I want the counter to physically count a finite number of pulses and correlate that to a precise time that I can use for the delay in my program.
03-11-2014 01:38 AM - edited 03-11-2014 01:40 AM
After a bit of experimenting, now I'm not sure if the hardware time delay has any advantage over the software delay. I can get a constant 5ms delay using the 'wait' function, yet when I use the counter I can normally get a 5ms delay, but sometimes (perhaps one trial out of five) I get a 4 or 6ms delay. I have even seen a 1ms delay using the counter method. Perhaps my method for measuring is flawed though? I have attached some screenshots of my program. If anybody has any comments it would be appreciated.
03-11-2014 02:41 AM - edited 03-11-2014 02:41 AM
HI Marc,
your method of measuring time is highly flawed!
- Remove all those locals and use wires instead.
- You only read the time with a 1ms resolution. Due to rounding errors you can easily get 4, 5, and 6ms as result of your "measurement"!
- LabVIEW also provides a high resolution timer, found at vi.lib/utility/HighResolutionRelativeSeconds.vi
- Measuring times in the order of just several ms is also tricky in a multitasking environment like Windows…
03-11-2014 06:20 AM
Thanks GerdW, I will try your suggestions tomorrow. Do you think that in theory using a hardware counter is a more precise and repeatable way of getting my required time delay as opposed to the software 'wait (ms)' function?
I'm aware that the best way to do it would be to use an FPGA or a cRIO with labview RT, but I am working with the hardware which I have, which is a cDAQ chassis.