Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating 4 analog output waveforms with different frequencies

Solved!
Go to solution

Don't hijack a completely unrelated thread.

 

Edit - the question was already asked and answered!

Message Edited by Dennis Knutson on 03-19-2010 08:46 AM
0 Kudos
Message 51 of 65
(1,630 Views)
 

Hello John,

                       I have a trouble in generating correct frequencies of waveforms. If you run the vi  Cont Gen Dig Wfm in Sync with Analog Wfm ver 5.0.vi (92 KB) to generate a sqaure waveform of 12.5Hz and digital waveform of 25Hz with 0.01duty cycle and two analog sine waveforms of same frequency say 434Hz or 844Hz or 5594Hz or 7594Hz.

 

I can see the analog saqure waveform of 12.5Hz and digital waveform of 25Hz are generated correctly. Where as the two sine waveforms are generated with correct frequency but there are some dicsontinuities in the waveform (may be jumps shown in the attached image). 

 

The sine waveforms are behaving in the same way at other frequencies as well at 844Hz 5594Hz etc...

 

I have fixed sampling rate at 250000. Number of samples at 20000. 

 

How can i generate correct waveforms???  Seems like some relationship exists between sampling frequency, no.of samples and frequency of waveform to generate correct waveforms???

 

I guess using array of waveforms i have not had this problem.

 

Thank you.


0 Kudos
Message 52 of 65
(1,612 Views)

Hi viswa,

 

In the example I posted I used a shift register to keep track of phase (to allow you to adjust the relative phases of the different waveforms).  It looks like you have taken this out of your current code.

 

Regarding the other example that you linked to, it only writes the data once (and then regenerates the data) so the number of samples must be a complete period of the waveform.  My examples here use non-regeneration and continuously write data while keeping track of the cumulative phase.  This can be done in two ways (demonstrated in the two versions of the code posted on the community site):

1.  Allow the Basic Function Generator function to keep track of phase for you--to do this you would have to not reset the waveform and thus would not be able to adjust the relative phase of the waveforms on-the-fly.  This is how Cont Gen Wfm Non Regeneration Mult Channel.vi works.

 

2.  Use a shift register to keep track of the phase yourself.  This way you can reset the phase every time and adjust it however you want to on-the-fly.  The other example, Cont Gen Wfm Non-Regeneration Multi-Channel Update Phase.vi, uses this method.

 

In your version of the code (v5) that you most recently posted, you have taken out the shift register which keeps track of phase but are also continuously resetting the Basic Function Generator.  This is why you are seeing the discontinuities.  Either of the two methods above will correct the problem, depending on whether or not you need to adjust the phase on-the-fly.  If you need help implementing this, could you post the most recent version of the code you were working with before you modified it to separate the different channels?

 

 

Best Regards,

John Passiak
0 Kudos
Message 53 of 65
(1,598 Views)

Hi John,

               Thanks for your suggestions. I have implemented option 2 to change phase on-the-fly. It seems like working well. 

 

I have a query about sampling clock rate.

 

Suppose if i want to generate square waveform of 12.5Hz and sine waveforms with same frequency 4656Hz and 25Hz digital waveform, how can i choose sampling rate correctly???

 

When i choose 250000 samples/sec or 125000 Samples/sec with No.of samples 20000, i can see all of the waveforms generate correctly.

 

But when i change sampling rate to 400000 samples/sec with 20000 samples then some parts of the sqaure waveform are stretched i mean it does not show 50% duty cycle any more.Why this happens??

 

I have attached the latest vi (V6)

 

Thank you very much.

 

0 Kudos
Message 54 of 65
(1,580 Views)

Hi Viswa,

 

Are you going off of the display of the waveform graph on the front panel or are you actually measuring the output signal?

 

The display is showing what you are generating for any given loop iteration.  It won't necessarily show a complete period of the digital waveform so you can't really use it to tell the duty cycle. 

At 125k Samples/sec and no. samples 20000, you will be generating 160 ms of data per loop iteration (20000/125000).  The period of a 12.5 Hz waveform is 80 ms, so you should see two full periods on the digital display in this case.

 

At 250k Samples/sec and no. samples 20000, you will be generating 80 ms of data per loop (20000/250000).  You should see a single period of the 12.5 Hz waveform on your digital display.

 

At 400k Samples/sec and no. samples 20000, you will be generating 50 ms of data per loop (20000/400000).  This would give 5/8 of a period of your waveform each loop.  Note that on the next loop iteration, the phase should pick up where it left off so the end result should still be outputting the correct frequency.

 

I suspect if you measure the output signal the result should be a consistent frequency output regardless of your sample rate, although there will be jitter of up to 1 sample clock period if your desired frequency does not go evenly into your sample rate (not a problem in any of the above 3 cases).

 

 

Best Regards,

John Passiak
Message 55 of 65
(1,575 Views)

Hi John,

                       Thank you very much for your help all the way. It really helped me to learn fundamental concepts as well as using them. After implementing shift register for phase tracking the vi is working irrespective of sampling rate value. 

 

Actually i measure all the generted waveforms using oscilloscopes to make sure generation is correct and to keep track of things in my experiment. It was real problem when i was using vi which has not had the shift register for phase tracking. 

 

You definitely deserve ackowledgement in my thesis!!!!

 

Best regards

Viswanath

 

0 Kudos
Message 56 of 65
(1,573 Views)

I am trying to do a similar thing (generate different analog outputs with varying frequencies) programitacally using the DAQmx library from C code. No labview involved.  Are there any examples of this? I have not come across them. 

0 Kudos
Message 57 of 65
(1,112 Views)

There are a few Analog Output C examples shipped with the driver (see here).  These examples all write an output buffer and regenerate the same data repeatedly.  The two disadvantages of this are:

 

1.  You must be careful to write an integer number of periods of your waveform(s) to the buffer or you will see discontinuities (this can get really tricky if not impossible if using multiple channels at different frequencies).

 

2.  Changing the output waveform while it is running can give discontinuities in the output (old vs. new data being generated vs. the position in the buffer that the hardware is reading from).

 

 

You can configure the hardware to not regenerate from the output buffer.  This solves the two problems above, but the downside is that you have to continuously write new output data to the buffer.  I wrote a LabVIEW example that does this for multiple channels here, but I'm not aware of an equivalent ANSI C example (it seems there should be some example showing non-regeneration in ANSI C, but I'm not sure where to find it).  LabVIEW has a pretty nice function generator method that keeps track of the phase of a signal between calls, but other than that the actual DAQmx API calls should be pretty easy to transfer over to ANSI C (e.g. the RegenMode property node becomes DAQmxSetWriteRegenMode).

 

Best Regards,

John Passiak
0 Kudos
Message 58 of 65
(1,100 Views)

Hello!

I met the similiar problem. I am trying to generate two different sawtooth wave in different frequencies by using non-regeneration, but it turned out that I was not able to select the phyical channels as like" Dev1/ao0:1. There are only two options: either Dev1/ao0 or Dev1/ao1. I wonder how I use two channels simultaneasly?

 

Thanks,

Chenyu

0 Kudos
Message 59 of 65
(1,059 Views)
How are you selecting the channels? What language? With LabVIEW, you simply click on browse to select multiple channels. You can also type the multiple channels into the control.
0 Kudos
Message 60 of 65
(1,054 Views)