03-09-2021 09:30 AM
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,
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
03-09-2021 10:01 AM - edited 03-09-2021 10:30 AM
@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:
03-09-2021 04:00 PM
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
03-09-2021 05:16 PM
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
03-10-2021 10:57 AM
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
03-10-2021 11:03 AM
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.
03-10-2021 12:06 PM
@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!