That's the correct way.I had been disabling the cmp_int "inside" it own handler routine but felt that this was bad practice (any thought?)
Comparators can give many interrupts right at the point where it switches (hundreds even, if the analog signal is slow). If it's allowed to return from the interrupt without disabling, it'll end up right back in the handler again until it's past the switching point of the comparator. External hysterisis can be added to the comparator to eliminate that, but it's not needed in this case.
Also, much like the PORTB change interrupt, you should read the CMCON register inside the handler to end the mismatch condition. Typically, the handler would do that anyways to determine which comparator fired.
And,
before enabling the comparator the first time. Read CMCON, then Reset the interrupt flag.
Then be sure to clear it again before re-enabling later. The flag may have been set during the time it was Disabled.
No need,that I may have to check the stability of all my variables before and after an interrupt implementation
Nothing happens to your other variables during an interrupt, unless you specifically change them in the handler.
<br>




Bookmarks