Accelstepper/blocking functions and interrupts

Hi everybody!
Just a simple questions relevant to stepper motors and limit switches:

Are the blocking functions in accelstepper/stepper sensitive to interrupts?

So next: is it possible to drive a stepper motor+limit switches using interrupts instead of nonblocking functions+polling?


Have you tried it?

No I didn't. That's why I'm asking. If somebody already knows the answer I won't waste time trying. Google didn't help me much.

It is definitely NOT safe to call most Accelstepper functions from an ISR.

The 'blocking' functions just calls the non-blocking function until the move is done:

// Blocks until the target position is reached and stopped
void AccelStepper::runToPosition()
    while (run())
	YIELD; // Let system housekeeping occur

I think the best way to handle limit switches is to write your own 'blocking' function instead of using the library function. Polling the limit switch between calls to .run(). On limit, call .stop() and then run to the new position. The 'stop' function sets the destination to the closest point where maximum deceleration can stop. You will need some compliance in your limit switch so the switch will activate before it is too late to stop.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.