Go to Post A good measure of Integrity is what you do when nobody's watching. - DonRotolo [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Spotlight this post!  
Unread 08-02-2008, 11:39
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Interrupts, Interrupts, and more Interrupts!

How can the autonomous routine loop and loop and loop and never
(apparently) return and still work under MPLAB/WPILIB or EasyC?
----------------------------------------------------------------

I've done something similar before. Again, in the system clock routine check to determine when autonomous mode is ending (I was in autonomous last clock tick, but this time I'm not -- so autonomous period just ended). When you detect this, reset the variable stack managed by the C compiler and reset the hardware stack location (STKPTR) to point to the return to main().

For example, in the standard IFI code if:
_entry (reset) jumps to _startup
_startup then calls main()
main() then calls Autonomous()

Code:
main()
{
    Autonomous();
    Operator();
}
Autonomous()
{
     while(1)
     {
         // user code here...
     }
}
The call stack will always look like:

Code:
 0000
 0001  _startup+n  <- main's return will pop and use this
 0002  _main+n     <- autonomous' return will pop and use this
Slamming the stack pointer and frame pointer managed by the C compiler back to their defaults and then changing the STKPTR index to 2 and then returning normally from the interrupt service routine will make it appear as if the Autonomous() routine just returned to main() on its own. Instead, the interrupt service routine hijacked the stack and did it for us...

Yeah, we could do the same thing between iterations through Autonomous(), but this way again we don't really care how long the code path through autonomous is, it will get yanked immediately into the Operator() code when autonomous ends.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How many interrupts is too many interrupts? Madison Programming 14 08-02-2008 12:09
More than 6 RC digital input interrupts? Jared Russell Programming 2 06-02-2007 15:41
Interrupts and Script Conundrums Jon236 Programming 2 08-02-2005 23:01
interrupts and putdata() doy Programming 4 23-02-2004 22:45
Interrupts and rotation sensors kor Programming 3 12-02-2004 11:05


All times are GMT -5. The time now is 23:46.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi