10-23-2012 03:05 PM
Thanks a lot, Chris!
Try to implement your version with the script.
I'm Sorry for molestation, could you say, what is the reason of not working it.
And more.
I tried this variant:
Configure a set of arbitrary waveform, from minimum to a maximum value with a given precision (step phase), for example.
And further, on the fly switch on the necessary signal.
But even on the configuration from 0 to 1 degrees in increments of 0.001 degrees (only 1000 arbitrary waveform) takes more than 30 - 40 seconds,
and with a larger range (0 - 2 degrees) there is an error, that the memory is full.
In general, preferably to have a range of:
Phase 0 - 360 degrees with accuracy 0.1;
Amplitude 2,5 - 3,5 volt with accuracy 0.01 and
Frequency 49 - 51 hertz with accuracy 0.1 too.
i.e. 7.200.000 arbitrary waveform.
Is there any way to change or simplify (generally optimize performance) shown below the program for the implementation of this option?
Or is it too much data for 5422?
Regards, Max.
Engineer and software developer,
TeSLa.
10-24-2012 08:04 AM
Hello Chris,
I slightly modified the sample code Fgen Switch Between Waveforms, and now the amplitude and phase change with the required parameters.
But I need to also change and the frequency on the fly, infantry would be range 49 - 51 Hz in steps of 0.1.
There is a problem with the frequency.
We can control the frequency, setting the Waveform Size in niFgen Allocate Named Waveform VI
But the least value, that can be achieved - is 97 Hz at 2.055.552 samples. And then, again occurs Error, that the memory is full.
May be there are other ways?
Regards, Max.
Engineer and software developer,
TeSLa.
10-24-2012
10:33 AM
- last edited on
02-18-2025
12:29 PM
by
Content Cleaner
Hi Max,
Your resolution with respect to frequency, phase, and amplitude are a function of sample rate (200 MS/s), vertical resolution (16 bits -> 2^16 = 65,536 vertical values), and range (adjustable from +/-2.82 mV to +/-6 V). There are also various memory size options for the 5422 (8, 32, 256, and 512 MB) that affect what size waveforms we can load onto the device; which one do you have?
In regards to the out of memory error you were receiving, given an onboard memory size of m at 16 bits/sample = 2 bytes/sample, you effectively can load up to m / (2 bytes/sample) = m / 2 samples on the board. Since you are using scripting to toggle between two waveforms on the fly, each of the two waveforms can be no more than m / 4 samples in size, assuming they are each the same size.
At a constant sample rate, a single cycle of a waveform at a given frequency will indeed have a characteristic number of sample points; changing that frequency will increase or decrease the period, effectively changing the number of samples required to produce the waveform. Given a sampling rate of 200 MS/s, a frequency of 50 Hz will have a period of 20 ms, which would contain 4,000,000 samples. To store two of these waveforms, you would need at least the 32 MB (15.26 MB required) version of the 5422. I would venture to guess that your board is the 8 MB version, which is why you can only do frequencies of 97 Hz (period of 10.31 ms -> 2,061,800 samples per waveform, or 7.87 MB for two waveforms).
You could lower your device's sampling rate as low as 5 MS/s, decreasing the number of samples required to produce a complete cycle of your waveform. Keep in mind, however, that the time between successive samples has a direct correlation with your frequency resolution, r, at a given frequency, f; let s be defined as sampling rate (inverse of sampling period):
Samples per cycle: s / f
Next available frequency (add one sample and convert back to frequency): s / ( s / f + 1 )
More generally: fn = s / (s / f0 + n)
For example, let s = 5 MS/s and f0 = 51 Hz: f1 = 5 MS/s / (5 MS/s / 51 Hz + 1) = 50.9995 Hz, theoretically
I would recommend setting your sampling rate starting at 5 MS/s in order to accommodate your board's memory and given the low frequencies you are working with. I would also recommend you take a look at the board's specifications (here) to make sure the clock stability and accuracy will be sufficient for your application since you are making such small incremental changes. For example, the clock stability on page 18 is listed as +/-25 ppm, which translates to +/-25 ppm of the period of your requested frequency (error compounds on each onboard clock cycle, propagating the 25 ppm error). At 51 Hz, for example, your waveform period is 1 / 51 Hz = 19.61 ms. The error on this period is +/-25 ppm * 19.61 ms = 0.490 us. Adding this error to your period yields in a frequency ranging from 51.0013 Hz to 50.9987 Hz, which should be inside your step range.
In addition, as you decrease your sampling rate, your ability to shift phase will be affected as well. The minimum phase shift available will always be the time between successive samples (1 / 5 MSs = 0.200 us). In this case, at 51 Hz, shifting by 0.200 us in a 1 / 51 Hz = 19.61 ms period effectively changes the phase by 0.200 us / 19.61 ms = 0.00102% = 0.00367 degrees, which should be within the bounds of your requirements.
Increasing the sampling rate from 5 MS/s to something higher could give you better phase and frequency resolution. You may try using an external clock source if you need better stability, such as the PXIe-6672 (25 times better clock at +/-1 ppm vs +/-25 ppm), but this card as it is should be able to make the incremental changes you are requesting if you lower your sampling rate. Just make sure that the accuracy/stability is also within your specifications.
Regards,
10-24-2012 12:18 PM
Thanks Chris.
In all of these data and characteristics need to understand.
It seems that you are right. And our module has 8 MB of memory. Because in overflow error there is a message with
Total Davice Memory: 8388608
Pease, can you show or write a simple program with the possibility to change the frequency for an example with the script. Or for to change the frequency in an Arbitrary Waveform mode, we can use the Property Node (Frequency)?
Regards, Max.
Engineer and software developer,
TeSLa.
10-24-2012 02:02 PM
You cannot change the Sample Rate of a 5422 "on-the-fly" (meaning, while the generator is running, without aborting and initiating again). What you are attempting to do is emulate function generator functionality using arbitrary waveform functionality. This is tricky to do because you cannot really change the size of an arbitrary waveform once it has been allocated and you are running. So, depending on which specific frequencies you need, it might be possible to get something that works reasonably well for your use case.
Could you describe from the beginning what you want to do? Which specific frequencies, phases, you need to generate? How you want to switch among them?
10-24-2012 02:06 PM
Hi Max,
I would recommend using either niFgen Util Create Waveform Data.vi or niFgen Util Create Frequency Sweep Data.vi:
The first VI will make a single cycle of the waveform you request. Setting the number of points in the Waveform cluster as a function of your sampling rate to get your desired frequency (e.g. 50 Hz at 5 MS/s requires the number of points to be 5 MS/s / 50 MHz = 100,000 sample points) will be more efficient for generating your data points than the VI you are currently using.
The second VI will actually use a single waveform to perform the frequency sweep you request. Beware here that the memory on your card will limit the kind of frequency sweeps you can do in a single shot.
You can wire controls from your Front Panel into either of these VIs and, as long as your controls are read inside your main loop, this will let you make changes to your waveforms on the fly.
Regards,
10-24-2012 02:16 PM
Thanks, Marcos. I was not trying to imply we change the sampling rate on the fly, but rather tune the sampling rate, prior to generation, to an optimal rate that maximized the board's memory while not sacrificing frequency/phase resolution too much. The board's memory will be the limiting factor here ultimately for sweeping several frequencies. And I completely agree, a function generator is much better suited here.
10-25-2012 04:58 AM
Hi Marcos and Chris,
All I need is when the application starts - to generate two synchronized Sinewave, one of them with changeable on the fly parameters. I.e. during signal generation. Don't with software restart.
As I wrote above, preferably to have a:
Phase in range of 0 - 360 degrees with step 0.1 deg,
Amplitude in range of 2,5 - 3,5 V with step 0.01 V and
Frequency in range of 49 - 51 Hz with step 0.1 Hz too.
Requires that all of these characteristics should be changed on the fly!
Using the example Fgen 5404 Synchronization.vi can change the amplitude and frequency, but not the phase. Using the example Fgen Switch Between Waveforms.vi can change the amplitude and phase, but not the frequency. And they work in different modes.
The first works in the Standard Function mode, and the second in Script mode.
As you rightly pointed out:
You cannot change the Sample Rate of a 5422 "on-the-fly" (meaning, while the generator is running, without aborting and initiating again).
And if configure an array of Waveform (with different Sample Rate) in the range of 49 to 51 Hz in steps of 0.1 (i.e. 20 waves) with help the niFgen Allocate Named Waveform VI, and during signal generation process to switch between them.
Can you prompt the solution?
Regards, Max.
Engineer and software developer,
TeSLa.
10-25-2012
08:18 AM
- last edited on
02-18-2025
12:29 PM
by
Content Cleaner
Hi Max,
Did you try the two VIs I suggested in post # 16? The first VI will let you set frequency and amplitube in the VI's input. You can then shift phase by rotating the outputted array as I mentioned in post # 10. Have you tried implementing a rotation on the array going into your niFgen Write Named Waveform (DBL).vi? All the information we have here in the thread should accomplish what you are trying to do. I am still working on a polished Community Example for the on-the-fly phase shifting as I previously mentioned (expect this out by end of day Friday), but you'll need to implement your other on-the-fly features as they pertain to your application. Unfortunately, NI does not officially provide complete, custom coding solutions for our customers. If you are looking for a service like that, I would recommend getting in touch with one of our Alliance Partners.
Regards,
10-25-2012 10:59 AM
Using the example Fgen 5404 Synchronization.vi can change the amplitude and frequency, but not the phase. Using the example Fgen Switch Between Waveforms.vi can change the amplitude and phase, but not the frequency. And they work in different modes.
Watch out: Function Generator Mode on an arbitrary waveform generator such as the 5422 is simulated by the driver, because the hardware cannot do things such as change the frequency of a waveform seamlessly. What this means is that you can change the frequency "on-the-fly", but in reality the driver needs to stop generation, create new waveforms, possibly change the Sample Rate, restart the generation. The effect of this is that there will be a discontinuity when you change frequency. If you had a true function generator (5402, 5406) then changes in frequency or phase are continuous. This also applies to devices with Onboard Signal Processing, such as 5441, 5442 because we use the Onboard Signal Processing block to do Function Generation.
In your case, since you are trying to use an Arbitrary Waveform Generator as a Function Generator, you can accomplish this:
Phase: You can change phase of the waveform being generated by allocating two waveforms in device memory, creating a script that switches between them. When you want to switch, you can replace the data in the waveform not being generated with data that has the desired phase. Then you switch between them through a hardware or software trigger. This will be glitchless.
Amplitude: You can use the analog hardware for amplitude control by using the Gain property. This could glitch if the change in gain makes you change hardware amplifiers. This would be the case in a Function Generator too. Alternatively, you can use the Digital Gain property which gives you glitchless amplitude control at the expense of some dynamic range.
Frequency: This is very hard to accomplish on an Arbitrary Waveform Generator. You may be able to come up with fixed buffer sizes that contain an integer number of periods of sine waves at the different frequencies you need. You can then replace the proper allocated waveform with new data as long as the total number of samples is the same and switch to it. If you can accomplish this (you need to sit down and do the math) then you will be good to go.
I hope I was able to explain myself