LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I output three digital waveforms at once?

I posted this in Digital I/O, but now I think it's actually more appropriate here because it's not a hardware question. I need to output three digital waveforms at a relatively low frequency, 71.9 Hz. I have a PCI DAQ card, the 6024E and am using the NI-DAQmx functions to try to do this. My program basically generates the square wave that I want, and converts it into a digital wave. I do this 3 times for the three separate waves, and then I combine them into an array and send them to my DAQ functions, which are in a while loop so I can get continuous output. My problem is that the waveform that the DAQ is actually outputting is not what I want. It's outputting a wave that has the same duty cycle (approximately) but the frequency is over 2 kilohertz. It's not like this all the time; after it outputs about 7 cycles of this wave, it goes to logic low for a long time, and then repeats itself. When I probe the digital waveform right before it goes into the DAQ functions, it's running correctly at 71.9 Hertz. Am I doing anything wrong with the DAQ functions or the sampling information? Thanks in advance.

-- Josh Matloff
0 Kudos
Message 1 of 9
(3,434 Views)
Posting your code would go a long way in trying to assist you.
It almost sounds like you should be using a timer/counter card instead of discrete digital outputs.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 2 of 9
(3,426 Views)
I thought about using counters, but I had trouble setting them up. Here's my code though. In this version, I fixed the delay between it outputting the wrong waveform, but it's still outputting at an astronomical frequency, comparatively speaking.
0 Kudos
Message 3 of 9
(3,422 Views)
Ensign:

I have not worked with the new signals and DAQmx functions yet, I am clueless here. Pretty cool though, I was unaware these functions existed.

It looks like you set things up for digital channels, but the DAQmx function in the while loop appears to be for use on an analog output (I may be wrong here).

Hopefully someone will come to you aid shortly.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 4 of 9
(3,419 Views)
If you want the waveforms to change as you adjust the servo controls, you need to have the controls in the while loop. Next, you don't want to constantly update the wave form. You only need to update the wave forms when the values change. An event structure can be used to accomplish this. And finally, whenever you open a task you should always close it when done.

Attached is some modified code that may work.
0 Kudos
Message 5 of 9
(3,406 Views)
Hello Josh,

I'm pretty sure that the reason that your digital waveforms are not being produced at the correct frequency is because your digital output is not associated with any sort of timing. Unfortunately, with an E series board you can only do software timed digital operations. This means that the frequency at which the values on your digital lines will be updated depends on how fast/often your computer executes the DAQmx Write that is inside of your while loop. If you have an M series board, you can actually correlate the DIO operations with another subsytems clock (AI/AO sample clock, etc.) which means that you can acheive hardware-timed DIO. In the event that you do not have access to an M series board, I think that AnalogKid2DigitalMan was spot on that you would want to use counters to generate pulse trains (that is if your digital waveforms have a constant duty cycle and period). Depending on what the DAQ board is outputting to, you might also want to consider using the Analog Output channels to generate your digital waveform. As long as you continue to use the digital lines on the 6024E, there is not really a way to guarantee the timing of when the digital lines will be updated. You might be able to get close, but you will probably see some "hiccups", especially if your computer needs to service interrupts or give processing time to another application. And lastly, heed geckoee's advice and don't forget to properly close out your tasks! Putting in some error handling may also help in the debugging process.

Take care,
E.Lee
Eric
DE For Life!
0 Kudos
Message 6 of 9
(3,383 Views)
Thanks to everyone who responded! I now think counters are the way to go.
0 Kudos
Message 7 of 9
(3,369 Views)
Ensign, someday you'll make a good Captain 🙂

I have used the outputs of multiple counters and fed them into 74XX series logic gates to create modulation schemes.
For example, doing a logical AND (7408N) on the output of 2 counters running at different frequencies of 400Hz and 25KHz and duty cycles to perform complex PWM schemes for laser power control. Much easier than doing in software.

May be worth consideration if it applies to your needs.
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 8 of 9
(3,367 Views)
Well, I did successfully output one of my waves using a counter. It outputs at the right frequency. Right now I just have to figure out how to copy that same waveform but change the phase delay using LabVIEW. The main problem is that I only have two counter outputs, and I need three seperate spikes in my wave.
0 Kudos
Message 9 of 9
(3,365 Views)