05-26-2015 11:25 AM
I have a program that creates a digital PWM signal with variable duty cycle. The duty cycle changes every 50 ms, but the overall wave frequency stays at a frequency determined by the user. I have the VI attatched.
My problem is this...I need to be able to control the overall cycle time. This means the size of my array of duty cycles needs to adjust based on the cycle time (i.e. a cycle time of 1 second would require 20 of the 50 ms slots, while a 1.3 second cycle would need 26).
I currently have only 4 slots in my array, meaning the total cycle time is .2 s. I understand how to manually add and remove elements to the array, but I can't figure out how to add a control to it so that the array size changes automatically, allowing much quicker entry of data. As of now I can make it work, it just takes super long to add or delete array elements. The ideal situaton would have a constant control for cycle time divided by 50 that would change the array size.
I can't find any info on this, and I think I even saw a post asking that this kind of feature be added. I'm relatively new to this program.
Thanks
Solved! Go to Solution.
05-26-2015 11:39 AM
For the sake of a Good-Looking Front Panel, you probably don't want to have the actual physical size of your Percent Duty Cycle control change (I notice you have it embedded in a Decoration, for example).
Have you thought about adding a Vertical Scroll Bar, which will let you "go to the end and add new elements"? [Hmm -- how would you know when to stop adding new elements? You could do something funky like changing the color of the elements to bright red when it gets full, or possibly play with the Array Index indicator to prevent scrolling "past the end" -- you might want to write a little "test VI" and play around with this ...]
Bob Schor
05-26-2015 11:58 AM
You can do it one of two ways. You can have an array constant with the maximum number of ellements that you will need and then use the array subset function to select the portion that you want. The second option is to use the initialize array function and connect the array size input to your control.
05-26-2015 12:27 PM - edited 05-26-2015 12:37 PM
Currently, your VI is a one-shot deal. What you need is a state machine that updates the pct duty cycle array control as a function of the frequency while the current I/O code is idle.
I would use an array of clusters, where each cluster contains e.g. a sequence number, a duty cycle, and a string as element label. Show the scrollbar and set the size whenever the relevant inputs change. Do you want to reset the current setting when the number changes or do you want to retain the current settings as much as possible? You could just use the existing values, reshape to the larger or smaller size, and write it back to the control via a local variable. Set all elements except the percent to disabled so they act as indicators and cannot be changed by the user.
(You also need to program around it if the operator tries to manually add more elements. A better solution would be this idea, so vote for it :D.)
Some more general comments bout your code:
05-26-2015 01:41 PM
Subst array works for what I'm doing
Thanks man
05-26-2015 01:48 PM
@Patches_ wrote:
Subst array works for what I'm doing
"Reshape array" would do the same thing with fewer input connectors. 😄
(See the last sentence of the help, it even works for making a 1D array longer if needed, something that "subset array" cannot do. ;))