From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sequence output using arrays

Solved!
Go to solution

See if this works.

0 Kudos
Message 11 of 15
(671 Views)

Your code makes absolutely no sense.

 

  • Both inner while lops can be removed without any change in functionality. Why are they there?
  • The RPM control related logic seems to be the same in all cases, thus belongs outside the case structure
  • The values of the orange array constant seems completely irrelevant for the current function. What is their significance?
  • Your arrays are either 8 or 16 elements long, so the output of the case structure is either 0,  8 or 16 on all four outputs There seems to be a lot of reduncancy. All the orange stuff could be replaced by 3x I16 diagram constants.
  • Why are you configuring the port from scratch with every iteration of the outer while loop. That only needs to happen once outside the loop.
  • You seem to have the misconception that the visible size of an array container somehow determines the array size. That's not true.

You really need to explain what you actually want to happen and how it is supposed to function. I am drawing a blank. Sorry. 😉

 

0 Kudos
Message 12 of 15
(666 Views)

For example, when the user places the switches into CCW, Full Step, Continuous mode the selector case will be case “0”. In case “0” the input sequence for the motor to rotate counter-clock wise at full step is 0011 (wire 1), 1100 (wire 2), 1001 (wire 3), and 0110 (wire 4).  These are the numbers I am trying to use the array to transmit to the stepper write VI in order for the motor to turn in the desired direction.  This obviously is not working which is why I am seeking advice on the use of arrays.  I understand that I have some other issues with my code (I am still learning) but, if you could suggest a better solution for what I am attempting to do starting with the arrays then working from there it would be welcomed.

0 Kudos
Message 13 of 15
(650 Views)

Sadly I cannot view your code because I use LV 2010, but I think I have some hints for you about using arrays.

 

First of all, define constant arrays with your sequences as boolean arrays, instead of double arrays with zeros and ones. This reduces the amount of resources necessary and might be helpful in future implementation of your solution into DAQ.

In order to do so, insert Array Constant, and then place boolean constant inside it. This way you create 1D boolean array. You can drag and drop a border of array to see more elements of it, but as someone noted before, it doesn't mean you set the array size by doing so!

The number you can see next to an array is used to scroll through an array. To be exact, this is the number of the first element you currently see. I assume you want to work with 8-bit arrays, so for the starters leave that number set to 0, and expand the view so you can see 8 boolean values. The full understanding of that number will come with experience.

Set desired values to array ements by setting true or false on each element. You will notice they change color to more solid green, which indicates that these values are added and recognized as array elements - those in more pale colors are NOT array elements and cannot be treated as such.

 

From that point, in order to use an array value for anything, use "Index Array" block form Array palette. Here you can wire an array, and a number of item you'd like to extract. It outputs the desired array element.

 

Oh, and when you switch the array type to Boolean array, you might need to change your controls and indicators on the front panel.

 

Hope this helps!

0 Kudos
Message 14 of 15
(646 Views)
Solution
Accepted by Phalanx13

Ok, here's a cleaned up version of your VI that I'm guessing is what you want.  I don't have your library, so it might not be totally correct.  Some things I did:

  1. Initialize the serial communication and stepper motor control once before the main loop.
  2. Got rid of the Array Size functions.  All they return are the size of the arrays.  You need the data in the arrays.
  3. Changed the arrays to I16 representation.  That's what it seems your library wanted.
  4. Put the write to motor code inside of a FOR loop.  This way you are iterating over the arrays so you write them out in a sequence.
  5. Removed the RPM calculation from the case structure.  It's being repeated.  There's no point in that.  The wait then went inside of the FOR loop.
  6. You calculations for which case to perform is way too complicated.  Build array and use Boolean Array to Number.  Now your cases are 1 through 7.

VI saved in 2010.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 15 of 15
(625 Views)