1) This doesn't do what you think it does: if (P2IN & BIT1 == BIT1) It should rather be: if ((P2IN & BIT1) == BIT1) 2) This also doesn't do what you think it does: if (t2 > t1) In Continuous mode the counter wraps every ~65 milliseconds, so there is a fairly good chance it will wrap between the two edges, and t2 < t1. Dealing with modulo-64K values can be messy, but if you compute the difference t2-t1, unsigned underflow will do the right thing and you'll get the expected result. Life gets easier if you only work with the deltas, not the actual timestamps. I'm not sure what to recommend you replace this line with, because I'm not sure it should be there at all. My first suggestion would be to just remove it, and let the subtraction on the next line do what it does. Unsolicited: I'll throw in the usual warning about not using the UART from an ISR, but maybe(?) you were planning to remove that stuff anyway.
↧