I am working on a PID controller that also does the quadrature decoding of an optical encoder (which I made tehehe). I have it basically working using assembly interrupts.
The basic operation is to get the current encoder channels and the encoder channels from the last interrupt (interrupt on change of pin value) into one byte, which goes from 0-15 (I make sure to clear the 4 MSB bits).Then it uses a lookup table (In assembly, consisting of a PCL addition to a GOTO branch) to determine what this code means. I know it'd be faster to shift my index left by 1 or 2 places, and then have the necessary instructions on 2 or 4 lines. However, I'm not there yet.
My main concern is that right now, I put my interrupt service routine as close the top of the code as possible, w/the table near the top of the interrupt service routine. I do this because I want the PCL to have a value that is less than 255-15, so that when I add to it jumps to the right place. According to AN556 from Microchip (http://www.engr.usask.ca/classes/EE/331/AN556.pdf) standard practice is to put an "org [address]" at the beginning of a table. What I can't figure out, even after searching quite a bit, is what is a good value for this? I've played around with it a bit, but it either doesn't compile because the address interferes w/PBP code, or crashes my code.
Where can I determine a good value for the ORG of my table? Also, I know that the interrupt service routine needs to be near the top, is this because it has to be on the first page?
I'm a bit confused about these pages and stuff. What's the best way to attach code?
Please advise.
Thanks,
Matt
Bookmarks