Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Can 1hz analog frequency output accuracy be achieved around 5Khz?

Goal #1 - I am trying to generate an analog frequency burst.  It is to be 5Vpp and burst 7 sine waves at 5KHz, then wait until the next 50mS and generate again.  The bursting frequency has been accomplished. 

 

Goal #2 - The next problem is that I need to be able to change the 5KHz burst output with 1Hz accuracy to verify a bandpass filter.  I am currently using a 6221 as a development card.  It appears the 6221 will accept 1Hz input changes but the output does not match the input.  (It seems to have 5Hz output resolution – I am running Continuous, 1 Cycle/Buffer, and 100 Samples/Buffer - gives good resolution to the signal.)  Can 1Hz increment/decrement (in the 5 KHz range) be achieved with any of the AO lines on any PCA like the 6221, 6224, 6722, 16XE etc.  I realize the Function Generator boards will accomplish my goal but I would need to purchase two PCAs since I need 6 AO lines and at that price I would prefer other optional test equipment.

 

Hello from New Hampshah 😉

 

Jeff Smiley Happy

0 Kudos
Message 1 of 8
(4,222 Views)

Hey Jeff,

The 6221 should be able to generate waveforms with 1Hz of frequency resolution - as long as you send it the correct waveform. It sounds like you are using on of the example programs, probably the "Cont Gen Voltage Wfm-Int Clk.vi". If you're looking for better frequency generation, I would try the Basic Function Generator.vi, specify a large sample rate, and calculate the number of samples required to generate the signal you want. You should be able to feed the results directly into the Timing and DAQmx Write vi's.

If you still don't see better results, how are you measuring the resulting frequency?

Thanks,

Andrew S

National Instruments

Message 2 of 8
(4,185 Views)

Andrew S.

I am glad to hear the 6221 should be able to meet my needs.  I did base my devlopment on the "Cont Gen Voltage Wfm-Int Clk.vi".  It is interesting to note that the "Basic Function Generator.vi" you recommend is actually in the "Cont Gen Voltage Wfm-Int Clk.vi" so I am not sure how to use it differently from the way it is used in the "Cont Gen Voltage Wfm-Int Clk.vi."  I am using two counting sources; A universal counter and I am wiring the 6221 frequency output to a 6221 input after I condition it properly (digital).  Both verify my concerns.

I have attached a screen shot of the fronts and blocks of the Vi's.  Note that when I input a Desired Frequency of 5001Hz the timing property node (sampleclk.rate) divides it back to 5000Hz (Resulting Frequency) based on the Resulting Sample Clock Rate.  This is the root of my problem since it is the Resulting Frequency that is input into the Basic Function Generator.Vi.  I tried to bypass the timing node but the freuency output did not change.  Any other thoughts and does anyone possibly know the dividing factor of the timing property node (sampleclk.rate)?

0 Kudos
Message 3 of 8
(4,179 Views)

Hi Jeff,

The Basic function generator is used in that vi, but the front end with your settings decreases the frequency resolution. I would take a little more of a low level approach. The current VI calculates the sample rate based on the inputs, finds the closest sample rate that is supported by the daq card (divided down from the 20MHz clock) and sets the generation frequency based off of that. If the calculated sample rate does not match up with what is supported by the card, then the frequency generated will not match up with what you want.

But if you specify the sample rate (for example 800k), the number of samples and the frequency you want generated, you will get the output you want. It sounds like you're looking for a finite generation, so you should not have to worry about phase continuity, but if you do I can post some code to maintain that. Take a look at the modified example I've attached and/or the pic:

Hope this helps, let me know if you have additional questions.

Andrew S  

Message Edited by stilly32 on 06-18-2007 02:58 PM

Message Edited by stilly32 on 06-18-2007 03:04 PM

Download All
Message 4 of 8
(4,172 Views)

Andrew S

Thanks so much for your quick response.  I thought for sure you had it nailed.  When I ran your edited application, even though the result frequency showed exactly what I wanted, when I observed the Universal counter and it showed me that only 4800hz was being output.  Looking at a scope revealed that after a few sine waves, the signal was being refreshed in the middle of a sine wave (end of samples?)  I tried recalculating the samples by dividing the clock rate/frequency desired.  This seems to be the answer but 5003hz does not divide nicely into 800000 (a base clock value I presume).  I even tried 833000 as a clock rate.  Since the amount of samples has a decimal portion, the output fluctuates +/- a few hz.  Can't get it to lock onto 5003hz even though the Resulting Frequency believes it is.  Anything else? (It appears it may work for finite samples but not for continuous.  I need both options.)

Message Edited by j.masse on 06-18-2007 01:03 PM

Message 5 of 8
(4,167 Views)

Hey Jeff,

If you are going to be running continuously, then you have a couple options.

You can run the Cont Gen Wfm Non Regeneration Example.vi - it automatically generates the waveform with phase continuity (no gaps/jumps). This will work out of the box but you may run into buffer underflows if your computer cannot keep up with your generation.

Or you could run the math and figure out how many samples you need to generate in order to ensure that the number of samples you generate at the specified sample rate corresponds to an integer number of periods or you signal. I've actually had to implement this before, so I've attached the code. It's not the prettiest and I'm sure there are other algorithms out there but from my testing it seems to work fine.

Note - LabVIEW has an LCM.vi but it only works for 32 bit integers. I found I needed 64 bits in most of my calculations so I just changed the type.

Also note that this card doesn't have an ultra stable clock (50ppm) but we should be able to get within a Hz. Let me know how this goes.

Andrew

Message 6 of 8
(4,156 Views)
Maybe part of the solution is to redefine the way you think about the problem?
 
It appears that one of your assumptions is that some integer number of discrete samples should span exactly 1 period of your sine wave.  However, you are also planning to generate multiple cycles of that sine wave.  Instead, you *could* choose to have a sine wave that spans, say, 102.75 sample intervals.  The discrete sample values for the 2nd sine wave cycle will be different than those for the 1st sine wave cycle, but in aggregate they'll represent the right sinusoidal frequency.  This kind of approach frees you pick an output sine wave frequency that doesn't have to be an integer divisor of the sample clock timebase.  This alone may be the best approach for your 7-cycle burst.  You'll just have to be willing to let the final sample be at the 6.993 cycle point or whatever -- something not quite exactly = to 7.0000
 
I got into a thread related to this kind of thing a long time back.  The context of that app was for continuous generation, and wanting the cleanest possible transition from end-of-buffer back to beginning-of-buffer while also supporting very precise sinusoid frequencies.  If you also need to support continuous generation, the utility posted at the end may prove useful for calculating the best fit automatically in your program. 
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 7 of 8
(4,152 Views)
Andrew S
Thanks for the Cont Gen Wfm Non Regeneration Example.vi.  It seems to be the answer.  Thanks for sticking with me through the problem. 
 
Kevin
thanks for your input.  Your link was helpful in explanation and I found some nice equations. 

Message Edited by j.masse on 06-19-2007 04:16 AM

Message 8 of 8
(4,137 Views)