05-31-2012 12:32 PM
nathand,
This does get converted to boolean, oh yes, I set the output voltage for my card on it's external power supply, not in the labview code. Good call.
What other features or benefits would I receive for using those lower down DAQmx functions? As I understand, its better programming, but is that for the execution speed of the program, or just to learn incase I would need to do more in depth coding later on? I guess I don't know why I'd use them for this program?
Assuming this improves speed, I have a program that has this PWM output (from above), and an analog input part (both in same program), and every time the analog input runs, the program lags slightly. So every time the analog input updates the graph, the PWM output lags slightly because they are in the same program, which isn't too noticeable at low frequencies, but at higher frequencies it gets bad. Would using the DAQmx functions fix this?
Thank you.
05-31-2012 01:01 PM
g e m i n i wrote:
What other features or benefits would I receive for using those lower down DAQmx functions? As I understand, its better programming, but is that for the execution speed of the program, or just to learn incase I would need to do more in depth coding later on? I guess I don't know why I'd use them for this program?
Truthfully it probably doesn't matter much for your program. There might be a small amount of overhead in using the DAQ Assistant, but in this case (from right-clicking Open Front Panel on the DAQ Asst) it looks like there's not much. However, the DAQ functions are pretty simple and easy to use, and they'll actually clean up your code a bit (you'll be able to configure the task for a single digital line, eliminating the build array). Also, you'll have control over when the task is started, stopped, and cleaned up. A lot of experienced LabVIEW programmers have an aversion to any Express VI, including the DAQ Assistant, because we like to know what's going on in detail and the Express VIs often contain overly-complicated code in order to cover every possible case.
If you can post your whole program, with the analog input part as well, I'd be happy to take a look. Without seeing the code it's hard to guess at what's happening.
05-31-2012 01:53 PM
Thanks nathand,
Attached is my program. I simply have a digital out on a switch, a pwm output, and an analog input which gets displayed in a mixed signal graph.
On simulated hardware, the pwm signal runs completely smoothly, but when I hook up the actual cards and try, every time that the mixed signal graph updates, there is a very slight lag/pause that labview gets.
Also, when the mixed signal graph was inside the same while loop, the while loop would only get updated once per second, which was pretty slow.
Question, I guess you probably cant see the lag, but do you see any improvments that I could make? I know I should use the DAQmx, but I have yet to figure those out.
Thanks again.
05-31-2012 03:58 PM
It's never a good idea to run a loop in LabVIEW indefinitely without having some sort of wait. A loop that executes a fixed number of times, like a for loop, is fine at full speed, but anything that runs continuously without stopping will consume all the CPU available, preventing other tasks from running. That's roughly what your upper loop is doing. Once a second the bottom loop wakes up (the DAQ assistant is set to read 1000 samples at 1000 samples/second = 1 second) and interrupts the upper loop, causing that moment of lag. This is why in my first message I said you'll never get consistent software timing at that frequency. Windows will frequently and unpredictably interrupt your loops, and if you try to do other tasks on your computer while that loop is running, either the computer will feel very slow or the loop rate will become unpredictable depending on task priorities.
As might be obvious from the above, the reason the loop only updated once a second is because you set the DAQ assistant to acquire 1000 samples at 1 kSamples/second.
05-31-2012 04:17 PM
Awesome! I added a wait 1ms on the top loop and a wait 1000ms on the bottom (max time values so that I didn't affect performance), and I looked at my cpu usage and it was around 10% lower after adding the wait ms functions! So, Im thinking and hoping this will fix my lag issue! I'm not sure if it will yet, but tomorrow I will be able to try my labview code out again. I really appreciate all the help!
I will hopefully report back tomorrow that it works flawlessly.
06-01-2012 01:17 PM
Its working a lot more smoothly, thank you!
08-13-2012 07:15 PM
The Multifunction DAQ (for instance NI-6210) PWM generation example/white paper on the NI web site here: http://www.ni.com/white-paper/2991/en provides examples and details for using the counters on a Multifunction DAQ but the text ALSO says that the digital lines can be used for PWM
"...it's worth noting that National Instruments hardware and software also supports generation of PWM signals using digital line(s)..."
without providing an example of how to do this. Some other posts on the NI web site, including this thread, seem to indicate that the only way to do PWM with Multifunction DAQ digital lines is with software timing. Is that right?
For context, the bigger issue I have is this: using a single Multifunction DAQ device (e.g., NI-6210) I would like to generate three independently controlled PWM outputs. Is this possible or not?
08-13-2012 07:48 PM
The spec sheet for the USB-6210 says it has 2 counter/timer channels and that they support pulse generation. That means you can generate 2 PWM signals in hardware. Not sure why you can't find any examples, but pulse train generation and PWM generation are the same thing, so look at the examples for pulse train generation. For the third channel you'll either have to accept software timing (less accurate and a much lower maximum frequency), add another card, or switch to a board that has more counter/timer channels. I don't know if any USB multi-function DAQ boards have more than 2 counter channels.
01-11-2013 08:00 AM
Hello,
I am using a DAQ that has 2 timers and 16 Digital output pins. I want 4 PWM signals. Is there a way to generate 4 PWM signals simultaneously using 4 digital output pins?
01-11-2013 08:43 AM - edited 01-11-2013 08:44 AM
Hi hshah14,
yes, there's a way...