LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM timing issue

Solved!
Go to solution

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. 

0 Kudos
Message 11 of 22
(1,186 Views)

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.

0 Kudos
Message 12 of 22
(1,180 Views)

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. 

0 Kudos
Message 13 of 22
(1,173 Views)

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.

Message 14 of 22
(1,162 Views)

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.

0 Kudos
Message 15 of 22
(1,160 Views)

Its working a lot more smoothly, thank you!

0 Kudos
Message 16 of 22
(1,152 Views)

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?

0 Kudos
Message 17 of 22
(1,129 Views)

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.

0 Kudos
Message 18 of 22
(1,124 Views)

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?

0 Kudos
Message 19 of 22
(1,089 Views)

Hi hshah14,

 

yes, there's a way...

 

Spoiler
Don't mind to provide more information like available hardware and required PWM specs?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 20 of 22
(1,085 Views)