|
Re: loosing encoder count
James,
It sounds like Mark has probably identified your problem, however there are two other things that you might want to change. In your HandleTurretInterrupts routine, you need to check for the interrupt enable bit as well as the interrupt flag (INT2IF & INT2IE for example) in your IF statement. Disabling the interrupt enable, doesn't stop the interrupt flag from getting set, it only disables the processor from generating an interrupt in response to the flag. For example, say you have the pan interrupt disabled (INT3IE = 0) and you get a rising edge from both the pan and tilt encoders. Both the INT2IF and INT3IF flags get set, but only the INT2IF flag generates an interrupt. In your code, since you only look at the interrupt flag and not the enable bit, you will handle both interrupt flags even though you want to ignore the pan (INT3IF) one. If you check the interrupt enable flag, you can ignore the INT3IF flag and later, once your main code reenable the pan interrupt (INT3IE = 1), the pending interrupt flag (INT3IF) will immediately geneate a new interrupt and your code can handle it then. Second, if at all possible, I wouldn't use a print statement within an interrupt. You would be better off by incrementing a variable and then printing it from your main loop if it changes (or displaying it on the dashboard). You will get the same information but not delay interrupt processing.
Mike
|