04-23-2010 11:39 AM
Hi all,
I am trying to use function generator and making use of its frequency and duty cycle options to generate multiple signals for multiple inputs. In my project its about 95 of them.
I have writen some code but its not working as I was expecting it.
I want each input selection to have its own output result and use only one function, but apparently there is only one output for all the inputs.
How can I make it or what should I do to make my code do what I wont it to do? Any suggestions? I would like to avoid using the function generator 95 times if possible.
Thanks a lot.
04-23-2010 11:51 AM
04-23-2010 12:09 PM
04-23-2010 12:56 PM
04-23-2010 01:15 PM
You don't even need the while loop. This will give you an output for each input:
04-23-2010 01:19 PM
If you include the while loop and keep the function running , you might notice that the on/off states are all the same if yu include the same duty cycle and different frequencies, which is wrong, so that vi is not workin properly.
I believe the function generator keeps track of the last value so when a new value ( new frequency) goes in, the result would be dependent from that.
What do you think?
04-23-2010 01:49 PM
It make sense to always read 1 because you always read the first value. . For example (with the current settings: sampling freq = 1000, number of sampling = 1000), if the frequency you select is 1 Hz and the duty cycle is 50% the first 500 values will be logical 1 and the other 500 will be logical 0. Since you always read the first value (index array function with index set to 0) you will always read 1.
Ben64
04-23-2010 02:59 PM
What is on/off supposed to indicate. As has been mentioned, it just reads the first element in the boolean array. Because your are generating a square wave, the array will be full of 0s and 1s. Even 1 cycle will have a 0 and a 1. So how does this relate to on/off? Let us know what you intend for on/off to indicate.
04-23-2010 03:42 PM
The code is supposed to controll a bunch of LED and needs to do that really fast. Unfortunately due to pc speeds, i was going to pre generate the data first and save them on file, so when i send the data to the led they are` already there, just being read I hope its faster than being generated in real time.
If you run the on/off vi and choose the first frequency 0.001 ( thats visible ) you see that the socondary or any other frequency doesnt have any affect, but for the second output I need to see the result of the 2nd input freq, which the program is not doing.
To brighten the LED i am using some LED drivers which use the shift registers, meaning that to change the value of one , I need to input all the values, in my case 95. So even though there are 100 1's there, they are there for a good reason, those values are correct for only 1st LED not the rest of them.
I hope I am clear.
04-23-2010 04:07 PM
tau at wayne wrote:
If you run the on/off vi and choose the first frequency 0.001 ( thats visible ) you see that the socondary or any other frequency doesnt have any affect, but for the second output I need to see the result of the 2nd input freq, which the program is not doing.
It does show the result of the 2nd input freq. The results just happen to be the same. I'll try to explain again. Your on/off states indicator is taking the first element out of the array of values being generated by the square wave function. No matter what the frequency is, the sqare wave generator will generate an array of values, and the first value will be the same no matter what the frequency.
Lets say the frequency is 0.001. The output of the square wave generator will be 1,0,1,0,1,0.... and will continue until the number of cycles is satisfied. Lets way you then change the frequency to 0.005. The output will be 1,0,1,0,1,0... Doesn't this look the same? Just a different number of 1s and 0s. But the first element is always 1. It is working just as you programmed it to.
Again, you need to explain exactly what you want from the on/off states indicator. Maybe if you attached more of your code or a picture of your LED driver schematic. To change the brightness of LEDs, I would change the duty cycle, not the frequency. If the high level is on for longer, the LED will appear to be brighter.
If you are using the of/off states to drive an LED driver, you need to send the entire bit stream to the driver, not just the first element as your code shows. Your on/off would become a 2D array with row 1 being the bit stream for LED 1 and row 2 being the bit stream for LED 2. It might be like this if LED 1 is brighter than LED 2:
111111111100111111111100 - brighter LED 1
110000000011000000000011 - dimmer LED 2
The above is a 2D array of boolean values.