06-13-2013 05:02 PM
Hello,
I was trying to understand why my program is running the motor twice . The logic of programming is DITTO of the "1DmotorFINAL-TIME_ANALYSIS-2-CASE STRUCTURE.VI"
But , when I built the same thing into State Machine style it is running twice. I tried checking the program with "Highlight execution" But dint find anything strange.
I am not able to figure out whats happening. Could someone please try explaining why the program " Motor-UNI_Directiona Dev 5-STATE-MACHINE-Top_Level_TIME-ANALYSIS-FINAL 2.VI " is making the stepper motor run two rounds for the same number of steps as in the other program.
06-13-2013 05:34 PM
Most likely the Stop button is read almost immediately after an iteration starts. If the button is pressed after that, another iteration will occur before it is read. This is basic dataflow and is the fundamental paradigm under which LV operates.
If the Stop button is pressed when the program is in any state other than Motor Control: Motor Run, the value changed event will queue up and will execute immediately when that state is reached.
It appears that your event structure actually does nothing. With a zero timeout it does not wait. There is nothing to run parallel to it, so the zero wait does not release the CPU to run other code. and the Stop switch is polled by the for loop.
In the for loop the (N - (i + 1) ) =? 0 test is not needed. That is what a for loop does. The loop will stop at i = N-1 without that test. The conditional terminal will stop the loop if the Stop button is pressed before i reaches N-1.
You have speed set to 600. In the loop you calculate the Wait time = (1/600)*(800) = 1.33 ms. The resolution of the Wait (ms) function is 1 ms. You cannot get fractional millisecond delays.
Closing and re-opening the VISA resource on every iteration is not recommended. Open once outside the loop(s) and close after the exit.
Lynn
06-13-2013 06:27 PM
Let me explain what I see in my lab.
A stepper motor has 400steps to turn 1 full round. So the original program "1DmotorFINAL-TIME_ANALYSIS-2-CASE STRUCTURE.VI....." runs exactly 1 full round when the input is given as 400. Where as this runs for 2 rounds for the same number of steps.
1. Assuming you are talking about the STOP button of the FOR loop conditional terminal , I think yes. But , the FOR loop executes 2 times exactly ( if number of steps is 1 ) and writes to VISA. So there is no duplication or repetition of the FOR loop. Therefore it should STILL run only once.
2. Is there a problem if we have a Zero timeout case for an event structure ? ; the FOR loop still functions perfect as per the program execution.
3. (N-(i+1))=0 ? condition is not required , that is correct. Thank you very much.
4. I still dont understand why the motor takes 2 rounds to complete and that too pretty fast it runs. I cannot find whats happening where.
06-13-2013 07:43 PM
I tried running your VI with Execution Highlighting turned on. It takes several minutes but it only ran 1 round (the for loop ran 2 iterations for 1 step).
I do not have any other ideas at the moment.
Lynn
06-14-2013 07:55 AM - edited 06-14-2013 08:05 AM
Your number of steps is set to 1. Then in the Run Motor case, you multiply the number of steps times 2. This is what is wired to the For Loop N terminal. So of course it will run twice. If you press the stop button during the first iteration, well it is too late. The stop button is read immediately, as explained by johnsold. At the time it was read, it was still false. So the stop condition is not met. The loop will run twice. Remove the multiply by 2 to make it run once.
Edit: I just looked at your vi again. Which loop are you talking about, the For loop or one of the outer while loops? I think you should change your architecture. Try to acoomplish your goal using one while loop with an event structure.
06-14-2013 10:53 AM
Thank you for all your inputs. I was able to reproduce the problem by checking each and everythign that is causing my motor to run two rounds for the same number of steps.
The shift register data flow is causing a problem.
My hupothesis: The data flow (databits) is repeating twice via the shift register and thus writing it twice
Could some one shed some light on the difference between the following two diagrams: How does the dataflow happen through the shift registers in FOR LOOP ?
1. I haven taken any data out from the shift register of databits (see circled)
2. I have taken the data out for each loop and updating the output cluster.
06-14-2013 01:01 PM
The first time the loop runs, the data wired into the shift register on the left side is used. At the end of the first iteration, some data is written into the shift register on the right side. On the next iteration, this new data appears on the left side and is used in the second iteration.
In your top diagram, you don't have the left side shift register wire to anything, so the data written on the right (small red circle) is lost. But this is not why the loop iterates twice. For loops will iterate according to (1) what is wired into N, and (2) any array input with indexing enabled. Data left in the shift register will not cause the loop to iterate again. You don't have any arrays with indexing enabled as inputs, so the loop will iterate two times the number of steps (multiplied by 2).
I would still change the architecture to use one outer loop instead of two. A properly formed state machine should be able to handle the entire scenario. I think this is your real problem. When I have time, I will dig into it further.