LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

capture sequence of 4 digital inputs

What I have set up is a I am trying to read the outputs of a stepper motor driver.

It is bipolar which has two windings, so there is a total of outputs going to a non labview DAQ device.

 

So, what I created is a loop which reads the pulse of the 4 steps of the driver and creates a digital waveform plot. That was successful and I can see the different steps as the are activated.  I collect the data in an array. I trigger the sequence to start reading when the first bit goes HIGH.

 

I have been able to detect,

  • when a low to high state change has occurred.
  • What Step has occurred (the element of the array)
  • To detect if more than 1 step has occurred, which would be an error.

 

Also I created a sort of simulation with four buttons acting like the digital inputs.

 

I want to match the sequence and verify the direction of either Clockwise or Counter-Clockwise.

Array output stats at {1, 0, 0, 0}

 

Clockwise                                                            Counter-Clockwise

Step

1,     {1, 0, 0, 0}                                                   1,    {1, 0, 0, 0}

2,     {0, 1, 0, 0}                                                   2,    {0, 0, 0, 1}

3,     {0, 0, 1, 0}                                                   3,    {0, 0, 1, 0}

4,     {0, 0, 0, 1}                                                   4,    {0, 1, 0, 0}

 

 

What s the best method of collecting the data?

I have tried all of the following:

Do I convert out put to a string and read 0’s and 1’s?

Do I push this to some sort of array somehow?

Match outputs to time and base it off of that. 

 

It seems I am close, just need a little push, 

Thanks

Download All
0 Kudos
Message 1 of 7
(1,005 Views)

@montcuky wrote:

It seems I am close, just need a little push, 

Thanks


Maybe a little more than a push, because I don't understand your code at all. I assume the "edge.vi" is the simulation. How do you use it and what do you expect to see?

 

Many things are way too complicated., for example:

  • A "not equal true" is just a "not" No need for two inputs.
  • You can do "Or array elements" on the array with four elements.
  • You don't need to wire indices of index array if you want the elements in order.
  • You can do "boolean to 0,1" on the array followed by "add array elements. (I have no idea why you invert the output of the compound add, followed immediately by negation (see also).
  • You don't need a "equal 1" to wire to a case structure. Just wire the numeric and make one case "1" and the other "default". Same for the "equal 4".
  • If you place indicator terminals inside a case structure, they will not update if the other case executes.
  • ....

 

 

0 Kudos
Message 2 of 7
(984 Views)

I read altenbach's reply and won't be looking at the code.  Sounds like it's more problem than solution so far.

 

What you're doing is pretty analogous to quadrature decode logic.  You have 4 legal driver states, where each bit has its turn being high while the other 3 are low.  I would label those *driver states* unambiguously.

 

Driver State        Bit Pattern

0                         {0, 0, 0, 1}

1                         {0, 0, 1, 0}

2                         {0, 1, 0, 0}

3                         {1, 0, 0, 0}

 

If you detect any other bit pattern, it does not represent a valid state and you should throw an error.

 

Next, every time the bit pattern changes, you should evaluate the transition.  You should only ever increment or decrement by one driver state at a time.  If you see a transition between states 0 & 2 or between states 1 & 3 (in either direction), that's an invalid state transition and you should throw an error.

 

For the other driver state transitions, direction is determined by whether the state increments or decrements.  Implied in this is the "circularity" of that list of states.   In other words, incrementing from state 3 takes you back to state 0 and decrementing from state 0 takes you back to state 3.

 

The reason I numbered the states from 0-3 instead of from 1-4 is that I've been down this road before and found that it was handy to use modulo math (see the Quotient & Remainder function).  When you calculate (new_state - prev_state) MOD 4, you'll get either +1 for one direction or -1 for the other.  If the result is 2, it's one of the illegal transitions I mentioned earlier.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 3 of 7
(936 Views)

Oops, minor correction and too late to edit.  After the MOD 4, you'll either get +1 or +3.  That function only returns non-negative remainders.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 7
(928 Views)

 

Thank you for pointing out the mistakes. Always improving my LabVIEW skill-tools. I made change to the VI.  The simplified array manipulation makes total since.  This is the whole point of me posting this. Which I don’t do that often. 

 

When you were referring to “If you place indicator terminals inside a case structure, they will not update if the other case executes” was there a specific area you were addressing?

 

I have it working I can detect the direction either CW or CCW,  there is only one error being handled at the moment. 

 

I think the section where I concentrate the string could be cleaned up. I will have to work on that .  

 

The simulation was just something i made to mimic the inputs, its irrelevant so I just sent the new VI 

 

Thank you 

0 Kudos
Message 5 of 7
(885 Views)

Kevin

 

Wow, when I first started planning for this project this is the approach that I was going for. I did not know how to begin this way and create a status where the array elements were either increment or decremented.   What you stated makes since but it will take a bit to soak in and try and create this.

 

Thank you.

0 Kudos
Message 6 of 7
(883 Views)

@montcuky wrote:

 

Thank you for pointing out the mistakes. Always improving my LabVIEW skill-tools. I made change to the VI. 


Your VI is still full of Rube Goldberg  code. The entire VI could be done with 10% of the current code. Very convoluted!

0 Kudos
Message 7 of 7
(875 Views)