Quote:
|
Originally Posted by BradAMiller
The gear tooth sensors work, but it very difficult to get the difference between forward and backwards rotation. As was said, the way to tell is the length of the pulse that is returned. The time in/out of an interrupt service routine is pretty long - especially if you have to save the floating point data area and the temp data areas.
I've been very successful using them to detect pulses, but the direction is very unreliable. In EasyC and WPILib they are currently just counting pulses. I hope to have a new version out soon that will count up and down for clockwise/counterclockwise.
Brad
|
Brad,
When using interrupts on this microcontroller, remember that it has no floating point support in hardware. It only has 8 bit integer support. The larger the integer you use, the more instructions are required to do anything with it. Floating point is even worse.
In general, when writing an handler, you want to split the work into two pieces.
In the actual Interrupt Service Routine (ISR), you want to do the least work that you can get away with. In this case, simply subtracting from the last stored value and then storing off the timer value for next time. You want to do only what must be done to save the information about what happened.
The other half of the processing is done in a Deferred Procedure Call (DPC). In here, you can do your floating point division to figure out the actual speed. At the end of your ISR, you need to set a bit in memory somewhere that you will check in you code elsewhere... probably in the user_routines_fast() function. If the bit is set there, then you want to call your DPC function to finish the work on the new raw data.
Using this structure, you will avoid saving off the floating point registers when entering your ISR, will have more accurate timing, and far less interrupt time overall. This will make the rest of your processor more responsive and you will be able to handle far more interrupts on the processor without problems.
Good luck!
-Joe