10-28-2020 01:47 PM
Hello Everybody,
it is the first i write into the forum, and I feel emotioned about it 😄
I am building a small rig to move back and forward a bar using a gear and a step motor. I use Arduino to controll the stepper motor, 200 steps/rotation 1.8° per step.
At the end of each stroke I have one proxymity sensor that stops the motor and inverts it for undefined numbers of steps
and it works fine, but I need also to stop the motor half way through the routine at certain numbers of steps that are a % of the total stroke, but i am struggling to calculate the full stroke to half it for the purpose.
I attach the VI, i am also thinking to fit an encoder, with the stepper motor resolution above, which one you may recommend?
Thanks,
Marco
10-28-2020 02:03 PM
Sorry, I don't have your hardware or the missing subVIs, but I would recommend to remove all that duplicate code and unneeded sequence structures. I am sure it would be sufficient to have one loop, some state variable and one single place to do the serial setup.
10-28-2020 02:48 PM
Hello Altenbach,
thanks for the quick reply, i am aware that the code for the moment is not efficient, and I will spend time to make it leaner.
However, I am still stuck with the question.
How do i calculate the total steps between the two endstops when the routine is halted by the proximity sensor?
Thanks,
Marco
10-28-2020 02:49 PM
About the hardware, I use LYNX with Arduino for the PWM signal
10-28-2020 02:57 PM
Can't you wire the iteration terminal of the first loop out to see how many times it iterated and derive the number of steps from that.
10-28-2020 03:02 PM
i don't think so, because i send a signal with a standard number of cycles, and the loop will repeat it indefinetely until the sensor stops it overriding the last set of standand number of cycles.
this is the problem, because I stop the cycle in the middle of it due to the sensor's intervention.
10-28-2020 03:40 PM
Why not...
Won't that give you the number of steps it takes to get half way?
10-29-2020 09:01 AM
probably it's me that is not clear enough.
let make an example with some numbers
i move the motor to the zero position defined by the sensor that change from high to low telling the VI " hello, i am the end stop, please stop, invert the sense of rotation"
from this position i ask the motor to run 200 steps (1 turn) in the opposite way and it does it checking continuously if the other end sensor is activated.
after these 200 steps with no intervention of the sensor, the VI asks to the motor another 200 steps to be completed as above but this time half way through the sensor activated and the cycle stops.
in the VI i just set the number of steps and the direction, i don't ask to run a single step each time, and this is the problem.
i don't know how many steps have been done until the sensor is activated
i was thinking to read the digital output of the PWM to count those steps until pulses stop.
10-29-2020 09:12 AM
Hi Marckus,
@Marckus wrote:
in the VI i just set the number of steps and the direction, i don't ask to run a single step each time, and this is the problem.
i don't know how many steps have been done until the sensor is activated
Is there a need to ask for 200 steps each time?
Why don't you ask for small amount of steps?
Suggestion:
Ask for 200 steps, then just 1 step until the end position is found. Now you know how many steps there are between both limit switches…
10-29-2020 09:39 AM - edited 10-29-2020 09:46 AM
@Marckus wrote:
in the VI i just set the number of steps and the direction, i don't ask to run a single step each time, and this is the problem.
You are right, this IS the problem.
Why ask the motor to make 200 steps at a time?
Why not one step at a time until you figure out how many steps it takes to reach the stop?
Then calculate the half way point.
Now you can send the stepper the number of steps to go full stroke or half stroke.