Pages: [1]   Go Down
Author Topic: Moving Return Stack Pointer?  (Read 630 times)
0 Members and 1 Guest are viewing this topic.
Hertfordshire, U.K.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Hertfordshire, U.K.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48569
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Leighton Buzzard, UK
Offline Offline
Edison Member
*
Karma: 21
Posts: 1339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

there are only 10 types of people
them that understands binary
and them that doesn't

Hertfordshire, U.K.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Rob Tillaart

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Hertfordshire, U.K.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Jim
Logged

Hertfordshire, U.K.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: