LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to compose an arbitrary waveform for DAQmx?

Solved!
Go to solution

Hello,

 

I want to build an arbitrary waveform generator in LabVIEW.

The signal should be generated by an analog output of my USB DAQ card NI USB-6353.

 

There are lots of examples available with standard waveforms like sine, square etc.

But I would like to create a waveform step by step.

 

For example, my waveform could consist of the these five sections:

  1. Ramp up to 4V in 2sec
  2. Hold the 4V for 2sec
  3. Ramp down to 2V in 1sec
  4. A sine with 2V DC offset for 3sec
  5. Ramp down to 0V in 1sec

waveform.png

How can I generate such a signal in LabVIEW?

Are there any examples showing how to compose an arbitrary waveform in sections?

How to output the waveform on an analog output of my DAQ card?

 

Any suggestions are appreciated, I just don't know where to start.

 

Thanks,

Dietmar

 

 

0 Kudos
Message 1 of 10
(9,303 Views)

If you built them into waveforms, there is the nice Append Waveforms VI.  You just make each of your sections and use that VI to append them.  You can then just write that waveform out your DAQ.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 10
(9,293 Views)
Solution
Accepted by schuller

I'd suggest you begin by developing code that generates your specific waveform and plot it on a graph.

 - Look at a state machine (simple for loop with a case structure inside wired to the iteration terminal, one case for each stage of your waveform, that appends it's waveform portion to the waveform. Store the waveform on a shift register, appending each new part in each case of the state machine.

 

When you're happy with that code, look into how you can feed that waveform into a DAQ output buffer. The examples you've found for continuous output should be useable, replace the sinewave generation with sections of your waveform.

 

If you need more general assistance with LabVIEW, view the online training material - the basics stuff is free and very useful.

 

Good luck.

Thoric (CLA, CLED, CTD and LabVIEW Champion)


0 Kudos
Message 3 of 10
(9,292 Views)

Hello,

 

I have a followup question to this idea. I am effectively doing the same thing as Dietmar (generating a long arbitrary waveform). However, no consecutive periods are the same. Each period is larger or smaller in amplitude than the last. I am outputing Analog Output at 2 MS/s, and my waveform can be over a minute long. I receive out of memory errors if I attempt to write the entire waveform to a DAQmx Write. Because every period is different, and it doesn't repeat, I can't use regeneration. 

 

The  best idea I have found so far is to split the waveform into chunks, and save the chunks to a TDMS file. I load a few chunks at a time into a queue, and then output a chunk at a time. This way I can at least handle my large waveform. However, I am seeing up to a 200 ms delay between loop iterations. Reducing the chunk size reduces loop delay, but even a few ms delay between segments ruins the experiment. This also makes sense, as the DAQmx write must finish before moving on to the next loop iteration, which will take time.

 

I have tried putting all data loading into parallel processes (the idea being as long as you load chunks into the queue in parallel faster than the DAQmx Write takes to complete, you should be good), but it returns similar results. 

 

Are there any recommendations on how to output large arbitrary waveforms that cannot be held in memory all at one time?

 

Thanks,

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 4 of 10
(9,070 Views)
Anybody have any ideas?
Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 5 of 10
(9,011 Views)

I don't have the hardware to experiment with, but I don't think you need your output to stop as you add the next chunk.  You can query the devices queue size, and how much is left.  So if you put down 5,000 points, then just query the device until it is under 2,000 then put down the next 3,000 with the write, of course it needs to be finite, not continuous but I assumed it would just continue.

 

If that doesn't work I do have a solution, but it probably won't work in your situation.  A while ago we had a need for outputing an arbitrary waveform that went for 10 hours and didn't repeat.  The number of setpoints was few say a couple hundred at most, but we needed code to calculate the values in between the setpoints.  So say I would start at 5V, and then I needed to ramp to 10V in 2 hours.  I tried the DAQ method of creating the wave and putting it on the hardware but it was way too many points.  So I went with an FPGA.

 

https://decibel.ni.com/content/docs/DOC-35912

 

I was very happy with that example, but depending on your FPGA hardware choice you can probably run it faster, and the code could probably be improved with some single cycle loops.  The impressive part was when the FPGA would sample it's own output.  I could then graph the expected output versus the actual.  Then I'd have to zoom in over and over just to show the two lines were exactly on top of each other.  The difference was likely the clock cycle it took to sample the output so we were always shifted by about 1ms on the graph.

Message 6 of 10
(8,993 Views)

Hi Hooovahh, 

 

Thanks a lot for the suggestions. I'll definitely give this a shot. I was auto-starting the DO task without thinking about it, which is why I was assuming the Write had to complete before moving on. I don't see why I couldn't do it the way you describe. An R-Series card may be an option as well... I'll look into budget.

 

Much appreciated!

 

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 7 of 10
(8,983 Views)

Just following up here. I still haven't had a chance to work with hardware. But this is my best bet moving forward for long arbitrary waveforms. It's similar to what you suggested with the tweak of using RegenMode = Do Not Allow and AO.DataXferReqCond = Onboard Memory Less than Full: 

 

http://digital.ni.com/public.nsf/websearch/45A7AC6B59E026B386256F90006DAA49?OpenDocument

 

The final question will be if there are any discontinuities, but as long as you're righting to memory at the right speed I believe it should work.

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 8 of 10
(8,940 Views)

Schuller,

I wrote and example of an artibrary waveform function generator for use with DAQmx a few years ago.  

 

The example is found here:

https://decibel.ni.com/content/docs/DOC-25313

 

It allows on-the-fly adjustment of signal frequency, amplitude, phase, offset and will load custom waveform shapes specified by simple text files.  Possibly it may be of use to you.

 

Regards,

Steve

Message 9 of 10
(8,914 Views)

Oh man, I wish I had hardware to test this on at the moment, I never realized there is an example in the example finder called Voltage (non-regeneration) - Continuous Output.vi.  Just search regeneration.  It shows a method to put continuous output on a wave, and allow adjusting the frequency and amplitude at runtime.  It does this by writing part of the waveform, then the next time it writes to the buffer, it shifts the wave by the phase, making the output continuous even if not a full cycle is put on the buffer.  Using this a hardware timed frequency, or duty cycle sweep should be possible without much effort, among other things of course.

0 Kudos
Message 10 of 10
(8,903 Views)