Go Down

Topic: Moving Return Stack Pointer? (Read 787 times) previous topic - next topic

jimford

I've got an interrupt service routine that kicks in while in the method 'myStepper.step(steps)'. I don't want to return to the method, but to the point in my code where it's called. How do I decrement the return stack pointer in order that the code returns to the point I need, please?

Jim

AWOL

Don't muck about with stack pointers.
Restructure your code
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

jimford


Don't muck about with stack pointers.
Restructure your code


Thanks for the reply.

Hmm, not the quick and easy answer I was hoping for!

I'm winding a stepper motor driven carriage back to a start position. When it gets past the start position it operates a microswitch which triggers an interrupt. The interrupt service routine then backs the carriage off the microswitch to the final start position, and the code hopefully returning to the main loop.

As I mentioned in my OP, the interrupt service routine returns to the myStepper.step(steps) method, then hangs somewhere in it.

I'm not sure where to start restructuring my code. I thought just losing the return address of the myStepper.step(steps) method would get me back to the main loop just after it was called. A quick, albeit dirty solution!

Jim

PaulS

If you are running a stepper motor back to home position, until it hits a limit switch, it seems like a while loop that steps once then checks the limit switch state, until the limit switch is pressed would eliminate the need for the interrupt, and accomplish the same goal.

mmcp42

get the ISR to set a flag
test the flag in the main code

don't spend any longer in the ISR than setting a flag
there are only 10 types of people
them that understands binary
and them that doesn't

jimford


get the ISR to set a flag
test the flag in the main code


The problem is that it seems that the ISR doesn't return to the main code, but to an arbitrary point in the myStepper.step(steps) method., depending on when the switch is operated.

I've gone for a while loop, checking the switch state after every step and it works fine. It's actually quite an easy task, but my brain because locked into the idea of an interrupt!

Thanks for the ideas.

Jim

robtillaart

Post your code so we can see what "devils" you are fighting ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

AWOL

I have no idea how to restructure your code either because you didn't post any.

I have a rule of thumb - if something sounds like it is the wrong thing to do, it probably is the wrong thing to do.
About the only  time I've ever had to fiddle with stack pointers is for machine monitors and single step debuggers.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

jimford


Post your code so we can see what "devils" you are fighting ...


Thanks, but the devils are exorcised from my code now!

Jim

jimford


I have a rule of thumb - if something sounds like it is the wrong thing to do, it probably is the wrong thing to do.


Spot on for my (ex) problem!

As I said earlier, I got locked into the idea of an ISR and it got increasingly ugly from there!

Jim

Go Up