03-02-2011 09:55 AM
Hi all,
I'm trying to generate a set of sine waves of amplitude 10V and frequency 50Hz with a phase difference of 120 deg each (0,120,240 for R, Y, B respectively). For doing this, I'm utilizing 3 channels from my analog output card (PXI-6723). In this way, I have a matrix of 10 x 3 = 30 channels.
Now, when I'm trying to write the first set of 3 channels, I'm able to generate a proper output. The settings are as follows: amplitude: 10V, Frequency: 50.2 Hz and Phase difference of 120 deg for 3 channels. But as soon as I configure the second set with the following settings: A = 10V, Freq: 50.6 Hz and Phase difference of 120 deg, the frequency of the first set of channels starts flickering. That is, instead of 50.2 Hz, it flickers between 49.90 Hz to 52.10 Hz. The frequency of the second set of channels also flickers between 50.00 Hz to 52.40 Hz.
On the contrary if I keep the frequency setting of the first set as 50 (whole number) and second set as 51, the flickering is not observed.
I suspect this to be a software problem because, the flickering is visible on the graphs of my GUI also.
Please find attached the VI that we are using for our experiments. I hope you can throw some light in fine tuning/ changing the VI so as get a better and consistent values in the output.
Thanks.
Sreedhar
03-02-2011 11:33 AM
The problem is that your sampling rate defines which sinusoids can be effectively simulated. Your vi has a sampling rate of 10 kHz, which is a dt of 100 us. For a 50 Hz sinusoid that means that one cycle of the sinusoid will take 200 time steps. For a 50.2 Hz sinusoid, one cycle will take 199.2031872... time steps. Since this number is not an integer, it cannot be precisely simulated. The closest that can be simulated precisely for a 10 kHz sampling rate would be for 199 time steps which is 50.251256814... Hz. (10000/199 = 50.251256814)
03-02-2011 11:10 PM
Hi,
Thanks for your kind reply. But one thing that I am unable to understand is why the first set of values flickering on changing the values of the second set?
As per the VI I have attached, if the frequency of the first set is given as 50.2 and the frequency of second is say 50.0, then there is no flickering problem. But as soon as I change the frequency of second set to say 50.7, the frequency of the first set will start flickering by almost +/- 0.5 Hz.
Also i forgot to mention that I'm doing these measurements on a Fluke DMM. I have also tried using a tektronix scope but the results are similar.
Would you also suggest a better way of performance tuning (i.e. setting Sampling Rate and Frequency).
Many Thanks.
Sreedhar.
03-03-2011 11:57 AM - edited 03-03-2011 12:00 PM
You have to manually control the phase each time through the loop to avoid discontinuities. Plus, I don't think you can adjust the frequency while it is running, it might screw up the phase relationships. Restart it when you want the change the frequency. See attached.
03-09-2011 04:17 AM
Hi Randall,
Thank you very much for the VI you have shared with us. It has really helped us to fine tune the application to a great extent. There are still deviations of upto +/-0.3 Hz as generated from the card. Just so that I do not miss my point, I'm using a custom made cable assy with the other side open ended (not using the conventional NI cable and TB). Hope that is not the factor for deviation. If yes, what could be hardware that I can use externally to minimize these deviations... would something like LPF (low pass filter) work ?
@rpursley8 wrote:
You have to manually control the phase each time through the loop to avoid discontinuities. Plus, I don't think you can adjust the frequency while it is running, it might screw up the phase relationships.
Still it is unclear to me why this thing should be done. In the application that Im working on, the field gives me a command to generate a certain frequency and I need to change the frequency dynamically on the run-time.
Secondly, the only variation that we did with your code was to use DAQmx VIs instead of express VIs. We are still trying to improve that VI. I will share with you once we optimize it so that you can also have a look at it and let us know further improvements.
Thanks a lot anyways.
Regards
Sreedhar.
03-09-2011 11:44 AM - edited 03-09-2011 11:48 AM
OK, here is a quick example. I wrote a program that puts the function generator into a for loop which runs for two iterations. In the first figure I generate two 1 Hz waveforms at two different starting phases. Everything looks great because at a sampling frequency of 1 kHz, a 1 Hz signal takes 1000 points to go through a single cycle.
Now for the second example, I keep the phase the same but change one of the waveforms to 1.2 Hz. In this case one cycle of 1.2 Hz takes fewer than 1000 points so a second cycle begins. As you see, this generates a discontinuity in this waveform because the second time through the loop, the phase begins at zero again.
For the third example I added the feedback in so the phase represented by the last point in the 1.2 Hz waveform is remembered and fed into the function generator the next time through the loop as the new starting phase. This prevents the discontinuity and maintains a continuous waveform.
In your original vi you posted, each time through the loop you were creating these discontinuities which would affect your frequency readings. Hope this helps you understand what is going on.