12-22-2022 08:28 AM
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.
12-22-2022 09:10 AM
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,
12-22-2022 09:40 AM - edited 12-22-2022 10:06 AM
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 😉
12-22-2022 09:49 AM
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?
12-22-2022 10:09 AM
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
12-22-2022 10:42 AM
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
12-22-2022 10:55 AM - edited 12-22-2022 10:58 AM
for the 9kHz case it's simply 3 periodes and 32 sample in regen mode...
here
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
12-22-2022 10:13 PM
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).
12-23-2022 04:11 AM
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
12-23-2022 12:23 PM
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