Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize two analog output waveforms with different frequencies?

Hi,

 

I am trying to use my NI-6115 board to simultanesouly output two analog waveforms using AO 1 and AO 0.  My first problem is, how do I do that since I was under the impression that you would only need one tasks for the same type of output?  However I realized that I must set the output port when I initialize the voltage output channel using 

 

DAQmxCreateAOVoltageChan

 

Therefore I ended up creating two channels, one for each analog output.  I figured that I must also configure a separate sample clock for each channel using

 

DAQmxCfgSampClkTiming

 

The source of the clock for both channels will be the internal output of counter 0 since I am using that counter to divide the tick counts from the 20Mhz master clockbase.  Then to configure the the function for the actual analog output, I called the write analog function twice, one for each task.

 

 DAQmxWriteAnalogF64

 

So from my understanding, in theory this should create two equal output analog waveforms with the same frequency, right?

 

However DAQmx returns error -50103 stating that the specified resource is reserved.  The function that triggered this error is the  DAQmxWriteAnalogF64 function for the second analog output channel.  Is there some hardware limitation I am not aware of?

 

 

Second problem I have is, after I implement the above program, I would like the second channel to have a different output frequency than the first channel.  The two channels would have to be synchronized.  IE. Channel 2 would generate a point for every 4 points generated by channel 1.

 

Thank you

 

Howard

0 Kudos
Message 1 of 9
(8,820 Views)

An update to my problem.  Apparently I misunderstood the concept behind channels and tasks in DAQmx.  With the same type of output I could really just have grouped the two channels under the same task.  All I had to do was to call the DAQmxCreateAIVoltageChan twice and specifiy the two different output terminals for the two channels.  Both of which will be regulated under the same sample clock.

 

After that I called the DAQmxWriteAnalogF64 function once, specifying the "dataLayout" parameter to DAQmx_Val_GroupByScanNumber, which should output the sample array interleavingly.

 

The program now outputs two identical waveforms synchronized by the same sample clock.

 

However the second problem remains.  What happens when I want to vary the frequency of the second channel?  A simple and obvious solution would be to write and equal number of samples for both channels and just change the value of the sample for the second channel according to the frequency.  However this would result in a gigantic array if I have to add more channels later on.

 

Is there any way around this?

 

Thank you

 

Howard

0 Kudos
Message 2 of 9
(8,809 Views)

Hello Howard,

 

I did a lot of searching and tinkering to see if there was a better way of doing this, however it appears there is not.  You will just want to make sure that the waveforms you are outputting have the same number of total points, and just vary the number of points you output per cycle. 

ColeR
Field Engineer
Message 3 of 9
(8,788 Views)

ColeR,

 

Thanks for the work you put in.  So from my understanding, say if I wanted to output 1 point in Channel B for every 5 points in Channel A, I would need 5 points in the array for Channel A and 5 points in the array for Channel B interleavingly, totalling to 10 points in the array just for that 1 cycle, is that correct?

 

I could live with having a gigantic array for just two analog output channels as long as the board could handle it.  However for my project I would definitely need a third analog output channel.  The NI-6115 board I am using only supports 2 simultaneous analog output waveforms, so I would have to buy another board anyways.  Would the new board enable me to time the third channel using a different sample clock?  Or would I run into the same problem again?  Is there a DAQ board NI produces that doesn't time all of it's analog output channel using the same sample clock?

 

Thanks again

 

Howard

0 Kudos
Message 4 of 9
(8,781 Views)

Hello Howard,

 

If you want Channel A to be 5 times the frequency of Channel B, Channel A will need to go through 5 cycles in the time that Channel B completes one.  I'm fairly sure this is exactly what you described, but I just wanted to make sure. 

 

Using your new board, you will be able to use the time clock on that to output a completely different waveform.  You can then just synchronize the start of the two tasks to synchronize the outputs of your waveforms.  

 

And unfortunately, right now each of our DAQ cards only has one clock to use for AO.  

ColeR
Field Engineer
Message 5 of 9
(8,767 Views)

ColeR,

 

Yes the idea is basically what you said with the Channel A and Channel B, except the frequency of Channel B would need to be a lot lower than Channel A in reality which is why I was a bit concerned with the size of the array needed to perform this.  I need one cycle of Channel B per every ~500-600 cycles of Channel A.

 

Would I need a trigger to synchronize the output of my waveforms?  Or is it sufficient to just call the DAQmxStartTask for the two tasks next to each other?

 

Lastly, my project is actually data acquisition for an imaging device.  which is why I needed a Channel A to drive the x-axis of a scanner, a Channel B to drive the y-axis and a Channel C to drive the z-axis.

 

Would you happen to know if there are any boards NI offers that is more tailored for my project?

 

Thanks again

 

Howard

0 Kudos
Message 6 of 9
(8,765 Views)

Howard,

 

You will actually want to bundle both of these into the same task as each task will need to reference a clock and we only have one.  By creating both of these channels on the same task, we will ensure that they both start at the same time.  

 

For your project, it sounds like you could use a motion control board. Talking with some people around here, it looks like any of the 73xx series will work for you.  Looking around our site, it looks like the 7344 is a good mid range device.  It offers 4 axis of controll and should help you to gain good controll of your imaging device.

ColeR
Field Engineer
Message 7 of 9
(8,748 Views)

ColeR,

 

Sorry I should clarify, I was referring the third channel assumming it's coming from a second board.  From my understanding, Channel A and Channel B would be coming from the first board controlled by the same sample clock in the same task while Channel  C could be controlled by a second sample clock on the second board, which means I would have to put Channel C under another task, is that correct?  If that is the case would I need a start trigger or would putting the DAQmxStartTask next to each other be sufficient to synchronize all three channels?

 

I have looked into the NI-7344 board briefly and noticed that the programming API for that board is NI-MotionDriver, would that mean none of the functions under NI-DAQ would work with that board?  Because if that's the case I would have to rewrite parts of my program.

 

Thank you very much for your timely replies, really appreciate the help

 

Howard

Message Edited by HT156 on 07-02-2009 04:55 PM
0 Kudos
Message 8 of 9
(8,735 Views)

Hi,ColeTrain

I want to output two voltage waveform with different frequencies and different amplitude .I have realized with different amplitude. I can understand your idea,but  how to realize it in my program?

Looking forward  to your letters.

Thank  you 

0 Kudos
Message 9 of 9
(3,920 Views)