Glitches Eliminated using Interrupt Context Saving, BUT ...
Can someone give me some advice?
I have written some pulse-measurement code for last years' wheel encoders, and along the way I discovered some things.
1) the CCP (Capture/Compare) feature that would have been the ideal solution cannot be used because there are no CCP input pins available on the full-size controller.
2) therefore I had to use pulse edge detection - interrupt on the leading edge of the pulse, capture the time, reprogram to interrupt on trailing edge, interrupt on trailing edge, capture the time again - subtracting the two times to get pulse width. To get the times I use TIMER3 programmed at 1/10 microsecond resolution.
3) all along (even before I had started working on the pulse measurement code) I had been seeing
glitches on printf() output and also servo chattering. I'm using Kevin's interrupt-driven serial port code, but the printf() glitches were happening using the standard IFI serial port code also.
Suspecting some registers were getting clobbered by the interrupt service routines, I played around with the interrupt #pragma in user_routines_fast and managed to fix both problems ... but at a cost of substantial additional overhead - that affects both the minimum length of pulse I can measure, and the accuracy in measuring them.
I have some other interrupt-driven code that implements a wallclock timer using TIMER0, but disabling those interrupts does not fix the glitches - they are coming from elsewhere.
Here is the #pragma along with comments:
Code:
#pragma interruptlow InterruptHandlerLow save=PROD, section(".tmpdata"), section("MATH_DATA") /* You may want to save additional symbols. */
// Dec2006 - failure to save section .tmpdata results in glitchy servos
// - failure to save section MATH_DATA results in glitchy printf
// - COST OF SAVING SECTIONS IS ABOUT 14 MICROSECONDS PER SECTION!!!
// WHICH AFFECTS MEASURING ENCODER PULSE LENGTHS
// minimum pulse measurable with save=PROD is 14 usec
// adding section (".tmpdata") is 27 usec
// adding section ("MATH_DATA") is 40 usec
I'm happy to be rid of the glitches, but if I wasn't getting them in the first place I wouldn't need the extra #pragma sections and could measure smaller pulses.
Can anyone shed some light on this?