04-26-2010 06:21 PM
Hi tau at wayne,
Thank you for getting in contact with the forum community. It seems like everyone here has provided many useful suggestions but maybe I will be able to contribute some information also. The basic function generator does not have a recollection of the previous entries. What it does is takes the input values (signal type, sampling information, frequency, duty cycle, amplitude, phase, etc.) and generates a finite waveform. Additional executions will produce identical waveforms if the inputs remain the same. With a phase of 0, a square wave starts at a high and goes low. I noticed that you have not supplied any sampling info. I would set this up so you complete a finite number of periods in each generated waveform. With the default sampling info and a frequency of .0001 Hz, the function will generate all ones every time it executes.
If you want to continuously generate and update the data streams for each (i.e. have it remember what was last generated) you will have to compensate each channel with some phasic correction. Each time the VI runs for a given channel you will need to figure out what the phase of the next generation would have to be for the next iteration and store it. This will probably be a little tricky to write, but is very doable. I think the confusion here might be stemming from an assumption that the phase of the generation is handled by default, which it is not. The SubVI you posted looks at the first entry in all these arrays, which, while phase is zero, will always be 1. tbob has a good explanation of this above.
Hopefully this helps, please post further questions if this is confusing. Hopefully we can get you going!
04-26-2010 08:21 PM
Thanks tbob ,
thanks Verne.
Both you guys hit the problem head on and gave made me understand what I was trying to explain even better.
One more question,
how can I keep track of the phase? I had the suspion that I need to keep track of that, but wasnt sure. Now that I am I dont know how to do it? Could someone give any tips on how to use the phase to my advantage?
Thanks
04-27-2010 10:38 AM
tau at wayne wrote:
how can I keep track of the phase?
You can use an uninitialized shift register or a functional global, also called an Action Engine, which also uses an unitialized shift register to hold values. Once your phase is set, wire it to the shift register. When it changes, wire the new value to the shift register. Every time you call the vi, the latest value will be stored in the shift register.
Read all about Action Engines here
04-27-2010 07:15 PM
Thanks a lot tbob.
Since 3pm till now I have been working on the problem and finally got something meaningfull and hopefully the solution however, I have noticed a problem.
The LED controlles the # of for loop and how many distinct values are generated. If i put more than 1 value, turn the code running on/off ( by using the switch) thevalues 1, 8 and 10 of output array dont change even though the other ones are changing. Anyone have any ideas?
Thanks.
04-28-2010 11:01 AM
Sorry, I'm still waiting on a license renewal (new job) so I can't open your vi. Someone else will have to handle this one.
04-28-2010 12:40 PM
I think there was more than one issue here. I modified your duty func vi where the dynamic data to boolean function was not outputting what you expected. In the phase test vi I made some modifications also like adding replace array subset functions and removing the local variable. There are probably more improvements possible and some cleanup to do but I think it is now outputting what you want (we can see the output values change when their respective phases reach 180 and 360 deg).
Ben64
04-28-2010 10:20 PM
Good luck with your new job tbob.
Ben thanks a lot. Very pretty coding indeed.
I have 2 questions. If you could run the code and see the data passing through the wires, you would notice that sometimes the data would go halfway and it would baunce back, but the next loop iteration it would go forward. Why is that? How can the data return backward?
If you run the code witha frequency of 1 or 2 , the values dont change but if it is 1.1 or 2.xyz it runs fast again. And another thing, the lower the frequency the faster it changes values, that is 0.001 would give faster changes than 0.01 , isnt that wrong?
Thank you for your time
04-29-2010 08:45 AM
1- The data goes out of the for loop only after all loop iterations are completed. The data does not bounce back but is accumulated at the output of the for loop.
2- It is related to the default sampling frequency and number of samples. When you set your signal frequency to 1 Hz with the default Fs and #samples it is always the same phase that is outputted so the output value doesn't change. When you set it to 1.1 Hz it is changing fast again (note that it seems to change at the same rate than a 0.1 Hz signal, this is also surely related to the sampling frequency). I would suggest you look at the detailed help for the square wave vi.
Note: when I run the vi 0.01 does change faster than 0.001.
Ben
04-29-2010 12:26 PM
I took a look at the detailed help of the Square Wave VI. The phase out is equal to (Fsignal/Fsampling) X (360 deg) X (#samples). So with a Fsignal of 1 Hz and the default sampling values of Fs = 1000 and #s = 1000 you get a phase out of 360 deg which is why the output value doesn't change. Now if you change the signal frequency to 1.1 Hz the output phase will be 396 deg = 36 deg which is the same phase that you will obtain with a signal frequency of 0.1 Hz. This probably explain why in some of your cases the output is changing slower in higher frequecy signal.
You will need to select carefully your sampling parameters to get your expected results.
Ben