04-16-2010 03:44 PM
In combination with a USB-6009, "Stregkode.vi" is the main VI for my program "Printtest v1.0". When the operator inputs "12345" in the string-control, on the "Stregkode"-frontpanel and clicks OK, the "Test.vi" is called. This gathers measurements for voltage, current and frequency.
Now, the first time I click the OK button, and "Test.vi" is called, the DAQ works fine. The counter returns the value ~1415hz, which is OK.
Howefter, the next time I hit the OK button, on the Stregkode-frontpanel, the counter returns a incorrect value.
I cannot seem work my way around the problem. When I run the "Test.vi" by it self, it works fine. But when it is called upon, by "Stregkode.vi", it will only work the first time.
I suspect that it might be something with the structure of the program (loops ect.)
Question: How do I get the program to return ~1415hz, every time I click OK, without closing the program and opening it again?
Please help!
04-16-2010 05:32 PM
You are not closing your DAQmx sessions in your first sequence frame. You are stopping but not closing. So the second time you run it, you are opening another session when there was one previously open. This could cause problems. Put a close session function after the stop in each case.
Also, in your counter timer case (case 3), you have the counter running continuously in a loop until the elapsed timer goes off. Why run this continuously? If you want to delay before you take a reading, move the counter after the loop. The loop has no delay in it, so it will chew up 100% CPU time. I suggest you put a delay, even 0mS if you want it to run fast as possible. In this case however, I would think a 100mS delay will work. This will give the CPU time to perform other functions, and it may even solve your problem.
04-17-2010 02:08 AM
Well, by "close session" you mean "Clear Task", I already tried it - it did not do the trick.
The first time the program run, I am measuring aprox. 1400Hz. The second time I run the program (WITHOUT CLOSING IT), I am measuring 1-2Hz.
I made the While-loop in Case 3, with the "Elapsed Time"-function, so that the counter samples for 1000ms. That way, I can use the output from the "DAQmx Read"-block as a frequency-measurement.
I am afraid you have to explain this following a bit better:
"If you want to delay before you take a reading, move the counter after the loop. The loop has no delay in it, so it will chew up 100% CPU time. I suggest you put a delay, even 0mS if you want it to run fast as possible. In this case however, I would think a 100mS delay will work. This will give the CPU time to perform other functions, and it may even solve your problem"
04-19-2010 10:57 AM - edited 04-19-2010 11:01 AM
You should put a Clear Task at the end. If you don't, the task is somewhere out there in memory when your program ends. Then you run it again and a new task is created, but the old one is still in memory. This is not good programming practice. Put a Clear Task at the end.
If a loop does not have some delay in it, Labview will try to run it as fast as possible, which is desireable in some cases. However this comes at a price. The CPU is being used by Labview 100% of the time. There is no time for other functions, like updating the front panel, any background processing, etc. I have seen this cause problems in the past. By putting a delay, even 0ms in the loop, the CPU will have some time to do its other functions. I'm not saying this is your problem, but it is something to try.
Instead of putting the Couter in a loop to take multiple readings, setup the counter task to take multiple readings. Call it once, eliminate the elapsed time loop. You have the counter set for 1 sample. Set it for Multiple Samples -> 1D DBL, and then wire in the number of samles per channel. The counter will then take all the samples and will output an array of the samples.
04-19-2010 01:58 PM
I agree, I know that you have to free up the reserve resources. And as I wrote in the last post, I already tried using a "Clear Task", even before I posted this thread. I did not solve the problem, I am afraid.I
04-19-2010 02:15 PM
It may have something to do with running your counter in the elapsed time loop. You don't have to do this. Get rid of the loop and select the Counter - Multiple Samples - 1D DBL polymorphic function, and wire in the number of samples to take. Then average the number for the output. Otherwise, I can't see why it would give a different result the next time you called it. Try wiring the DAQmx error out wires to an indicator to see if there is an error.
04-20-2010 09:27 AM
Well, the weird part is that I tried another approach. I tried using two simple function-blocks: "DAQassistant" and the "Elapsed Time", still not working.
04-20-2010 12:04 PM
Post your new approach so I can look at it. Why don't you follow my suggestions and get rid of Elapsed Time, and set your counter for multiple readings? Try it.