11-13-2008 11:10 AM
Hi,
I am relatively new in LabView.
I am making power quality measurement system and I need to vary the sampling rate of my pci-6134 dynamically (all channels simultaneously). What I need is to have a constant amount of samples in each period of measured signal (grid voltage), which changes slightly all the time. Therefore I will have to measure the voltage, find its exact frequency and then adjust the sampling rate of daq accordingly. I know that there will always be some delay, but I would rather like not to go into any predictive algorithms...
I have found an information in the Forum that one of possible solutions is to use an onboard counter to change the sampling frequency but I have no idea how to make that. Can someone help me or possibly show an example?
Is there a simple way to solve that problem?
Thanks in advance
Andrzej
11-17-2008 05:03 AM
Hej Andrzej,
You cannot actually change the sampling rate of an acquisition while it is running, but there are several methods to accomplish what you want. One method would be to halt acquisition and change the rate before restarting. As another alternative, you can generate your own sampling clock and vary the frequency of that clock to change the sampling rate. There is a lot of information on our discussion boards that I think would be useful. I have included some of these links below:
Changing sample rate during acquisition http://forums.ni.com/ni/board/message?board.id=250&message.id=2144&requireLogin=False
DAQ examples: Cont Acq&Graph Voltage-To File (Binary) >> How to change sample rate and continue? http://forums.ni.com/ni/board/message?board.id=170&message.id=113514&requireLogin=False
Is it possible to change the Sample Clock Rate on the fly while performing a continuous analog input using a PCI-6221? http://forums.ni.com/ni/board/message?board.id=170&message.id=142372&requireLogin=False
Pease let me know if you need more information on the subject.
Thanks!
11-17-2008 07:05 AM
Hi Dennis,
Thanks for your reply!
I couldn't open some of links in the posts that you gave me but I have found other examples that helped me to understand the subject.
I think that the second proposal, namely generation of my own sampling clock and then varying its frequency dynamically, is suitable for me. The examples that were helpful are:
1. http://decibel.ni.com/content/docs/DOC-2227
2. ftp://ftp.ni.com/pub/devzone/tut/synchronization_code.zip
Thanks,
Andrzej
11-18-2008 07:13 AM - edited 11-18-2008 07:13 AM
Hi,
I have combined the mentioned examples to vary sampling rate dynamically but I still have some problems...
I have made a counter to work as a frequency source for an analog input. I want to be albe to change the sampling frequency of AI on-the-fly (beeing in a while loop). So I change the frequency of a counter during execution (using property node of a channel) but it does not change the sampling frequency. Where is the problem?
I attach my example to explain...
Thanks for any help
Andrzej
11-18-2008 07:48 AM
Hi Andrzej,
You need to connect the Counter output to a PFI line and use that line as input to the AI Sample Clock.
If you wire the Counter out 0 to PFI1 then choose Dev2/PFI1 from the pull down menu to the DAQmx Timing.vi for AI.
Thanks!
11-18-2008 10:32 AM
Hi Dennis,
Thanks for fast response as usual.
I can not connect counter output to PFI1 and then PFI1 to AI input because my device does not support that kind of routing (I get an error).
I have checked the allowed device routes and chose PFI3 as source and PFI8 as destination (I connect a counter output to PFI3 and then PFI3 to control AI timing). Both of them use counter 0 as subsystem. So I think it should work, but it doesn't.At least now I do not get any errors 🙂
Do I specify the terminal to generate pulses to correctly? Is this what you have thought about? I use property node: class DAQmx Channel, method CO.Pulse.Term.
I also attach a picture of the vi.
Thanks in advance for help.
Andrzej
11-18-2008 12:18 PM
At least at a glance, the code generally looks like it ought to work. Two thoughts:
1. Instead of getting into PFI3 vs PFI8 routing stuff, can't you just specify "Dev1/Ctr0InternalOutput" as the AI Sample Clock source? (You may need to right-click the terminal to get at the menu that exposes the so-called "advanced terminals").
2. Try writing both the freq AND duty cycle properties when you want to update the freq. Or try using the DAQmx Write vi instead of a property node. My past experience suggests that writing only the freq property *should* still work, but writing both isn't hard to try and may turn out to help if the behavior of your version of DAQmx differs somehow.
-Kevin P.
P.S. Bonus 3rd thought. I just went back to reread the thread more carefully, including your first screenshot. I'm now thinking that maybe the hardware actually WAS behaving properly, and that you just weren't aware of it. When you query the AI task for it's sampling rate, all the task can know is whatever rate you told it when you configured it outside the loop. So even as you change the counter freq to change the actual hardware sampling rate on the fly, the AI task will continue to report its orig freq. After all, how is *it* supposed to know?
Try an experiment: Set your original freq very low so that the AI task produces a timeout error without getting all the requested samples within the 10 sec timeout window. Run and verify the timeout. Then run again, but after 3-5 seconds set a new frequency that will produce all those samples in another 1 sec or less. Verify that you get the samples rather than timing out. That should demonstrate taht the counter freq change really *does* produce a change to the hardware sample rate, even though the task property node remains unaware.
11-19-2008 09:43 AM
Hi Kevin,
Thanks for your thoughts. I tried them and these are my comments:
--> 1. I tried different routes, also the one you have suggested and all of them which are allowed in MAX seemed to work (\not worked?) exactly the same.
I think it is just important to use 'direct routes' and then it should be ok.
--> 2. I will use both frequency and duty cycle properties from now on. Thanks for that one, it is always good to know 'good practices'.
I am not sure how to use the DAQmx Write vi instead of property node in this situation, but the above solution should also work (I think) so I will stay with property nodes.
--> 3. I made similar experiment to the suggested one. I have set the frequency to very low before the loop (and run it: it does generate error) and then changed the counter frequency to much higher as the first thing in the loop. If the frequency of AI was changed on the fly with counter's frequency I wouldn't get any error. Unfortunately there was an error. So, it means that AI task does not see the change in the counter frequency. But I thought that if i set the counter to act as a source to AI it would be enought to change the counter's frequency for changing AI's sampling rate. I thought that when I specify the correct routes to 'connect' counter's output to AI's time vi, the rest will be done by hardware and not by software and then I will be able to change frequency on the fly. So where am I wrong here? And can anyone have any ideas how can I implement dynamic change of sampling rate in AI, then?
Big thanks for any suggestions,
Andrzej