LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to adjust a "control array" size

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(7,477 Views)

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

0 Kudos
Message 2 of 6
(7,470 Views)
Solution
Accepted by topic author Patches_

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.

0 Kudos
Message 3 of 6
(7,461 Views)

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:

  • Why do you use extended precision floating point. All your waits are internally just integers. EXT makes no sense
  • There is a primitive for 1/x. However, you could just do a 1000/x and eliminate the multiplication afterwards. SInce you are dealing with integers, you can even do the division using quotient&remainder. Depending on the allowed frequency range there are possibly no orange data needed at all.
  • Make the diagram constant representation match the rest of the code.
  • The pulses/50ms indicator belongs before the loop. No need to recalculate and refresh it over and over from the same input values.
0 Kudos
Message 4 of 6
(7,445 Views)

Subst array works for what I'm doing

 

Thanks man

0 Kudos
Message 5 of 6
(7,413 Views)

@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. ;))

0 Kudos
Message 6 of 6
(7,403 Views)