Hi,
Now that you're aware of how ON INTERRUPT works there are a few things that can be done to help speed up the response (latency). Instead of having a single 500ms long pause, how about 500 pauses, each 1ms long?
Code:
i VAR WORD
Main:
GPIO.0 = 1
GOSUB GoToSleep
GPIO.0=0
GOSUB GoToSleep
Goto Main
GoToSleep:
For i = 1 to 500
PauseUs 1000 'Tweak this if timing is critical.
Next
RETURN
Now, you should get pretty close to what you expected in the first place. If timing is really critical you'll need to tweak the PauseUs statement as each time thru the loop takes a couple of uS longer due to the inserted checks of the interrupt-flag and the fact that it takes a few cycles to jump around inside the FOR-NEXT loop.
Also, remember what we said about HIGH and LOW? That they write to the TRIS register everytime.....and there's no need for you to use them as you've so elegantly set the TRIS register correctly at the beginning of your program. It's usually "better" and faster to simply write directly to the port register with GPIO.0=1 etc.
/Henrik.
Bookmarks