View Full Version : EDU Interrupt and Timer Template Code
Kevin Watson
12-12-2003, 21:56
To get the creative juices going for the coming build season, I've written some template code that will make the job of using interrupts and timers on the EDU controller much easier. It's somewhere around 800 lines of heavily annotated code that can be used alone or dropped into your own code. I've also re-written user_routines_fast.c to allow the use of all external and timer related interrupts. I'm also working on what I think are some cool demos using this code. If you have an idea on how to improve the code, find a bug or do something cool with it, leave a note here or e-mail me. Anyway, the zipped archive is located here (http://kevin.org/interrupts.zip). Have fun.
-Kevin
CyberWolf_22
13-12-2003, 19:37
Thank you this code is very helpful.
Kevin Watson
14-12-2003, 16:28
No problem. I'm glad you found it helpful.
-Kevin
Larry Barello
15-12-2003, 13:01
I wrote a small quadrature encoder interface using RB4-7 (ifi interrupt 3-6) and ran across a problem that doesnt appear to be addressed in your code: If you call a subroutine from an interrupt handler, you need to save additional stuff. You can find this in the C compiler in section 2.9 (something) or on the quick reference card. You need to replace
#pragma interrupt InterruptHandlerLow
with
#pragma interruptlow InterruptHandlerLow save=section(".tmpdata")
For more info, see below:
http://www.chiefdelphi.com/forums/showpost.php?p=200691&postcount=4
Kevin Watson
15-12-2003, 13:15
Hi Larry,
Thanks, I've had a few exchanges with folks about this via e-mail already and will make some changes to the code and do some testing this evening. It's strange in that I haven't had any problems with a couple of other applications that I've written lately. One, a motor controller, receives many hundreds of interrupts a second from an encoder, yet I've never had a problem (actually, while doing some testing, I found that I could handle a peak interrupt rate of just over 5,000 interrupts/sec and still see no wierdness).
-Kevin
Larry Barello
15-12-2003, 13:24
Hi Larry,
Thanks, I've had a few exchanges with folks about this via e-mail already and will make some changes to the code and do some testing this evening. It's strange in that I haven't had any problems with a couple of other applications that I've written lately. One, a motor controller, receives many hundreds of interrupts a second from an encoder, yet I've never had a problem (actually, while doing some testing, I found that I could handle a peak interrupt rate of just over 5,000 interrupts/sec and still see no wierdness).
-Kevin
I admit I was being a bit agressive: I have a 1000 count wheel on a servo motor as my test. I estimated around 1200-1800 RPM which gives 80-120K interrupts a second.
Even with the fix, that interrupt rate crashes the EDU system. It seems that 10-20k/sec is about as fast as it can go. Which is good since a 2 segment wheel on the back of a Boch motor generates about 5k/sec at full speed.
Joe Ross
16-12-2003, 09:47
I admit I was being a bit agressive: I have a 1000 count wheel on a servo motor as my test. I estimated around 1200-1800 RPM which gives 80-120K interrupts a second.
Even with the fix, that interrupt rate crashes the EDU system. It seems that 10-20k/sec is about as fast as it can go. Which is good since a 2 segment wheel on the back of a Boch motor generates about 5k/sec at full speed.
100k interrupts a second is extremely fast for a 40mhz processor. That's only 400 cycles between interrupts. Considering the time to save registers, as well as the fact that IFI has higher priority interupts, I can easily see why you had problems.
Kevin Watson
17-12-2003, 15:08
I've updated the template code to better handle low-priority interrupts.
It can be found here: http://kevin.org/frc.
-Kevin
Kevin Watson
22-12-2003, 14:11
"The Lucas" found a bug in my code related to timers 3/4 (thanks, Dude), so if you're using the interrupt and timer code that I posted, you might want to download the updated version from here: http://kevin.org/frc.
-Kevin
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.