LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get a 9 kHz output out of a NI USB 4431 DAQ?

Hi,

 

I am trying to use my NI USB-4431 to get a 9 kHz sinusoid out of the output port.

 

The USB 4431 has 5 ports, 4 input ports and 1 output port. 

 

I would like to use the 1 output port to generate a 9 kHz sinusoid which is going to be fed into one of the inputs, and also into another input via a resistor which will also be connected to a system I am testing.

 

We therefore need a 9 kHz sinusoid out of the output port. I have a block diagram with a DAQ assistant configured with

 

1. Generate Signals -> 2. Analog Output -> 3. Voltage -> 4. Select AO0 physical channel.

 

From there, I can change the 'samples to write' by selecting Generation mode as 'continuous samples', and I can change the rate via selecting Generation mode as '1 Sample (HW Timed)' - when I have generation mode set to continuous samples, the Rate (hz) is greyed out for some reason?

 

Changing the samples to write and Rate (Hz) changes the output frequency of the output port but it is very hard to accurately get 9 kHz.

 

For example there are only a few Rate (Hz) you can set it to, which are a multiple of 9. For example 1.5 kHz is a multiple of 9. However, no amount of 'samples to write' will get it to output 9 kHz.

 

Is there any other way of using the output port or is it impossible to output 9 kHz sinusoid? Thank you

 

I have attached a picture of the menu screen. The closest I can get is setting the Rate to 96k, and samples to 11. This gets the output measured via an oscilloscope to read 8.7 kHz but still not 9 kHz.

 

 

0 Kudos
Message 1 of 10
(2,000 Views)

Of course, you can generate a 9kHz sine wave using 4431.

 

I would recommend moving away from DAQ Assistant and using DAQmx drivers instead. This is a good article, skip the DAQ Assistant part - https://www.ni.com/en-us/support/documentation/supplemental/06/learn-10-functions-in-ni-daqmx-and-ha...

 

Tips on DAQ settings,

 

  1. Choose a sampling rate that is an integer multiple of the generated waveform (you have covered this) - you need at least an 18kHz sampling rate (Nyquist theorem)
  2. Use Finite samples and let them regenerate, choose an integer multiple that will result in a complete cycle of the sine wave. For example, you need 10 samples so that each cycle can be defined with 10 cycles when generated at 90kHz sampling rate and results in a 9kHz sine signal
  3. The reason for 8.7kHz instead of 9kHz is because 11 samples per cycle at 96kHz = 8.727kHz (96/11)
    1. Exact 9kHz at 96kHz sampling rate is not possible as both are not integer multiple, you can only be approximate

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 10
(1,987 Views)

I usually have the generator in a seperate loop and continously feed it in blocks with the signal I want.

So no matter what actual samplerate is used (but known! read the the actual SR property after setting the SR) some 10k Samples of a sine are easely calculated with a continous phase. 

As long as you are .4 below  the SR no problem. Your PC will easely calc the new points while the previous block is feed into the DAC... It's 2022 (not for very much long), enough calculation power under the desk 😄

 

Another aproach would be to feed more that one periode for a repeated generation at a certain SR. If you provide a block of samples of 1s length (only about 96kS max;) )  , you have a resolution of 1Hz for generation.  Or search for the least common multiple ..

 

 

And if you have the sound and vibration addon installed, have a look at shipped examples 😉

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 3 of 10
(1,972 Views)

Hi. 

 

Thanks for the reply.

 

The problem I can see is that with the USB 4431, it gives an error showing what frequencies can be used in the 'Rate (Hz)' box.

 

For example, 90 kHz is not one of the frequencies you can put into the Rate (Hz) box. I have attached a photo of the error showing the possible ones allowed.

 

From what I can see, none of the allowed frequencies are a multiple of 9. Multiples of 9 are 18, 27, 36, 45 etc. none of these are allowed?

0 Kudos
Message 4 of 10
(1,965 Views)

Check out the shipping example for non-regenerating continuous analog output.  There you'll see how to use regular DAQmx functions to generate your signal (as santhosh suggested) and repeatedly re-calculating the next block of samples needed to extend your 9 kHz sine wave smoothly.   (Or at least as smooth as you can get it with a max sample rate of only ~101 kHz.  The rule of thumb I learned is you'd want sample rate to be at least 20x the sine wave frequency for a "pretty smooth" digitization.  10x can be adequate if you're stuck with it -- and that's pretty much where you are.)

 

 

-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.
0 Kudos
Message 5 of 10
(1,950 Views)

Thank you for your help.

 

I can't seem to find an example called "non-regenerating continuous analog output" however I will look through examples to try and find the correct answer or VI. It seems to be harder than I thought but if its possible as you say then I will read the resources a bit more that santhosh linked and try to understand how to generate the output. Thanks

0 Kudos
Message 6 of 10
(1,934 Views)

for the 9kHz case it's simply 3 periodes and 32 sample in regen mode...

here find some matching periodes Q&D.png

 

the vi migth be a candidate for the rube channel 😉    

no elegand math .. simple trying

 

However the non regen mode can do any frequency ... below 0.4.. the samplerate

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


Message 7 of 10
(1,925 Views)

I would download the Dynamic Signal Generator (DSG) Soft Front Panel (SFP) from here:
https://www.ni.com/en-us/support/downloads/drivers/download.dsa-soft-front-panels.html#376770

This SFP is free to use and requires no programming.

If you really want to figure out analog output of an arbitrary-frequency sinusoid using the DAQmx driver, I strongly recommend starting with the non-regeneration example: <LabVIEW>\examples\DAQmx\Analog Output\Voltage (non-regeneration) - Continuous Output.vi

Either of the above solutions keeps the desired output frequency decoupled from the sample clock rate. I don't think you want to recalculate an optimal number of periods if you have to change your output frequency in the future (especially, if you are also using the analog input channels and want to be able to independently select the ai sample clock rate).

Doug
Enthusiast for LabVIEW, DAQmx, and Sound and Vibration
Message 8 of 10
(1,893 Views)

Hi dsb@NI,

 

I am using Labview 8.5 so I am not sure if it works with that? I installed the program as you mentioned but I can't see anything in labview related to it but maybe I dont know where to look?

 

Regardless I have found an example in labview titled 'Cont Gen Voltage Wfm-Int Clk-Non Regeneration.vi' 

 

This was located in C:\Program Files (x86)\National Instruments\LabVIEW 8.5\examples\DAQmx\Analog Out\Generate Voltage.llb

 

The LLB seems to be a way of navigating examples so when I opened that application there was one titled 'non regeneration' in there which I used and it seems to be generating sinusoids to a very accurate degree of frequency so thank you all for your help ! I should probably learn how to do it myself however instead of relying on examples but this is perfect for now so thank you

Message 9 of 10
(1,879 Views)

There should be an easier way to navigate the examples.  For quite a lot of years now you just use the LabVIEW window menu item "Help->Find Examples..." to get started.  If you don't find it there, poke around the menus a bit -- it'll be *somewhere*.

 

A lot of the examples make a good starting point that you can both rely on and learn from.  A good practice for learning is to save a copy of an example program at a file path of your own choosing, and then experiment, edit, and tinker from there.  If you break things too badly, you can always bring up the original unmodified example to start over.

 

 

-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 10 of 10
(1,844 Views)